Cassandra并插入浮动柱

时间:2010-11-02 14:06:22

标签: java cassandra

我有以下Cassandra配置:


    <ColumnFamily CompareWith="LongType" Name="MiFamily">

但是当我尝试插入以下值时:


    public byte[] dateToByte(Date date) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();  
        DataOutputStream dos = new DataOutputStream(bos);  
        dos.writeLong(new Long(1).longValue());                      
        dos.flush();  
        byte[] data = bos.toByteArray();
        return data;        
    }

我得到以下异常:


    Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:A long is exactly 8 bytes)
at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:28)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:103)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:96)
    at me.prettyprint.cassandra.service.Operation.executeAndSetResult(FailoverOperator.java:384)
    at me.prettyprint.cassandra.service.FailoverOperator.operateSingleIteration(FailoverOperator.java:190)
    at me.prettyprint.cassandra.service.FailoverOperator.operate(FailoverOperator.java:99)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:151)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl.batchInsert(KeyspaceServiceImpl.java:107)
    at borrar.PruebasCassandra.insertData(PruebasCassandra.java:77)
    at borrar.PruebasCassandra.main(PruebasCassandra.java:96)
Caused by: InvalidRequestException(why:A long is exactly 8 bytes)
    at org.apache.cassandra.thrift.Cassandra$batch_insert_result.read(Cassandra.java:13332)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_insert(Cassandra.java:717)
    at org.apache.cassandra.thrift.Cassandra$Client.batch_insert(Cassandra.java:692)
    at me.prettyprint.cassandra.service.KeyspaceServiceImpl$1.execute(KeyspaceServiceImpl.java:100)
    ... 8 more

2 个答案:

答案 0 :(得分:0)

感谢您的帮助。使用batchInsert时我做错了。

答案 1 :(得分:0)

Cassandra 0.8.1确实支持Float:

使用Java Hector:

StringSerializer se = new StringSerializer();
FloatSerializer fls = new FloatSerializer();
mutator.insert("mykey", "User", HFactory.createColumn("ftest", 0.12345678f, se, fls));