Cassandra:插入 timeuuid 错误

标签 cassandra cql datastax-java-driver

我有下表

create table test(
         userId varchar,
         notifId timeuuid,
         notification varchar,
         time bigint,read boolean,
         primary key(userId, notifId)) with clustering order by (notifId desc);

我正在运行以下查询:
PreparedStatement   pstmt  = session.prepare("INSERT INTO notifications(userId, notifId, notification, time, read) VALUES(?, now(), ?, ?, ?)");

BoundStatement      boundStatement  = new BoundStatement(pstmt);
        session.execute(boundStatement.bind("123", "hello", new Date().getTime(), false));

我收到以下错误:
Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Type error: cannot assign result of function now (type timeuuid) to notifid (type 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType)')
    at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
    at com.datastax.driver.core.ResultSetFuture.extractCause(ResultSetFuture.java:277)
    at com.datastax.driver.core.Session.toPreparedStatement(Session.java:281)
    at com.datastax.driver.core.Session.prepare(Session.java:172)
    at com.example.cassandra.SimpleClient.loadData(SimpleClient.java:130)
    at com.example.cassandra.SimpleClient.main(SimpleClient.java:214)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Type error: cannot assign result of function now (type timeuuid) to notifid (type 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType)')
    at com.datastax.driver.core.ResultSetFuture.convertException(ResultSetFuture.java:307)

我正在使用 cassandra 1.2.2。

最佳答案

您应该插入通过 datastax 驱动程序生成的 timeuuid。在您的情况下,由于您使用的是版本 1 timeuuid,您必须使用

UUIDs.timeBased()



您可以在以下引用中找到以上内容

http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/utils/UUIDs.html

关于Cassandra:插入 timeuuid 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23191933/

相关文章:

cassandra - CQL3 中一组列的 TTL 字段 - Cassandra

django - 在 centos 上使用 cassandra

java - cassandra单节点连接错误

cassandra - 关于如何在 DataStax java 驱动程序中使用 map cql 类型的示例

cassandra - 在 cassandra 中将一张表复制到另一张表

cassandra - Cassandra 如何存储文本等变量数据类型

ubuntu - Hadoop 找不到 cassandra CqlOutputFormat 类

java - Ignite C++ 客户端用于 cassandra 集成

java - 尽管使用了 -Xmx 堆选项,为什么 Cassandra 仍占用这么多内存?

java - 使用 "executeAsync"时如何限制对 cassandra 的写入请求?