Java 如何使用ApacheFlink删除Cassandra中的一行?

Java 如何使用ApacheFlink删除Cassandra中的一行?,java,apache-flink,cassandra-3.0,Java,Apache Flink,Cassandra 3.0,在ApacheFlink中,可以通过CassandraSink将行插入Cassandra。但是我找不到删除一行的方法 我还尝试编写自定义接收器,但得到了notserializableeexception。 如何构造删除操作的代码 public class MyCassandraSink implements SinkFunction<String> { private Cluster cluster = Cluster.builder() .addC

在ApacheFlink中,可以通过
CassandraSink
将行插入Cassandra。但是我找不到删除一行的方法

我还尝试编写自定义接收器,但得到了
notserializableeexception
。 如何构造删除操作的代码

public class MyCassandraSink implements SinkFunction<String> {

    private Cluster cluster = Cluster.builder()
            .addContactPoint("127.0.0.1")
            .build();

    private Session cassandra = cluster.connect("mykeyspace");

    @Override
    public void invoke(String value, Context context) throws Exception {
        cassandra.execute("SOME DELETE QUERY");
    }
}

要实现您自己的insert vs delete逻辑,请创建一个扩展
CassandraSinkBase
的接收器,并实现
send()
方法。请参见
AbstractCassandraTupleSink
作为执行此操作的示例。注意
CassandraSinkBase
如何避免Cassandra客户端的序列化问题,方法是将其设置为瞬态,并在
open()
调用中创建它。

我找到了一个解决方案,但我不喜欢它。CassandraPojoInputFormat可用于删除和更新行。(我还将其用于SELECT,顾名思义,SELECT似乎就是它的本意。)

事实上,这是唯一的救赎美德。我一直在使用它,直到我找到一个优雅的解决方案。我还在找

CassandraPojoInputFormat<MyThingyConnector> myThingyCassandraPojoInputFormat =
new CassandraPojoInputFormat<MyThingyConnector>(
"DELETE FROM " + dbKeyspace + ".<table_name> <where clause>",
clusterBuilder,
MyThingyConnector.class);

myThingyCassandraPojoInputFormat.configure(null);
myThingyCassandraPojoInputFormat.open(cassandraInputSplit);
myThingyCassandraPojoInputFormat.close();
CassandraPojoInputFormat myThingyCassandraPojoInputFormat=
新Cassandrapojoinput格式(
“从“+dbKeyspace+”中删除”,
clusterBuilder,
MyThingyConnector.class);
myThingyCassandraPojoInputFormat.configure(null);
myThingyCassandraPojoInputFormat.open(cassandraInputSplit);
myThingyCassandraPojoInputFormat.close();
CassandraPojoInputFormat<MyThingyConnector> myThingyCassandraPojoInputFormat =
new CassandraPojoInputFormat<MyThingyConnector>(
"DELETE FROM " + dbKeyspace + ".<table_name> <where clause>",
clusterBuilder,
MyThingyConnector.class);

myThingyCassandraPojoInputFormat.configure(null);
myThingyCassandraPojoInputFormat.open(cassandraInputSplit);
myThingyCassandraPojoInputFormat.close();