我在尝试使用 2 列的复合键查询列族 (CF) 时遇到问题:comment_key
和prattle_key
.
这是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 行,所以我知道那里有数据。
任何帮助将不胜感激!谢谢!