-1
我想我的手在kafka火花結構化流,但得到一些異常,如異常在線程「主」「org.apache.spark.sql.AnalysisException :無法解析'device
'給定的輸入列:[value,offset,partition,key,timestamp,timestampType,topic];異常在線程「主」org.apache.spark.sql.AnalysisException:
附上我的代碼
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.types._
import org.apache.spark.sql.streaming.ProcessingTime
case class DeviceData(device: String, deviceType: String, signal: String)
object dataset_kafka {
def main(args: Array[String]): Unit = {
val spark = SparkSession
.builder()
.appName("kafka-consumer")
.master("local[*]")
.getOrCreate()
import spark.implicits._
spark.sparkContext.setLogLevel("WARN")
val df = spark
.readStream
.format("kafka")
.option("kafka.bootstrap.servers", "172.21.0.187:9093")
.option("subscribe", "test")
.option("startingOffsets", "earliest")
.load()
println(df.isStreaming)
println(df.printSchema())
val ds: Dataset[DeviceData] = df.as[DeviceData]
val values = df.select("device").where("signal == Strong")
values.writeStream
.outputMode("append")
.format("console")
.start()
.awaitTermination()
}
}
任何幫助如何解決這個問題?