我有下表
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。
答案 0 :(得分:6)
您应该插入通过datastax驱动程序生成的timeuuid。在您的情况下,由于您使用的是版本1 timeuuid,因此必须使用
UUIDs.timeBased()
您可以在以下参考资料中找到以上内容
http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/utils/UUIDs.html
答案 1 :(得分:0)
它看起来像一个bug(与https://issues.apache.org/jira/browse/CASSANDRA-5472类似或相同),并且你使用的是很老版本的Cassandra。我建议您升级到最新的1.2.x版本,重新测试您的方案并提出问题,如果问题仍然存在