CompositeTypes, SlicePredicates, Bytes.EMPTY... I'm confused

38 views
Skip to first unread message

Kevin

unread,
Oct 7, 2012, 3:18:57 PM10/7/12
to sca...@googlegroups.com
Dan (or anyone else at Scale7), how are we supposed to perform range queries using Composite types?

I have a column family that has a (LexicalUUIDType: LexicalUUIDType: Long) composite comparator. I want to query all of the columns with equal UUIDs in the first component. However, there isn't much (or any) documentation on how to do this in Pelops.

I'm trying:

CompositeType.Builder compositeBuilder = CompositeType.Builder.newBuilder();
 compositeBuilder.addUuid(userID1);   //UUID
 compositeBuilder.addBytes(Bytes.EMPTY);  //start at beginning of range, I think?

Bytes rangeStartBytes = compositeBuilder.build();
 Bytes rangeEndBytes = Bytes.EMPTY;

  SlicePredicate blah = Selector.newColumnsPredicate(rangeStartBytes, rangeEndBytes, false, Integer.MAX_VALUE);

However, I'm not sure if this is correct. With this code, am I querying all the columns with "userID1" as the first component, or am i querying all columns appearing below that specified by rangeStartBytes (regardless of the first component)?
Furthermore, what exactly does Bytes.EMPTY signify? The beginning of a range? The end of a range? Both? And what does Bytes.NULL signify? I looked in to the source and it seems as though they're being created from byte arrays of 0 and respectively, but I'm not sure what those values signify when it comes to queries.

If any of you guys at Scale7 could lend me some wisdom, I'd appreciate it

Ali Serghini

unread,
Oct 8, 2012, 2:33:11 PM10/8/12
to sca...@googlegroups.com
There is an integration test for CompositeType in the source code [https://github.com/s7/scale7-pelops/blob/master/src/test/java/org/scale7/cassandra/pelops/CompositeTypeIntegrationTest.java]. Take a look at "testSlice".

- Ali

Kevin

unread,
Oct 12, 2012, 7:59:55 AM10/12/12
to sca...@googlegroups.com
That test method is somewhat informative, but I'm afraid it doesn't fully answer my question. Allow me to rephrase my question in terms of the Composites the test uses.

What I want to do is get all the columns that possess a first component of 31. Now, assuming I don't know the values that appear above or below those columns (i.e I'm not aware that the set of columns with 41 and 21 are (respectively) below and above the desired columns, how can I limit my search to only retrieve those columns?

I'm thinking I have to specify the start and end "bounds" of the second component to encompass its entire set of  possible values. How is that done? Bytes.EMPTY? Bytes.NULL? Both? Neither?

In other words, what do I put in place of the question marks in these lines of code:

Bytes rangeStartBytes = CompositeType.Builder.newBuilder().addLong(31).add????????????; 
Bytes.rangeEndBytes = CompositeType.Builder.newBuilder().addLong(31).add????????????;

gupu81

unread,
Feb 11, 2015, 2:58:55 AM2/11/15
to sca...@googlegroups.com
Hello Kevin,

This is very pertinent query you had raised, and I really feel frustrated to see it not being responded from the team. I am facing a similar kind of situation using Pelops 1.3 as of today. I tried both,

List<Column> cols = selector.getColumnsFromRow(colFamily, Bytes.fromInt(1), slice, ConsistencyLevel.ONE);
List<Column> cols = selector.getPageOfColumnsFromRow(colFamily, Bytes.fromInt(1), startRange, false, 20, ConsistencyLevel.ONE);

however, doesn't seem to be using it properly (I suppose) as I am not getting the desired result.

Can you kindly share if you were able to find a solution.

Thanks,
Sutanu
Reply all
Reply to author
Forward
0 new messages