本文介绍了Cassandra:插入timeuuid错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的表
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。
I am using cassandra 1.2.2.
推荐答案
您应该插入通过datastax驱动程序生成的timeuuid。在您的情况下,由于您正在使用版本1 timeuuid,因此必须使用
You should insert the timeuuid generated via datastax driver. In your case , since you are using version 1 timeuuid, you must use
您可以在以下参考文献中找到以上内容
You can find the above in following reference
这篇关于Cassandra:插入timeuuid错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!