基本上我问了同样的事情,如这个问题,但对于Python Cassandra Library,Pycassa。

让我们说你有一个存储数据的复合类型:

[20120228:finalscore] = '31-17'
[20120228:halftimescore]= '17-17'
[20120221:finalscore] = '3-14'
[20120221:halftimescore]= '3-0'
[20120216:finalscore] = '54-0'
[20120216:halftimescore]= '42-0'
.

所以,我知道我可以通过执行:,根据复合类型的第一部分轻松切片

>>> cf.get('1234', column_start('20120216',), column_finish('20120221',))
OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
.

但如果我只想要终结,我会认为我可以做到:

>>> cf.get('1234', column_start('20120216', 'finalscore'),
column_finish('20120221', 'finalscore'))
.

获取:

OrderedDict([((u'20120216', u'finalscore'), u'54-0')])
.

但相反,我得到:

OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
.

与第一呼叫相同。

我做错了什么?这是工作吗?或者使用cf.get(...列= [('20120216','FinalScore')])是有一些语法])?我也试过了,得到了一个例外。

根据 http://www.datastax .com / dev /博客/介绍 - 复合列 - part-1 ,我应该能够做到这样的事情...

感谢

有帮助吗?

解决方案

If know all the components of the composite column then you should the 'columns' option:

cf.get('1234', columns=[('20120216', 'finalscore')])

You said you got an error trying to do this, but I would suggest trying again. It works fine for me.

When you are slicing composite columns you need to think about how they are sorted. Composite columns sort starting first with the left most component, and then sorting each component toward the right. So In your example the columns would look like this:

+------------+---------------+------------+---------------+------------+----------------+
| 20120216   | 20120216      | 20120221   | 20120221      | 20120228   | 20120228       |
| finalscore | halftimescore | finalscore | halftimescore | finalscore | halftimescore  |
+------------+---------------+------------+---------------+------------+----------------+

Thus when you slice from ('20120216', 'finalscore') to ('20120221', 'finalscore') you get both values for '20120216'. To make your query work as you want it to you could change the column_finish to ('20120216', 'halftimescore').

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top