Cassandra CQL method for paging through all rows

后端 未结 2 592
心在旅途
心在旅途 2021-01-07 07:52

I want to programmatically examine all the rows in a large cassandra table, and was hoping to use CQL. I know I could do this with thrift, getting 10,000 (or so) rows at a t

相关标签:
2条回答
  • 2021-01-07 08:16

    Check this one: http://wiki.apache.org/cassandra/FAQ#iter_world

    You would need to program it manually, for example each following query would need to provide starting point, which was the last result from previous query. This starting port will allow you to create slice query, which returns limited amount of results.

    For example you have row with following column names:

    A1,A2,A3,B1,B2,B3,B4,B5,B6,C4,C5,D1,D2,D4,E2,E23,E4,E5,E6,E7

    Now you would like to iterate over it, where each response has 3 results

    Slice 1) Start: "", End: "", Limit: 3 -> A1,A2,A3
    Slice 2) Start: "A3", End: "", Limit: 3 -> B1,B2,B3
    Slice 3) Start: "B3", End: "", Limit: 3 -> B4,B5,B6
    Slice 4) Start: "B6", End: "", Limit: 3 -> C4,C5,D1

    0 讨论(0)
  • 2021-01-07 08:26

    Turns out greater than and less than have a very non-intuitive, but useful, behavior (at least in CQL2, I haven't check CQL3 yet). It actually compares the tokens not the key values. Here is an example:

    > create table users (KEY varchar PRIMARY KEY, data varchar);
    > insert into users (KEY, 'data') values ('1', 'one');
    > insert into users (KEY, 'data') values ('2', 'two');
    > insert into users (KEY, 'data') values ('3', 'three');
    > insert into users (KEY, 'data') values ('4', 'four');
    > select * from users;
       3 | three
       2 |   two
       1 |   one
       4 |  four
    > select * from users LIMIT 1;
       3 | three
    > select * from users WHERE KEY > '3' LIMIT 1;
       2 |  two
    > select * from users WHERE KEY > '2' LIMIT 1;
       1 |  one
    > select * from users WHERE KEY > '1' LIMIT 1;
       4 | four
    
    0 讨论(0)
提交回复
热议问题