Dev Woman
Dev Woman

Reputation: 88

Cassandra UDT and JAVA

I have some questions about UDT, not sure if it's bug or not.

here is my type definition and table definition

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>>
);

After creating those objects, I used cqlsh to insert data, it got success, and I can use select command to retrieve data. But after inserting data via JAVA, it will cause lots of problems.

Here is the repository I used for inserting data: https://github.com/sophiah/cassandra_test/tree/master/cassandra-test-udt

After inserting data into test_tbl_udt, everything looks great and I can select via cqlsh as normal:

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}}}

but, after inserting data into test_tbl_bigint, there are something = wrong:

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',)})

any suggestion?

thanks

Upvotes: 1

Views: 361

Answers (1)

Olivier Michallat
Olivier Michallat

Reputation: 2312

The short answer is that the table name is wrong in da_test_tbl_bigint.java, it tries to insert into test_tbl_int. It's not yet clear to me why the driver doesn't catch the error, I'll update my answer when I've figured it out.

Upvotes: 2

Related Questions