Last weekend I updated my high-level C++ client for Cassandra, libcassandra to support a lot of the new features in the 0.7 Cassandra release. In particular, one of the new features is secondary indexes and I wanted to very briefly outline how secondary indexes can be used programatically in libcassandra.

An article by Datastax gives a great overview of secondary indexes. I'm going to use the example in that article here.

The first thing which we must do is create a keyspace and column family. This is accomplished in libcassandra like:

After creating a keyspace and column family for working with, we next want to insert some sample data. I'll use the sample data inserted in the article but instead of inserting it through the CLI, I'll insert it using libcassandra:

Next, to perform the same query as was used in the article, the code looks like:

Currently, the result set is a std::map of row keys to an inner std::map of column names to column values. I plan on adding support for the result to contain more information about each row in the result set in the future.



blog comments powered by Disqus

Published

27 February 2011

Category

cassandra