[英]spark streaming rdd to json output without deprecation
下面的代码片段:df5数据帧可正确打印json,但isStream为false,在spark 2.2.0中也已弃用,因此我在最后两行代码中尝试了另一种方法,但它无法正确读取json,有任何建议?
val unionStreams = ssc.union(kinesisStreams)
unionStreams.foreachRDD ((rdd: RDD[Array[Byte]], time: Time) => {
val rowRDD = rdd.map(jstr => new String(jstr))
val schema = StructType(StructField("clientTime",StringType,nullable= true) :: StructField("clientIPAddress", StringType,nullable = true) :: Nil)
val df5 = sqlContext.read.schema(schema).json(rowRDD)
println(df5.isStreaming)
val df6 = spark.readStream.schema(schema).json(rdd.toString())
println(df6.isStreaming) )}
使用Dataset[String]
:
import sqlContext.implicits._
sqlContext.read.schema(schema).json(rowRDD.toDS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.