flink CassandraSink.addSink(输入)类型不匹配

时间:2017-11-30 19:50:25

标签: scala cassandra apache-flink flink-streaming

我是Flink的新手。我正在尝试使用Flink 1.3.2从我们的Kinesis流中读取并将输出写入Cassandra表。该程序能够从Kinesis流式传输数据。

问题在于,当我执行'CassandraSink.addSink(countsStreaming)'时,它会让我'类型不匹配。 expected:DataStream [NotInferredIN],actual:DataStream [(String,Long)]'。我已经阅读了文档和源代码,并注意到addSink需要DataStream [IN]。

有人可以帮助我了解'IN'类型是什么以及如何解决这个问题?

提前致谢!

val env = StreamExecutionEnvironment.getExecutionEnvironment
val mapper = new ObjectMapper
val kinesis = env.addSource(new FlinkKinesisConsumer[String](
  "kinesis-stream", new SimpleStringSchema, ConsumerConfig))

//DataStream[(String, Long)]
val countsStreaming: DataStream[(String, Long)] = kinesis.map(x => mapper.readValue(x,classOf[java.util.Map[String,String]]))
  .map(x => x.get("game_name"))
  .map({x => (x,1L) })
  .keyBy(0)
  .timeWindow(Time.seconds(5))
  .sum(1)

countsStreaming.print()

CassandraSink.addSink(countsStreaming)
  .setQuery("INSERT INTO example.values (id, counter) values (?, ?);")
.setClusterBuilder(new ClusterBuilder() {
  override def buildCluster(builder: Cluster.Builder): Cluster = {
    builder.addContactPoint("0.0.0.0").build()
  }
}).build()

env.execute("StreamingExample")

1 个答案:

答案 0 :(得分:0)

问题是CassandraSink.addSink只接受Java DataStream。

您需要在scala DataStream之后添加.javaStream,然后类型不匹配应该消失。