2013-02-26 228 views
0
查詢範圍的日期

我試圖用這個模式做一個查詢範圍日期:使用卡桑德拉

create column family fact_ingreso with comparator = UTF8Type and 
key_validation_class=UTF8Type and 
column_metadata = 
[{column_name: ing_fecing, validation_class: DateType,index_type:KEYS}]; 

,我插在這樣的數據

// Date format: "2010-04-01 00:00:00" 
// The datos[20] has a date as a String in the above format 
SimpleDateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
Date fecha = formatoFecha.parse(datos[20]); 
System.out.println(fecha); 
Column ing_fecing = new Column(toByteBuffer("ing_fecing")); 
ing_fecing.setValue(ByteBufferUtil.bytes(fecha.getTime())); 
ing_fecing.setTimestamp(timestamp); 
client.insert(toByteBuffer(id_row), parent, ing_fecing, ConsistencyLevel.ONE); 

到目前爲止,一切都很好,但當我嘗試使用後續的代碼做一個查詢範圍日期:

get fact_ingreso where ing_fecing>2011-01-12; 

我得到了錯誤「沒有索引列存在索引條款的Wi日運營商EQ」

但是,如果我取代了運營商‘>’爲‘=’它的工作原理:

get fact_ingreso where ing_fecing=2011-01-12; 

輸出

RowKey: 645 
=> (column=ing_fecing, value=2011-01-12 00:00:00-0300, timestamp=1361899176638) 

我在卡桑德拉數據庫新手,我真的很需要爲我的論文工作部署此功能。 如果有人可以幫助我,我真的很感激。

編輯:卡桑德拉的版本是1.2 問候

回答

0

隨着卡桑德拉你必須有使用規定的條款等於至少一個值;即你不能只指定一個範圍。一個簡單的方法是編寫一個表示已知值的標記列。例如,您可以編寫代表當前月份或年份的列,然後將其用作平等值。在查詢時你可以知道的任何值都可以做到。