4
votes

I am newbie in cassandra,and my data storage structure is

list test
RowKey: key1
=> (column=colkey1:colkey2, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey3, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey4, value=amitdubey, timestamp=1381832571947000)
-------------------
RowKey: key2
=> (column=colkey1:colkey2, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey3, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey4, value=amitdubey, timestamp=1381832571947000)
-------------------

using column definition is

create column family test
with column_type = 'Standard'
and comparator=
'CompositeType(org.apache.cassandra.db.marshal.UTF8Type,
org.apache.cassandra.db.marshal.UTF8Type)'
and default_validation_class = 'UTF8Type'
and key_validation_class = 'UTF8Type';

but when I fetch keyRow :

SliceQuery<String,Composite,String> sliceQuery=HFactory.createSliceQuery(keyspace, se, ce, se);
sliceQuery.setColumnFamily("test");
sliceQuery.setKey("jax");
sliceQuery.setRange(null,null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<Composite,String>>result=sliceQuery.execute();
System.out.println(orderedRows.getColumns());

output is:

[HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5)]       
1
I am not sure if this is the problem but in code to fetch the row you are querying a different column family (something named postrecieve)ftrujillo

1 Answers

3
votes

You are nearly there, you have the data - you need to unpack the columns, see below:

SliceQuery<String, Composite, String> sliceQuery = HFactory.createSliceQuery(keyspace, StringSerializer.get(), CompositeSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily("test");
sliceQuery.setKey("key1");
sliceQuery.setRange(null, null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<Composite, String>> result = sliceQuery.execute();
ColumnSlice<Composite, String> slice = result.get();

List<HColumn<Composite, String>> columns = slice.getColumns();

System.out.println("Packed");
System.out.println(columns);

System.out.println();
System.out.println("Unpacked");
for (HColumn<Composite, String> column : columns) {
  String first = column.getName().get(0, StringSerializer.get());
  String second = column.getName().get(1, StringSerializer.get());
  System.out.println(first + ":" + second + "=" + column.getValue());
}

which should give you output like this:

Packed
[HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey), HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey), HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey)]

Unpacked
colkey1:colkey2=amitdubey
colkey1:colkey3=amitdubey
colkey1:colkey4=amitdubey

(Tested with hector 1.1-4.)