Cassandra UDT和JAVA

时间:2015-11-09 09:34:25

标签: java cassandra cassandra-cli

我对UDT有一些疑问,不确定它是否有错误。

这是我的类型定义和表定义

CREATE TYPE test_udt_bigint (
    id    varchar,
    data Map<int, bigint>
);

CREATE TYPE test_udt (
    id    varchar,
    data Map<int, int>
);

CREATE TABLE test_tbl_bigint (
    row_id varchar PRIMARY KEY,
    udt_data map<varchar, frozen<test_udt_bigint>>
);

CREATE TABLE test_tbl_int (
    row_id varchar PRIMARY KEY,
    udt_data map<varchar, frozen<test_udt>>
);

创建这些对象后,我使用cqlsh插入数​​据,它成功了,我可以使用select命令来检索数据。但是在通过JAVA插入数据后,会产生很多问题。

这是我用于插入数据的存储库: https://github.com/sophiah/cassandra_test/tree/master/cassandra-test-udt

将数据插入test_tbl_udt后,一切看起来都很棒,我可以正常通过cqlsh进行选择:

cqlsh:testcassandra> select * from test_tbl_int;

row_id | udt_data
--------+------------------------------------------------
test | {'key-01': {id: 'mapkey-01 ', data: {10: 20}}}
xxx |  {'key-01': {id: 'mapkey-01', data: {10: 20}}}

但是,在将数据插入test_tbl_bigint之后,有一些东西= 错误:

cqlsh:testcassandra> select * from test_tbl_int;
Traceback (most recent call last):
File "bin/cqlsh", line 1093, in perform_simple_statement
    rows = self.session.execute(statement, trace=self.tracing_enabled)
File "/opt/apache-cassandra-2.1.11/bin/../lib/cassandra-driver-internal-only-2.7.2.zip/cassandra-driver-2.7.2/cassandra/cluster.py", line 1602, in execute
    result = future.result()
File "/opt/apache-cassandra-2.1.11/bin/../lib/cassandra-driver-internal-only-2.7.2.zip/cassandra-driver-2.7.2/cassandra/cluster.py", line 3347, in result
    raise self._final_exception
error: unpack requires a string argument of length 4

cqlsh:testcassandra> select * from test_tbl_bigint;
NoHostAvailable: ('Unable to complete the operation against any hosts', {<Host: 127.0.0.1 datacenter1>: ConnectionShutdown('Connection to 127.0.0.1 is defunct',)})

任何建议?

感谢

1 个答案:

答案 0 :(得分:2)

简短的回答是da_test_tbl_bigint.java中的表名错误,它会尝试插入test_tbl_int。目前还不清楚为什么驱动程序没有发现错误,我会在弄清楚时更新我的​​答案。