I need to write data of my filtered stream to cassandra using Java and Datastax Spark Cassandra Connector.
I followed the datastax java documentation .
The documentation explains how to write a RDD to cassandra, but not how to write a Dstream.
I need to be able to save a PairDStream and I don't know how to do it, because all examples are written in scala.
I need to turn the following code written in scala in the java's code:
val wc = stream.flatMap(_.split("\\s+"))
.map(x => (x, 1))
.reduceByKey(_ + _)
.saveToCassandra("streaming_test", "words", SomeColumns("word", "count"))
Basically I have to save a JavaPairDStream<String, Integer>
Solution, in case anyone looking for the answer
To write a DStream or JavaDStream to Cassandra, need to import:
import static com.datastax.spark.connector.japi.CassandraStreamingJavaUtil.*;
and use javaFunctions(DStream<T> arg0)
or javaFunctions(JavaDStream<T> arg0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.