Why is there no random access CassIterators

48 views
Skip to first unread message

Robin Mahony

unread,
Apr 2, 2015, 8:24:49 PM4/2/15
to cpp-dri...@lists.datastax.com
Hi guys,

I want to do a binary search across a CassResult, but all that is exposed is a forward iterator. Any reason there is no random access?

Cheers,

Robin

Michael Penick

unread,
Apr 3, 2015, 11:08:04 AM4/3/15
to cpp-dri...@lists.datastax.com
Hi Robin,

CassIterator is iterating over the raw binary result set returned from Cassandra and the size of the data in each row/column can vary in size. This makes random access impossible without building a separate index if offsets into the data.  The driver doesn't currently support this, but I could see this being very useful when the size data in a result set is large.  I put together a story here to address this: https://datastax-oss.atlassian.net/browse/CPP-252. There's a proof-of-concept API in there. Feedback would be very helpful.

As a stop gap, the driver doesn't do any extra copies internally so it should be fairly efficient to copy the data to an array and do the binary search there.

Thanks,
Mike

To unsubscribe from this group and stop receiving emails from it, send an email to cpp-driver-us...@lists.datastax.com.

Robin Mahony

unread,
Apr 8, 2015, 6:30:40 PM4/8/15
to cpp-dri...@lists.datastax.com
What do you mean by "copy the data" exactly? There doesn't appear to be a way to just dump the data for a row, and I can't just copy each CassRow* using cass_iterator_get_row, since cass_iterator_next() will invalidate it.

Here is my scenario:

I have many rows, and each row has a bunch of columns (ranging in number depending on which table I query). I want a generic way to handle iterating over each row (ie. a way to use the STL on a CassResult, so need a way to provide a begin() and end() iterator).
Message has been deleted

Robin Mahony

unread,
Apr 8, 2015, 7:43:45 PM4/8/15
to cpp-dri...@lists.datastax.com
And a question regarding the proposed indexing:

const CassRow* cass_row_index_get_row(const CassRowIndex* row_index, size_t row);

So this would return the row, and the size of the row. Would "size_t row" be the constant size of a row within this CassResult?

Ie.

To get to 9th row, could I just do:

row_index += row*9;
CassRow* ninthRow = cass_row_index_get_row(row_index, row);

Michael Penick

unread,
Apr 14, 2015, 6:53:26 PM4/14/15
to cpp-dri...@lists.datastax.com
A column iterator can be created using cass_iterator_from_row(). Then  cass_iterator_get_column() can be used to get the value for each of the columns. If you need to be generic about the types in the columns then cass_value_type() can be used to branch on the type to call the corresponding cass_value_get_<type>() functions to extract the value.


Mike
Reply all
Reply to author
Forward
0 new messages