cassandra thrift long insert - InvalidRequestException(why :( String未验证。)

时间:2014-05-23 13:38:37

标签: cassandra

我在Cassandra 2.0.7中使用thrift Api创建动态列族并插入long值。但它的投掷错误只适用于长型。其他类型如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,         long long,long timestamp)抛出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;

}

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

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

2 个答案:

答案 0 :(得分:2)

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

感谢您的支持

答案 1 :(得分:1)

请更改您的

default_validation_class = UTF8Type to default_validation_class = LongType

它应该有用。