Cassandra:插入timeuuid错误

man*_*ish 4 cql cassandra 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);
Run Code Online (Sandbox Code Playgroud)

我正在运行以下查询:

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));
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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)
Run Code Online (Sandbox Code Playgroud)

我正在使用cassandra 1.2.2.

Ana*_*nth 6

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

UUIDs.timeBased()

您可以在以下参考中找到以上内容

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