Created
July 16, 2012 07:57
-
-
Save bartprokop/3121434 to your computer and use it in GitHub Desktop.
Querying whole column family in Cassandra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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