2012-04-19 69 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