Java 卡桑德拉约没有';不适用于保存时间戳

Java 卡桑德拉约没有';不适用于保存时间戳,java,cassandra,apache-beam,dataflow,Java,Cassandra,Apache Beam,Dataflow,这里是我的简单代码,它从pubsub订阅读取消息,并使用当前时间戳将消息体保存到Cassandra表 该消息已从订阅中使用,但没有向表插入记录,也没有错误消息 但是,如果我将日期类型“Timestamp”更改为Long-in-class TestTable,那么这段代码将正常工作并将记录插入表中 DROP TABLE IF EXISTS test_table; CREATE TABLE IF NOT EXISTS test_table( post_index int, inge

这里是我的简单代码,它从pubsub订阅读取消息,并使用当前时间戳将消息体保存到Cassandra表

该消息已从订阅中使用,但没有向表插入记录,也没有错误消息

但是,如果我将日期类型“Timestamp”更改为Long-in-class TestTable,那么这段代码将正常工作并将记录插入表中

DROP TABLE IF EXISTS test_table;

CREATE TABLE IF NOT EXISTS test_table(
    post_index int,
    ingestion_time TIMESTAMP,
    body text,
    PRIMARY KEY ((post_index))
);
这里是创建表的脚本

DROP TABLE IF EXISTS test_table;

CREATE TABLE IF NOT EXISTS test_table(
    post_index int,
    ingestion_time TIMESTAMP,
    body text,
    PRIMARY KEY ((post_index))
);
@Table(keyspace=“{keyspace\u name}”,name=“{Table\u name}”,
readConsistency=“本地仲裁”,
WriteConsistence=“本地仲裁”,
caseSensitiveKeyspace=false,
区分大小写(可设置为假)
类TestTable实现可序列化{
@分区键
@列(name=“post_index”)
整数后索引;
@列(name=“摄入时间”)
时间戳摄取时间;
@列(name=“body”)
弦体;
公共整数getPostIndex(){
返回后索引;
}
公共void setPostIndex(整数postIndex){
this.postIndex=postIndex;
}
公共时间戳getIngestionTime(){
返回摄取时间;
}
public void setIngestionTime(时间戳ingestionTime){
this.ingestionTime=ingestionTime;
}
公共字符串getBody(){
返回体;
}
公共体(字符串体){
这个身体=身体;
}
公共测试表(整数postIndex、时间戳ingestionTime、字符串体){
这个身体=身体;
this.ingestionTime=ingestionTime;
this.postIndex=postIndex;
}
公共测试表(){
这个。body=“”;
this.ingestionTime=Timestamp.from(Instant.now());
此.postIndex=0;
}
}
公共类TestCassandraJobJava{
公共静态void main(字符串[]args){
Pipeline Pipeline=Pipeline.create(PipelineOptionsFactory.fromArgs(args.create());
PCollection data=pipeline.apply(“ReadStrinsFromPubsub”,
publisubio.readStrings().fromSubscription(“projects/{project\u id}/subscriptions/{subscription\u name}”))
.apply(“window”,window.into(FixedWindows.of(Duration.standardSeconds(5)))
.apply(“CreateMutation”,ParDo.of(new DoFn)(){
@过程元素
public void processElement(@Element字符串字,OutputReceiver out){
TestTable t=newtesttable(new Random().nextInt(),java.sql.Timestamp.from(Instant.now()),word);
输出(t);
}
})).apply(CassandraIO.write()
.withHosts(Arrays.asList(“127.0.0.1”))
.带端口(9042)
.withKeyspace(“{keyspace}”)
.withLocalDc(“卡桑德拉”)
.withEntity(TestTable.class)
);
pipeline.run().waitUntilFinish();
}
}

要使其正常工作,您需要在Cassandra的
时间戳
java.sql.timestamp
之间安装一个编解码器。默认情况下,在Java驱动程序3.x中,
时间戳
被转换为
Java.util.Date
(请参阅),尽管您也可以通过使用Joda Time或Java 8.x Time API。在Java驱动程序4.x中,
即时
用于表示时间戳


对于
java.sql.Timestamp
,没有内置的编解码器,但是实现自己的编解码器应该不是很难,它非常详细地描述了自定义编解码器的创建和使用过程。

要使其正常工作,您需要在Cassandra的
Timestamp
java.sql.Timestamp
之间有一个编解码器。默认情况下,在Java驱动程序3.x中,
时间戳
被转换为
Java.util.Date
(请参阅),尽管您也可以通过使用Joda Time或Java 8.x Time API。在Java驱动程序4.x中,
即时
用于表示时间戳


java.sql.Timestamp
没有内置的编解码器,但是实现自己的编解码器应该不是很难,它非常详细地描述了自定义编解码器的创建和使用过程。

我们可以看到您试图处理的消息的示例吗?
Timestamp
的完整类名是什么?消息非常简单{“body”:“abc”}Timestamp的完整类名是java.sql.Timestamp我们可以看到您试图处理的消息的示例吗?
Timestamp
的完整类名是什么?消息是非常简单的json{“body”:“abc”}Timestamp的完整类名是java.sql.Timestamp