Reputation: 528
I am new to Cassandra and just playing around with it. I have created a Column family
having composite key and composite column. Following is the script for same:
create column family TestCompositeKey with key_validation_class='CompositeType(UTF8Type, TimeUUIDType)' and comparator='CompositeType(UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_class='UTF8Type';
After inserting data in the column family using Hector following is the view I am getting on CLI:
RowKey: AB:e9a87550-c84b-11e2-8236-180373b60c1a
=> (column=0007:TAR:PUB:BD_2013_01_11_0125094813, value=TESTSEARCH, timestamp=1369823914277000)
Now I want to search for data just by 'AB' given in row key as second part of key will be dynamic. It works fine when I give complete row key. Please tell me how can this be done. I am supplying search criteria on column too along with specifying key.
Thanks Harish Kumar
Upvotes: 1
Views: 1092
Reputation: 11110
You can't do this (efficiently, at least): to lookup by row key you need the whole key. In general, using TimeUUIDs as row keys should be avoided, unless you have some other table acting as an index to retrieve TimeUUIDs for a query.
If you want to lookup just by the first component of the key you should move the second component to the column composite and just have a single component as the row key. The definition would be
create column family TestCompositeKey with key_validation_class='UTF8Type' and comparator='CompositeType(TimeUUIDType, UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_class='UTF8Type';
If you used the CQL3 definition:
CREATE TABLE TestCompositeKey (
a varchar,
b timeuuid varchar,
c varchar,
d varchar,
e varchar,
f varchar,
PRIMARY KEY (a, b, c, d, e, f)
);
you would get essentially the same schema as I described. The row key (partition key in CQL language) is a, and the column names are a composite of b:c:d:e:f.
Upvotes: 1