我想通过 Kudu API 编写和更新。这是maven依赖:
<dependency>
<groupId>org.apache.kudu</groupId>
<artifactId>kudu-client</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.kudu</groupId>
<artifactId>kudu-spark2_2.11</artifactId>
<version>1.1.0</version>
</dependency>
在下面的代码中,我不知道KuduContext
参数。
我在 spark2-shell 中的代码:
val kuduContext = new KuduContext("master:7051")
Spark 2.1 流式传输中的相同错误:
import org.apache.kudu.spark.kudu._
import org.apache.kudu.client._
val sparkConf = new SparkConf().setAppName("DirectKafka").setMaster("local[*]")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val messages = KafkaUtils.createDirectStream("")
messages.foreachRDD(rdd => {
val spark = SparkSession.builder.config(rdd.sparkContext.getConf).getOrCreate()
import spark.implicits._
val bb = spark.read.options(Map("kudu.master" -> "master:7051","kudu.table" -> "table")).kudu //good
val kuduContext = new KuduContext("master:7051") //error
})
然后是错误:
org.apache.spark.SparkException:此 JVM 中只能运行一个 SparkContext(请参阅 SPARK-2243)。要忽略此错误,请设置 spark.driver.allowMultipleContexts = true。当前运行的 SparkContext 创建于:org.apache.spark.sql.SparkSession$Builder.getOrCreate(SparkSession.scala:860)