Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Cassandra and CQL3, how do you insert an entire wide row in a single request?
    primarykey
    data
    text
    <p>I want to insert a single row with 50,000 columns into Cassandra 1.2.8. Before inserting, I have all the data for the entire row ready to go (in memory):</p> <pre><code>+---------+------+------+------+------+-------+ | | 0 | 1 | 2 | ... | 49999 | | row_id +------+------+------+------+-------+ | | text | text | text | ... | text | +---------+------+------+------|------+-------+ </code></pre> <p>The column names are integers, allowing slicing for pagination. The column values are a value at that particular index.</p> <p>CQL3 table definition:</p> <pre><code>create table results ( row_id text, index int, value text, primary key (row_id, index) ) with compact storage; </code></pre> <p>As I already have the row_id and all 50,000 name/value pairs in memory, I just want to insert a single row into Cassandra in a single request/operation so it is as fast as possible.</p> <p>The only thing I can seem to find is to do execute the following 50,000 times:</p> <pre><code>INSERT INTO results (row_id, index, value) values (my_row_id, ?, ?); </code></pre> <p>the first <code>?</code> is is an index counter (<code>i</code>) and the second <code>?</code> is the text value to store at location <code>i</code>.</p> <p>This takes a lot of time. Even when we put the above INSERTs into a batch, it takes a lot of time.</p> <p>We have all the data we need (the complete row) in its entirety, I would assume it to be very easy to just say "here, Cassandra, store this data as a single row in one request", for example:</p> <pre><code>//EXAMPLE-BUT-INVALID CQL3 SYNTAX: insert into results (row_id, (index,value)) values ((0,text0), (1,text1), (2,text2), ..., (N,textN)); </code></pre> <p>This example isn't possible via current CQL3 syntax, but I hope it illustrates the desired effect: everything would be inserted as a single query.</p> <p>Is it possible to do this in CQL3 and the DataStax Java Driver? If not, I suppose I'll be forced to use Hector or the Astyanax driver and the Thrift <code>batch_insert</code> operation instead?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload