You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by DE VITO Dominique <do...@thalesgroup.com> on 2012/03/22 15:31:16 UTC
some tests with Composite (Composite as column names=>OK, as row
keys=>KO)
Hi,
I have tried few experiments with Composite (first, as columns, and next, as rows).
I have followed the paths described by http://www.datastax.com/dev/blog/introduction-to-composite-columns-part-1
My composite is (UTF8, UTF8): (folderId, filename)
And I have inserted for all tests, the following data: ("FID", "AT2"), ("FID", "BT2")... ("FID", "FT2")... ("FID", "ZT2")
I am using Hector + Cassandra 1.0.7
with the ByteOrderedPartitioner
a) using a Composite for column names
See [a] for the CF definition, and the algorithms used.
All data is into 1 row, named "1", including all the columns with the following Composite names: ("FID", "AT2"), ("FID", "BT2")... ("FID", "FT2")... ("FID", "ZT2")
I wanted to get only filenames (2nd component of the Composite) starting with "FT".
If the algorithm is correct, I should get one single result "FT2".
I have used a SliceQuery following the DataStax algo above: just OK
I have used too a RangeSlicesQuery following the DataStax algo above: just OK
For both cases, I have got only one result: "FT2".
Perfect.
b) using a Composite for row keys
See [b] for the CF definition, and the algorithms used.
All data are in rows with the following Composite row keys: ("FID", "AT2"), ("FID", "BT2")... ("FID", "FT2")... ("FID", "ZT2")
I wanted to get only filenames (2nd component of the Composite) starting with "FT".
If the algorithm is correct, I should get one single result "FT2".
I have used a RangeSlicesQuery following the DataStax algo above: KO
Instead of getting a single result "FT2", I have got 6 items: "AT2", "BT2", "CT2", "DT2", "ET2", "FT2"
Well, I am still wondering why I didn't get the same result for Composite as row keys than Composite as column names.
Is anyone having an idea ?
and a solution for fetching all the rows with a key like ("FID", "FT*") - that is, the 1st component is fixed "FID", and the 2nd component is expected to start with "FT" ?
Thanks.
Regards,
Dominique
[a]
create column family CF_COL with
comparator='CompositeType(UTF8Type, UTF8Type)' and
default_validation_class=UTF8Type and
key_validation_class=UTF8Type;
[a.1] using SliceQuery
SliceQuery<String, Composite, String> q = hector.createSliceQuery(getKeyspace(),
stringSerializer,
new CompositeSerializer(),
stringSerializer);
q.setColumnFamily("CF_COL");
Composite startRange = new Composite();
startRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
startRange.addComponent(1, "FT", AbstractComposite.ComponentEquality.EQUAL);
Composite endRange = new Composite();
endRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
endRange.addComponent(1,
"FT" + Character.MAX_VALUE,
AbstractComposite.ComponentEquality.GREATER_THAN_EQUAL);
q.setKey("1");
q.setRange(startRange, endRange, false, 1000);
[a.2] using RangeSlicesQuery
RangeSlicesQuery<String, Composite, String> q = hector.createRangeSlicesQuery(getKeyspace(),
stringSerializer,
new CompositeSerializer(),
stringSerializer);
q.setColumnFamily("CF_COL");
Composite startRange = new Composite();
startRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
startRange.addComponent(1, "FT", AbstractComposite.ComponentEquality.EQUAL);
Composite endRange = new Composite();
endRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
endRange.addComponent(1,
"FT" + Character.MAX_VALUE,
AbstractComposite.ComponentEquality.GREATER_THAN_EQUAL);
q.setKeys("1", "1");
q.setRange(startRange, endRange, false, 1000);
q.setRowCount(1);
[b]
create column family CF_ROW with
comparator=UTF8Type and
default_validation_class=UTF8Type and
key_validation_class='CompositeType(UTF8Type, UTF8Type)';
RangeSlicesQuery<Composite, String, String> q = hector.createRangeSlicesQuery(getKeyspace(),
new CompositeSerializer(),
stringSerializer,
stringSerializer);
q.setColumnFamily("CF_ROW");
Composite startRange = new Composite();
startRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
startRange.addComponent(1, "FT", AbstractComposite.ComponentEquality.EQUAL);
Composite endRange = new Composite();
endRange.addComponent(0, "FID", AbstractComposite.ComponentEquality.EQUAL);
endRange.addComponent(1,
"FT" + Character.MAX_VALUE,
AbstractComposite.ComponentEquality.GREATER_THAN_EQUAL);
q.setKeys(startRange, endRange);
q.setReturnKeysOnly();
q.setRowCount(1000);