Querying CompositeType columns in Cassandra using Hector

前端 未结 1 1991
不思量自难忘°
不思量自难忘° 2020-12-23 23:10

Here\'s a sample of the scenario I\'m facing. Say I have this column family:

    create column family CompositeTypeCF 
    with comparator = \'CompositeType(         


        
相关标签:
1条回答
  • 2020-12-24 00:11

    Good starting point tutorial here.

    But, after finally having the need to use a composite component and attempting to write queries against the data, I figured out a few things that I wanted to share.

    When searching Composite columns, the results will be a contiguous block of columns.

    So, assuming a s composite of 3 Strings, and my columns look like:

    A:A:A
    A:B:B
    A:B:C
    A:C:B
    B:A:A
    B:B:A
    B:B:B
    C:A:B
    

    For a search from A:A:A to B:B:B, the results will be

    A:A:A
    A:B:B
    A:B:C
    A:C:B
    B:A:A
    B:B:A
    B:B:B
    

    Notice the "C" Components? There are no "C" components in the start/end terms! what gives? These are all the results between A:A:A and B:B:B columns. The Composite search terms do not give the results as if processing nested loops (this is what I originally thought), but rather, since the columns are sorted, you are specifying the start and end terms for a contiguous block of columns.

    When building the Composite search entries, you must specify the ComponentEquality

    Only the last term should be GREATER_THAN_EQUAL, all the others should be EQUAL. e.g. for above

    Composite start = new Composite();
    start.addComponent(0, "A", Composite.ComponentEquality.EQUAL);
    start.addComponent(1, "A", Composite.ComponentEquality.EQUAL);
    start.addComponent(2, "A", Composite.ComponentEquality.EQUAL);
    
    Composite end = new Composite();
    end.addComponent(0, "B", Composite.ComponentEquality.EQUAL);
    end.addComponent(1, "B", Composite.ComponentEquality.EQUAL);
    end.addComponent(2, "B", Composite.ComponentEquality.GREATER_THAN_EQUAL);
    
    SliceQuery<String, Composite, String> sliceQuery = HFactory.createSliceQuery(keyspace, se, ce, se);
    sliceQuery.setColumnFamily("CF").setKey(myKey);
    ColumnSliceIterator<String, Composite, String> csIterator = new ColumnSliceIterator<String, Composite, String>(sliceQuery, start, end, false);
    
    while (csIterator.hasNext()) ....
    
    0 讨论(0)
提交回复
热议问题