简体   繁体   中英

Cassandra DataStax driver: how to page through columns

I have wide rows with timestamp columns. If I use the DataStax Java driver, I can page row results by using LIMIT or FETCH_SIZE, however, I could not find any specifics as to how I can page through columns for a specific row.

I found this post: http://cassandra-user-incubator-apache-org.3065146.n2.nabble.com/CQL-3-and-wide-rows-td7594577.html which explains how I could get ranges of columns based on the column name (timestamp) values.

However, what I need to do is to get ALL columns, I just don't want to load them all into memory , but rather "stream" the results and process a chunk of columns (preferably of a controllable size) at a time until all columns of the row are processed. Does the DataStax driver support streaming of this kind? and of so - what is the syntax for using it?

Additional clarification: Essentially, what I'm looking for is an equivalent of the Hector's ColumnSliceIterator using which I could iterate over all columns (up to Integer.MAX_VALUE number) of a specific row in batches of, say, 100 columns at a time as following:

SliceQuery sliceQuery = HFactory.createSliceQuery(keySpace, ...);
sliceQuery.setColumnFamily(MY_COLUMN_FAMILY);
sliceQuery.setKey(myRowKey);
// columns to be returned. The null value indicates all columns
sliceQuery.setRange(
    null // start column
    , null // end column
    , false // reversed order
    , Integer.MAX_VALUE // number of columns to return
);

ColumnSliceIterator iter = new ColumnSliceIterator( 
    sliceQuery // previously created slice query needs to be passed as parameter
    , null // starting column name
    , null // ending column name
    , false // reverse
    , 100 // column count <-- the batch size 
);
while (iter.hasNext()) {
    String myColumnValue = iter.next().getValue();
}

How do I do the exact same thing using the DataStax driver?

thanks!

Marina

The ResultSet Object that you get is actually setup to do this sort of paginating for you by default. Calling one() repeatedly or iterating using the iterator() will allow you to access all the data without calling it all into memory at once. More details are available in the api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM