【问题标题】:cassandra creating and using index [pycassa]cassandra 创建和使用索引 [pycassa]
【发布时间】:2012-04-19 21:26:31
【问题描述】:

我想在标准列族的“年龄”键上创建和使用索引。

我使用 pycassa 做了以下操作:

In [10]: sys.create_index('test01', 'word_map', 'age', 'IntegerType', index_type=0, index_name='index_age')
In [11]: age_expr = create_index_expression('age', 6, GT)
In [12]: clause = create_index_clause([age_expr], count=20)
In [13]: cf.get_indexed_slices(clause)

error: 'No indexed columns present in index clause with operator EQ'

根据这个漂亮的page,我需要设置值类型。然而:

In [16]:  cf_words.column_validators
Out[16]: {'black_white': 'BooleanType', 'url': 'UTF8Type', 'age': 'IntegerType', 'site': 'UTF8Type', 'len': 'IntegerType', 'content': 'UTF8Type', 'colourful': 'BooleanType', 'printer_friendly': 'BooleanType'}

所以年龄有一个数据类型集。

有什么想法吗?

【问题讨论】:

    标签: python indexing cassandra pycassa


    【解决方案1】:

    使用pycassa.index.GT 代替字符串“GT”。这是 Thrift 用整数实现的枚举。

    您可以在此处找到所有文档和示例用法:http://pycassa.github.com/pycassa/api/pycassa/index.html

    【讨论】:

    • 如果我使用 pycassa.index.GT 它说 NameError: global name 'pycassa' is not defined 将代码更改为 'GT' 到 GT 给我一个不同的错误:“索引中没有索引列带有运算符 EQ 的子句"
    • @rikAtee 您需要执行“from pycassa.index import GT”之类的操作,然后您就可以直接使用 GT。 “索引子句中不存在索引列”是因为您的子句中必须至少有一个 EQ 表达式来处理使用 Cassandra 进行二级索引查询的索引列。
    • 我做了:sys.alter_column('test01','word_map','age','IntegerType') 和:sys.create_index('test01','word_map','age',' IntegerType'),我仍然得到“InvalidRequestException(why='No indexed columns present in index clause with operator EQ')”
    • @rikAtee 你必须在至少一个索引列上有一个 EQ 表达式。您现在只使用 GT 表达式;即使该列已编入索引,但这还不够。
    猜你喜欢
    • 2014-03-03
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多