I am trying to convert RDD to DataFrame in Spark Streaming. I am following below process.
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)
I am providing input through socket nc -lk 9999
If I give "hello world" as my input it is showing me below error
StructType can not accept object 'hello world' in type <class 'str'>
expected output
+-------=-+
|text |
+---------+
hello world
+---------+