Cassandra Pycassa:如何查询复合类型的部分

Cassandra Pycassa:如何查询复合类型的部分,cassandra,pycassa,Cassandra,Pycassa,基本上,我要求的是与中相同的东西,但要求的是Python Cassandra库,PyCassa 假设您有一个存储数据的复合类型,如下所示: [20120228:finalscore] = '31-17' [20120228:halftimescore]= '17-17' [20120221:finalscore] = '3-14' [20120221:halftimescore]= '3-0' [20120216:finalscore] = '54-0' [20120216:halftimesc

基本上,我要求的是与中相同的东西,但要求的是Python Cassandra库,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'
+------------+---------------+------------+---------------+------------+----------------+
| 20120216   | 20120216      | 20120221   | 20120221      | 20120228   | 20120228       |
| finalscore | halftimescore | finalscore | halftimescore | finalscore | halftimescore  |
+------------+---------------+------------+---------------+------------+----------------+
因此,我知道我可以很容易地根据复合类型的第一部分进行切片,方法是:

>>> 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(…columns=[('20120216','finalscore')]的语法?我也试过了,但有个例外

根据,我应该可以做这样的事情


谢谢

如果您知道复合列的所有组件,那么您应该选择
选项:

cf.get('1234', columns=[('20120216', 'finalscore')])
你说你在尝试这样做时出错,但我建议你再试一次。这对我来说很好

在对复合列进行切片时,需要考虑如何对它们进行排序。复合列首先从最左边的组件开始排序,然后向右排序每个组件。因此,在您的示例中,列将如下所示:

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

因此,当您从
('20120216','finalscore')
切片到
('20120221','finalscore')
时,您会得到
'20120216'
的两个值。要使查询按您所希望的方式工作,您可以将列_finish更改为
('20120216','halftimescore')

好的,那么您在cf.get()调用上是对的,这是正确的,我一定键入了错误的内容。但是关于我问题的第二部分,我认为我的示例有点糟糕,因为我真正想要的是如何在Pycassa中查询部分组合。显然,在Hector和Pycassa中,都可以使用部分组合执行切片查询,如:cf.get('1234',column_start=('20120216',),column_finish=('20120221',),但当我尝试使用部分组合执行cf.get()时,会出现错误。这在卡桑德拉不可能吗?部分复合材料只能用于切片。使用get时,您必须知道所需列的完整名称。好的,非常感谢。因此,一般来说,如果您需要根据复合材料的一个子类型过滤数据,要么您的应用程序代码需要处理它,要么您需要重新组织复合材料组件的顺序?@stantonk关于切片端的部分复合材料,您肯定能够做到这一点(在pycassa 1.4.0或更高版本中)。你觉得怎么样?