2012-04-19 52 views
1

我想创建和使用标准列家族的“年龄”键上的索引。cassandra创建和使用索引[pycassa]

我做了以下使用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'} 

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

任何想法?

回答

2

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

你可以找到所有的文档和示例使用这里的:http://pycassa.github.com/pycassa/api/pycassa/index.html

+0

如果我用pycassa.index.GT它说NameError:全局名称“pycassa”没有定义的代码更改为“GT”到GT给我一个不同的错误:“索引子句中没有带有操作符EQ的索引列” – rikAtee 2012-04-20 09:50:17

+0

@rikAtee您需要执行类似'from pycassa.index import GT'的操作,然后才可以直接使用GT。 “索引子句中没有索引列”是因为您的子句中必须至少有一个EQ表达式,它处理与Cassandra进行二级索引查询的索引列。 – 2012-04-20 16:27:20

+0

我做了:sys.alter_column('test01','word_map','age','IntegerType') 和:sys.create_index('test01','word_map','age','IntegerType') 和我仍然得到“InvalidRequestException(为什么='索引子句中没有带有操作符EQ的索引列')” – rikAtee 2012-04-20 20:17:27