【问题标题】:New To Cassandra - SliceQuery giving error Not Enough bytes to read value of component 0Cassandra 的新手 - SliceQuery 给出错误 Not Enough bytes to read component 0 的值
【发布时间】:2012-11-20 15:20:24
【问题描述】:

我在尝试使用 2 列的组合键查询列族 (CF) 时遇到问题:comment_keyprattle_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 行,所以我知道那里有数据。

任何帮助将不胜感激!谢谢!

【问题讨论】:

    标签: java cassandra thrift hector


    【解决方案1】:

    当您使用复合主键时,第一个键用作行(或分区)键,其余主键用作非键列的列标题的一部分。例如,在您的情况下,CQL 列正文的列名是由 prattle_key 值和字符串“body”的值组成的复合值。这也意味着一个列族行可以包含多个 CQL 行,它们都具有相同的 comment_key 值但不同的 prattle_key 值。

    我认为你得到的错误来自这样一个事实,你试图处理一个只有 comment_key 的 rowkey 值和一个有两个组件的复合类型。更改您的键值,使其只是 comment_key 并查找返回的第一个组件等于 prattle_key 值的列名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 1970-01-01
      • 2019-06-07
      相关资源
      最近更新 更多