gpt4 book ai didi

Cassandra:插入 timeuuid 错误

转载 作者:行者123 更新时间:2023-12-05 00:25:55 26 4
gpt4 key购买 nike

我有下表

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com