【问题标题】:cassandra thrift long insert - InvalidRequestException(why:(String didn't validate.)cassandra thrift long insert - InvalidRequestException(为什么:(字符串未验证。)
【发布时间】:2014-07-12 21:42:40
【问题描述】:

我正在创建动态列族并通过在 Cassandra 2.0.7 中使用节俭 Api 插入长值。但它的抛出错误仅适用于长类型。其他类型,如 string 、 int 和 byte 正在工作。

InvalidRequestException(why:(String didn't validate.) [Monitor][Groups][since] failed validation)                                                                                           
    at org.apache.cassandra.thrift.Cassandra$batch_mutate_result$batch_mutate_resultStandardScheme.read(Cassandra.java:28232)                                                               
    at org.apache.cassandra.thrift.Cassandra$batch_mutate_result$batch_mutate_resultStandardScheme.read(Cassandra.java:28218)                                                               
    at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:28152)                                                                                                 
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)                                                                                                                 
    at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:1069)                                                                                                  
    at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:1055)                                                                                                       
    at com.sify.beacon.cf.TestGroups.insertColumns(TestGroups.java:588)



CREATE COLUMN FAMILY Groups
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND default_validation_class = UTF8Type;

代码:

public ColumnOrSuperColumn createColumnOrSuperColumn(String name, 长值,长时间戳)抛出 UnsupportedEncodingException {

ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE);
buffer.putLong(value);

Column column = new Column(ByteBuffer.wrap(name.getBytes("utf-8")));
column.setValue(ByteBuffer.wrap(buffer.array()));
column.setTimestamp(timestamp);

ColumnOrSuperColumn c = new ColumnOrSuperColumn();
c.setColumn(column);
return c;

}

我需要进行任何其他转换来解决此问题吗?

如果有人有想法,请告诉我。

【问题讨论】:

  • 你能发布你的列族定义..........
  • 是的,需要您的定义才能回答。但是您几乎肯定会发现使用其中一个用于 Cassandra 的 java 客户端要容易很多倍,例如datastax java 驱动程序。
  • 我已添加列族定义。请检查..

标签: cassandra


【解决方案1】:

我在创建键空间时删除了 default_validation_class。然后插入发生,包括长值。

感谢您的支持

【讨论】:

    【解决方案2】:

    请更换你的

    default_validation_class = UTF8Type to default_validation_class = LongType
    

    它应该可以工作。

    【讨论】:

    • 我认为它不会解决问题。因为我通过动态创建列族并插入不同类型的值,如字符串、字节、整数和长。
    • 我也像你说的那样改变了。但它抛出异常的原因是因为 state 是 string type 。 InvalidRequestException(为什么:(预期 8 或 0 字节长 (2))[Monito][Groups][state] 验证失败)
    • 您使用的是thrift客户端还是其他客户端?
    猜你喜欢
    • 2011-10-23
    • 2016-09-06
    • 2014-01-05
    • 1970-01-01
    • 2014-08-29
    • 2013-05-05
    • 2015-06-03
    • 2019-03-29
    • 1970-01-01
    相关资源
    最近更新 更多