3
votes

I'm inserting into a CF and it goes OK, I can also read the full row from the cassandra-cli with a simple

get columnFamily[lexicaluuid(de80a290-dd71-11e0-8f9d-f81edfd6bd91)];

The key for each column is a timeUUID:

key = TimeUUIDUtils.getUniqueTimeUUIDinMillis();

Part of the description of the CF:

ColumnFamily: columnFamily
       Key Validation Class: org.apache.cassandra.db.marshal.TimeUUIDType
       Default column value validator: org.apache.cassandra.db.marshal.BytesType
       Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type

We've also changed the key validation class to test with BytesType UTF8Type and TimeUUIDType.

As the cassandra client from Java I'm using Hector.

When I try to get a row knowing it's id I'm not able to retrieve anything.

Examples:

String rowKey = "de80a290-dd71-11e0-8f9d-f81edfd6bd91";
SliceQuery<UUID, String, String> result =HFactory.createSliceQuery(CassandraManager.getKeyspace(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get());
result.setColumnFamily("columnFamily");
result.setKey(UUIDSerializer.get().fromByteBuffer(StringSerializer.get().toByteBuffer(rowKey)));

result.setColumnNames(COLUMNS); //COLUMNS ins a predefined list of colums
QueryResult <ColumnSlice<String, String>> columnSlice = result.execute();
System.out.println(columnSlice.get().getColumnByName(name).getValue());

And the result is the following exception:

me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Invalid version for TimeUUID type.)
    at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:50)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl$7.execute(KeyspaceServiceImpl.java:285)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl$7.execute(KeyspaceServiceImpl.java:268)
    at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:101)
    at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:232)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:131)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.getSlice(KeyspaceServiceImpl.java:289)
    at me.prettyprint.cassandra.model.thrift.ThriftSliceQuery$1.doInKeyspace(ThriftSliceQuery.java:53)
    at me.prettyprint.cassandra.model.thrift.ThriftSliceQuery$1.doInKeyspace(ThriftSliceQuery.java:49)...

I've also tried with a StringSerializer as the keySerializer in the sliceQuery definition, and I don't get an Exception but none results.

I guess that my question is basically "how do I retrieve a row querying by the key?" :)

It seems that it could be a stupid question but is driving me crazy for some days.

1

1 Answers

2
votes

This line is wrong,

result.setKey(UUIDSerializer.get().fromByteBuffer(StringSerializer.get().toByteBuffer(rowKey)));

Instead you want to do something like,

result.setKey(java.util.UUID.fromString(rowKey));

StringSerializer.get().toByteBuffer(rowKey)) gives you a bytebuffer which contains rowKey as 36 utf-8 bytes. This is not the same as the serialized form of a uuid, which is 16 bytes (a long msb, then a long lsb).

There is probably no need to use a String at all in this case. Just use TimeUUIDSerializer and com.eaio.uuid.UUID everywhere in your code.