Apache spark 从Spark数据帧中删除空白字段
我使用spark structured streaming来使用kafka主题,该主题有几种类型的消息(每种类型的模式不同)。我定义了一个模式,其中包含不同类型消息的所有字段。Apache spark 从Spark数据帧中删除空白字段,apache-spark,apache-kafka,apache-spark-sql,spark-structured-streaming,Apache Spark,Apache Kafka,Apache Spark Sql,Spark Structured Streaming,我使用spark structured streaming来使用kafka主题,该主题有几种类型的消息(每种类型的模式不同)。我定义了一个模式,其中包含不同类型消息的所有字段。 如何从每行的dataframe中筛选空字段,或者如何使用动态模式从kafka中读取dataframe val inputDS=spark .readStream .格式(“卡夫卡”) .option(“kafka.bootstrap.servers”,“localhost:9092”) .期权(“认购”、“概述”) .l
如何从每行的dataframe中筛选空字段,或者如何使用动态模式从kafka中读取dataframe
val inputDS=spark
.readStream
.格式(“卡夫卡”)
.option(“kafka.bootstrap.servers”,“localhost:9092”)
.期权(“认购”、“概述”)
.load()
val schemaa:StructType=StructType(
排列(
StructField(“标题”,StringType,true),
StructField(“url”,StringType,true),
StructField(“内容”,StringType,true),
StructField(“收集时间”,StringType,true),
StructField(“时间”,StringType,true),
StructField(“用户头”,StringType,true),
StructField(“图像”,StringType,true)
)
)
inputDS.withColumn(“value”,来自_json($“value”.cast(StringType),schemaa))
//.filter()//todo筛选器空字段
.writeStream
.格式(“控制台”)
.start()
.终止
不能从行中删除单个列。也许可以将它从Kafka读入RDD,找出消息类型,并将其移动到正确模式的数据帧中。@Andrew非常感谢。我已经启用了alreday,将它从Kafka读入RDD,我想将它从spark流媒体升级到spark结构化流媒体。