【发布时间】:2019-05-14 16:58:01
【问题描述】:
我正在尝试在 Spark Streaming 中将 RDD 转换为 DataFrame。我正在遵循以下流程。
socket_stream = ssc.socketTextStream("localhost", 9999)
def convert_to_df(rdd):
schema = StructType([StructField("text", StringType(), True)])
df =spark.createDataFrame(rdd, schema = schema)
df.show(10)
socket_stream.foreachRDD(convert_to_df)
我通过套接字nc -lk 9999提供输入
如果我输入“hello world”作为我的输入,它会显示以下错误
StructType can not accept object 'hello world' in type <class 'str'>
预期输出
+-------=-+
|text |
+---------+
hello world
+---------+
【问题讨论】:
标签: python apache-spark apache-spark-sql spark-streaming