2012-12-03 19 views
3

我在嘗試使用2列組合鍵查詢列族(CF)時遇到問題:comment_keyprattle_keyCassandra的新增功能 - SliceQuery給出錯誤沒有足夠的字節來讀取組件0的值

下面是CF的定義:

CREATE TABLE comments (
    comment_key text, 
    prattle_key text, 
    parent_key text, 
    depth int, 
    author text, 
    date_created timestamp, 
    body text, 
    PRIMARY KEY (comment_key, prattle_key) 
) WITH 
    comment='' AND 
    caching='KEYS_ONLY' AND 
    read_repair_chance=0.100000 AND 
    gc_grace_seconds=864000 AND 
    replicate_on_write='true' AND 
    compaction_strategy_class='SizeTieredCompactionStrategy' AND 
    compression_parameters:sstable_compression='SnappyCompressor'; 

這是我的Java代碼:

Composite key = new Composite(); 
key.addComponent(prattleKey, StringSerializer.get()); 
key.addComponent(commentKey, StringSerializer.get()); 

SliceQuery<Composite, String, String> query = HFactory.createSliceQuery(keyspace, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get()); 

query.setColumnFamily("comments").setKey(key).setColumnNames("parent_key", "body", "depth", "date", "author"); 

QueryResult<ColumnSlice<String, String>> queryResult = query.execute(); 
ColumnSlice<String, String> cs = queryResult.get(); 

我收到以下錯誤信息:

InvalidRequestException(why:Not enough bytes to read value of component 0) 

使用命令行CQL工具,我可以選擇ColumnFamily中的所有3行,所以我知道那裏有數據。

任何援助將不勝感激!謝謝!

回答

0

當您使用複合主鍵時,第一個鍵用作行(或分區)鍵,其餘主鍵用作非鍵列的列標題的一部分。例如,就你而言,CQL列體的列名是一個由prattle_key值和字符串「body」組成的複合值。這也意味着一個列族行可以包含多個CQL行,它們都具有相同的comment_key值但不同的prattle_key值。

我覺得你得到的錯誤來自於你試圖處理一個只有comment_key的複合類型有兩個組件的rowkey值。更改您的鍵值,使其只是comment_key,然後查找第一個與prattle_key值相等的組件返回的列名稱。

相關問題