问题
I have data stored using CompositeType
that looks like the following:
RowKey: 101390
=> (column=1320987600000:P:350.0:symbol, value=AAPL/F6LbE.O, timestamp=1320771711561000)
=> (column=1320987600000:P:355.0:symbol, value=AAPL/F6LfE.O, timestamp=1320771711569000)
=> (column=1320987600000:P:360.0:symbol, value=AAPL/F6LjE.O, timestamp=1320771711576000)
=> (column=1320987600000:P:365.0:symbol, value=AAPL/F6LnE.O, timestamp=1320771711586000)
=> (column=1320987600000:P:370.0:symbol, value=AAPL/F6LrE.O, timestamp=1320771711592000)
=> (column=1320987600000:P:460.0:symbol, value=AAPL/F6LzF.O, timestamp=1320771711607000)
=> (column=1320987600000:C:350.0:symbol, value=AAPL/FuLbE.O, timestamp=1320771712117000)
=> (column=1320987600000:C:355.0:symbol, value=AAPL/FuLfE.O, timestamp=1320771712120000)
=> (column=1320987600000:C:360.0:symbol, value=AAPL/FuLjE.O, timestamp=1320771712123000)
=> (column=1320987600000:C:365.0:symbol, value=AAPL/FuLnE.O, timestamp=1320771712128000)
The composite has four parts : [ timestamp : type : price : attribute_name]
Is it possible to query for 1, 2 or all components parts using SliceQuery
?
- For instance I want to query from timestamp T1 --> T2 (that works fine)
- Also need to say timestamp T1 --> T2 and Type = "C" and only "C"
- Timestamp T1 --> T2, Type = "C" AND price = "365.0"
Is it possible to query parts of the composite in this fashion? In my testing so far I have not been able to and the composite appears to be compared as if it is only long byte array -- instead of the individual components.
回答1:
From ML answer: Here is an example of such that is sort of half-started. There should be enough here in the comments to get you going: https://github.com/zznate/cassandra-tutorial/blob/master/src/main/java/com/datastax/tutorial/StaticCompositeIndex.java
Let me know if that helps.
回答2:
Yes, you can search parts of a composite. If you are using Cassandra 0.8.1 and above, you need to specify the comparator to be "CompositeType" in your schema. Here is a complete tutorial on programming range query using CompositeType: http://randomizedsort.blogspot.com/2011/11/cassandra-range-query-using.html
来源:https://stackoverflow.com/questions/8054882/hector-how-to-query-parts-of-a-composite-type