3

我有一个问题,我尝试寻找解决方案,但无法解决任何问题,我希望获得任何 *pointers。

所以我正在尝试将 Spark 结构化流与 Apache Kudu 集成,我正在从 Kafka 读取流并进行一些处理,现在应该写入 Kudu 表,问题是 Spark 结构化流不提供对 Kudu 接收器的支持(即我知道吗?),我正在使用 foreach 编写器,但是一旦尝试在“ForeachWriter.process()”中创建一个数据框,它就会挂起并且永远不会继续

import org.apache.spark.sql.ForeachWriter
val foreachWriter = new  ForeachWriter[Row] {


  override def open(partitionId: Long,version: Long): Boolean = {
    val mySchema = StructType(Array(
      StructField("id", IntegerType),
      StructField("value", DoubleType),
      StructField("EventTimestamp", TimestampType)
    ))
       true
  }

  override def process(value: Row): Unit = {
    println("values\n------------------")

    val spark = SparkSession.builder.appName("Spark-Kafka-Integrations").master("local").getOrCreate()
    val valRDD=spark.sparkContext.parallelize(value.toSeq)
    val valRDF=valRDD.map(x=>x.toString.split(",").to[List])
    println(value)

    val valDF=spark.createDataFrame(valRDF)
    valDF.show()
    println("End values\n///////////////////")
    //shoud insert into kudu here
   }

  override def close(errorOrNull: Throwable): Unit = {
   }
}
   //count is a Dstream/streaming dataframe

count.writeStream.foreach(foreachWriter).outputMode("complete") .option("truncate", "false").start().awaitTermination()
4

0 回答 0