0
votes

I have created a column family with Comparator_type="LexicalUUIDType", Default_validation_class="UTF8Type" and Key_validation_class="UTF8Type".

And set TimeUUID as column_name within the column family above. It's insertion runs very well, but how can I get the columns? I can't set the correct column_name! The following are the code:

    ColumnPath path = new ColumnPath();
    path.setColumn_family("test");
    path.setColumn(("44c32fe1-38a4-11e1-a06a-485d60c81a3e".getBytes()));
    ColumnOrSuperColumn or = new ColumnOrSuperColumn();
    try {
        or = client.get(ByteBuffer.wrap("key").getBytes()), path, ConsistencyLevel.ONE);
    } catch (InvalidRequestException e) {
       ...

data in Cassandra DB:

    => (column=44c32fe0-38a4-11e1-a06a-485d60c81a3e, value=32, timestamp=1325881397726)
    => (column=44c32fe1-38a4-11e1-a06a-485d60c81a3e, value=33, timestamp=1325881397726)
    => (column=44c32fe2-38a4-11e1-a06a-485d60c81a3e, value=34, timestamp=1325881397727)
    => (column=44c37e00-38a4-11e1-a06a-485d60c81a3e, value=35, timestamp=1325881397728)
    => (column=44c37e01-38a4-11e1-a06a-485d60c81a3e, value=36, timestamp=1325881397728)
    ...

And the exception informations:

    InvalidRequestException(why:LexicalUUID should be 16 or 0 bytes (36))
    at org.apache.cassandra.thrift.Cassandra$get_result.read(Cassandra.java:6490)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_get(Cassandra.java:519)
    at org.apache.cassandra.thrift.Cassandra$Client.get(Cassandra.java:492)
    at test.cassandra.MainTest.query(MainTest.java:118)
    ...

That's why? I can't execute single query or slice query now. How can I execute query by key and column name with uuid? Thank in advance!

1

1 Answers

1
votes

The byte representation of a UUID is not what you get when you call "44c32fe1-38a4-11e1-a06a-485d60c81a3e".getBytes() (a uuid is 16 bytes, this string.getBytes() is 36 bytes). The FAQ on the cassandra wiki has instructions how to do what you want in java:

java.util.UUID.fromString("44c32fe1-38a4-11e1-a06a-485d60c81a3e");