0

在 cqlsh 我试图插入一条记录:

INSERT INTO data 
(order_id,order_ts,transaction_id,transaction_discount,transaction_qty,
transaction_total,
product_category,product_profit,product_upc,product_name,product_price,
product_distributor,
store_id,store_name,store_state,store_region,id) 

values ('YBC8RWE18',1368438171000,'LQKLVVI4E', 0, 1, 140.72, 
'Office Supplies', 12.42, 
'YT8899H3357', 'Casio USB Model FX-9860GII', 140.72, 'QR0', '2YOYWMR28Q', 
'BigLots', 'AZ', 
'Southwest', 2259a88e-b62d-4625-a86e-b86d77418a34 );

看起来不错,但我遇到了一个数字异常:

Caused by: java.lang.NumberFormatException: Zero length BigInteger
    at java.math.BigInteger.<init>(BigInteger.java:190)
    at org.apache.cassandra.serializers.DecimalSerializer.deserialize(DecimalSerializer.java:41)
    at org.apache.cassandra.serializers.DecimalSerializer.deserialize(DecimalSerializer.java:26)
    at org.apache.cassandra.db.marshal.AbstractType.compose(AbstractType.java:142)
    at org.apache.cassandra.db.marshal.DecimalType.compare(DecimalType.java:46)

看起来DecimalSerializer.deserialize真正的问题在这里。如果我尝试将小数括在引号中(我想值得一试),我会得到:

Bad Request: Invalid STRING constant (140.72) for product_price of type decimal

所以这没有帮助。我需要做什么才能插入小数?我应该发布 COLUMFAMILY def 吗?

这是描述表:

CREATE TABLE data (
  id uuid,
  order_id text,
  order_ts timestamp,
  product_category text,
  product_distributor text,
  product_name text,
  product_price decimal,
  product_profit decimal,
  product_upc text,
  store_id text,
  store_name text,
  store_region text,
  store_state text,
  transaction_discount decimal, 
  transaction_id text,
  transaction_qty int,
  transaction_total decimal,
  PRIMARY KEY (id)
)

如果我去掉 140.72 左右的引号,我会得到:Request did not complete within rpc_timeout.并且日志会显示deserialize错误。如果我尝试只插入几列,那很好——直到我尝试插入 product_price 字段。

4

2 回答 2

0

即使表上没有索引,也会出现同样的异常。如果您查看 BigInteger 的构造函数中的堆栈跟踪,public BigInteger(byte[] val)则当传入的字节数组为空时会引发异常。也许 Cassandra 驱动程序中存在反序列化十进制的错误?但是,有以下评论很有趣:

将包含 BigInteger 的二进制补码表示的字节数组转换为 BigInteger。输入数组假定为大端字节序:最高有效字节位于第零个元素中。

Cassandra 驱动程序会保证传递的字节数组是大端的吗?解决方案可以改用其他类型double

于 2015-04-20T21:53:39.367 回答
0

没有得到任何答案,但确实得到了一些帮助。

这个问题的答案不是很令人满意。没有一个错误真正让我知道发生了什么,但我想:好吧,这里实际上只有几个活动部分:表 def 和索引。所以我删除了表并在没有索引的情况下重新创建了它。修复了问题。重新创建索引,问题仍然得到解决。所以也许索引搞砸了?

于 2014-06-05T18:06:29.873 回答