Skip to content

Instantly share code, notes, and snippets.

@bartprokop
Created July 16, 2012 07:57
Show Gist options
  • Save bartprokop/3121434 to your computer and use it in GitHub Desktop.
Save bartprokop/3121434 to your computer and use it in GitHub Desktop.
Querying whole column family in Cassandra
public static void main(String... args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("test-cluster", "localhost:9160");
Keyspace keyspace = HFactory.createKeyspace("MyKeyspace", cluster);
RangeSlicesQuery<String, String, String> q = HFactory
.createRangeSlicesQuery(keyspace, StringSerializer.get(),
StringSerializer.get(), StringSerializer.get());
q.setColumnFamily("ColumnFamilyName");
q.setRange(null, null, false, 2);
QueryResult<OrderedRows<String, String, String>> execute = q.execute();
OrderedRows<String, String, String> get = execute.get();
Iterator<Row<String, String, String>> iterator = get.iterator();
while (iterator.hasNext()) {
Row<String, String, String> next = iterator.next();
System.out.println("Key: " + next.getKey());
ColumnSlice<String, String> columnSlice = next.getColumnSlice();
for (HColumn<String, String> c : columnSlice.getColumns()) {
System.out.println(c.getName() + " = " + c.getValue());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment