CQL3 tables and composite key range queries and insertion

74 views
Skip to first unread message

Martin Merfort

unread,
May 21, 2013, 9:04:29 AM5/21/13
to hector...@googlegroups.com
Hello everyone,
I have a CQL3 table which I created like this:
CREATE TABLE element(
key1 UUID,
key2 UUID,
key3 UUID,
value1 text,
value2 blob,
value3 bigint,
PRIMARY KEY(key1, key2, key3));

I insert data using a mutator to which I add data like this:
    private <U extends AbstractSerializer<T>, T> void addToMutator(UUID key1,
   UUID key2, UUID key3, String name, T value, U serializer) {
Composite composite = new Composite();
composite.addComponent(key2, UUIDSerializer.get());
composite.addComponent(key3, UUIDSerializer.get());
composite.addComponent(name, StringSerializer.get());
HColumn<Composite, T> column = HFactory.createColumn(composite, value,
new CompositeSerializer(), serializer);
mutator.addInsertion(key1, "element", column);
    }

Which requires calling this function 5 times (for every key but the first and every value).
I then execute the mutator.
Is there a better way of doing this with less overhead or maybe an easier way?

I also execute a range select over key3 with a SliceQuery<UUID, Composite, byte[]> which eventually gives me 5 HColumns consisting of a Composite (key1, key2, "<key of value>") and the actual value for each entry in the db which I then have to put in a HashMap<UUID, HashMap<String, byte[]>> to sort it.
Is there a way of doing this more effectively?
I thought about using the Hector Object Mapper but I don't know if it works with CQL3 and Composite keys and I did not find any information about this.

I also found this Issue: https://github.com/hector-client/hector/issues/408 which should have been fixed a year ago but is not fixed in the version 1.0-2 of hector. Does anyone know what happened to this?

Nate McCall

unread,
May 22, 2013, 2:39:51 PM5/22/13
to hector...@googlegroups.com
I've not been shy about my frustration with the lack of interop
between thrift and CQL3 hidden composites for the non-compact tables
in the lastest Cassandra versions.

That said, what you have here is interesting in that you have a
formula for picking apart the row format for non-compact tables.

If you could wrap a utility class around this, I would love to take it
as a commit - at least have it up on the wiki for others to see.
> --
> You received this message because you are subscribed to the Google Groups
> "hector-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hector-users...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages