2010-11-02 112 views
1

我有以下卡桑德拉配置:卡桑德拉和插入浮动列


    <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 

+0

题外话,但:'dos.writeLong(new Long(1).longValue());'?! ''回合'dos.writeLong(1L);'? – 2010-11-02 14:13:51

+0

你的代码对我来说看起来很好。如预期的那样,字节数组的长度为8。你确定这是导致错误的代码吗? – dogbane 2010-11-02 14:37:19

回答

0

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

+1

你能解释一下你做错了什么,以及你如何解决它?其他人可能会遇到同样的问题。 – 2010-12-31 17:24:53

0

卡桑德拉0.8.1不支持浮点:

使用Java赫:

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