0

Possible Duplicate:
Misunderstanding on Composite Key for Cassandra

I have a columnfamily with a composite key:

create column family MyCF
with key_validation_class = 'CompositeType(UTF8Type, UTF8Type)'
and comparator = 'CompositeType(UTF8Type, UTF8Type)'
and default_validation_class='CompositeType(UTF8Type, UTF8Type)'
;

and I have stored the row key with the following values 1:1,2:2,1:3,2:1,1:2,2:3

RowKey: 1:1
= (column=colum1, value=value1, timestamp=1351093372962000)

RowKey: 2:2
=> (column=colum1, value=value1, timestamp=1351093411137000)

RowKey: 1:3
= (column=colum1, value=value1, timestamp=1351093385820000)

RowKey: 2:1
= (column=colum1, value=value1, timestamp=1351093401162000)

RowKey: 1:2
= (column=colum1, value=value1, timestamp=1351093379274000)

RowKey: 2:3
= (column=colum1, value=value1, timestamp=1351093421393000)

After loading Cassandra, I want to recover all the rows that starts with 1, that are 1:1, 1:2 and 1:3

I've tried to do it using Hector and Thrift but I haven't been able to find any information on the docs.

With CQL is not possible to recover it because this kind of queries are not supported or this is what it is said on the forums.

I've also manage to recover the information by selecting the row keys (1:1, 1:2, 1:3) and this works correctly, but what I really need to do is recover the information asking only the first element of the compositive key.

How can I do it?

Thanks

Community
  • 1
  • 1

1 Answers1

0

Well, a completely different way to go is something like this

RowKey: 1:1
= (extra:1, column=colum1, value=value1, timestamp=1351093372962000)

RowKey: 2:2
=> (extra:2, column=colum1, value=value1, timestamp=1351093411137000)

RowKey: 1:3
= (extra:1, column=colum1, value=value1, timestamp=1351093385820000)

RowKey: 2:1
= (extra:2, column=colum1, value=value1, timestamp=1351093401162000)

RowKey: 1:2
= (extra:1, column=colum1, value=value1, timestamp=1351093379274000)

RowKey: 2:3
= (extra:2, column=colum1, value=value1, timestamp=1351093421393000)

And then you can index the extra field. As an Example in PlayOrm with cassandra, you could have

public class Entity {
  @NoSqlId
  private String id;

  @NoSqlIndexed
  private String extra;

  @NoSqlPartitionedBy
  private Account fieldYouMightPartitionBy;    
  private String column;
  private String value;
}

then you can run

PARTITIONS (:partitionId) SELECT e from Entity as e WHERE e.extra = 1;

later, Dean

Dean Hiller
  • 19,235
  • 25
  • 129
  • 212