Cassandra UDT错误:unpack需要长度为8的字符串参数

时间:2015-10-20 11:31:27

标签: java cassandra user-defined-types

我在Cassandra中创建了两种类型,如下所示:

CREATE TYPE my.param (
    key text,
    value text
);

CREATE TYPE my.stats (
    value double,
    events int,
    users int
);

并尝试插入我这样做:

    String aid = "konoha3";
    String uid = "james3";
    String event = "payment3";
    long dates = 1445328622;
    Date deto = new Date(new Timestamp(dates).getTime());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Timestamp stamp = new Timestamp(System.currentTimeMillis());
    Date date = new Date(stamp.getTime());
    Map<UDTValue, UDTValue> item = new HashMap<UDTValue, UDTValue>();

    UserType params = cluster.getMetadata().getKeyspace("my").getUserType("param");
    UDTValue param1 = params.newValue().setString("key", "cid").setString("value", "7");
    UDTValue param2 = params.newValue().setString("key", "cid").setString("value", "8");
    UserType stats = cluster.getMetadata().getKeyspace("my").getUserType("stats");
    UDTValue stats1 = stats.newValue().setInt("users", 10).setInt("events", 12).setDouble("value", 12.0);
    UDTValue stats2 = stats.newValue().setInt("users", 11).setInt("events", 13).setDouble("value", 21.0);

    item.put(param1, stats1);
    item.put(param2, stats2);

    PreparedStatement ps = session.prepare(
            "INSERT INTO events_by_user_param " + "(appid, userid ,event,date, items) " + "VALUES (?,?,?,?,?)");

并确保我插入的字段是空的,我用以下方法仔细检查:

LOGGER.info("AID: " + aid);
LOGGER.info("AID: " + uid);
LOGGER.info("AID: " + event);
LOGGER.info("AID: " + date);
LOGGER.info("AID: " + item.entrySet());
session.execute(ps.bind(aid, uid, event, date, item));

它运行顺利,但是当我尝试时:

select * from table;

它给了我这个错误:

Traceback (most recent call last):
  File "/opt/apache-cassandra-2.1.9/bin/cqlsh", line 1093, in perform_simple_statement                                                                                                    
    rows = self.session.execute(statement, trace=self.tracing_enabled)                                                                                                                    
  File "/opt/apache-cassandra-2.1.9/bin/../lib/cassandra-driver-internal-only-2.6.0c2.post.zip/cassandra-driver-2.6.0c2.post/cassandra/cluster.py", line 1594, in execute                 
    result = future.result(timeout)                                                                                                                                                       
  File "/opt/apache-cassandra-2.1.9/bin/../lib/cassandra-driver-internal-only-2.6.0c2.post.zip/cassandra-driver-2.6.0c2.post/cassandra/cluster.py", line 3296, in result                  
    raise self._final_exception                                                                                                                                                           
error: unpack requires a string argument of length 8  

我尝试将null替换为item(UDT的地图)

session.execute(ps.bind(aid, uid, event, date, null));

它有效,所以我认为UDT地图有问题。

我想知道那可能是什么?

0 个答案:

没有答案