來源:https://stackoverflow.com/questions/39619782/how-to-read-in-memory-json-string-into-spark-dataframe
先將字符串轉為RDD,再由RDD轉為DF。
From Spark SQL guide:
val otherPeopleRDD = spark.sparkContext.makeRDD( """{"name":"Yin","address":{"city":"Columbus","state":"Ohio"}}""" :: Nil) val otherPeople = spark.read.json(otherPeopleRDD) otherPeople.show()
This creates a DataFrame from an intermediate RDD (created by passing a String).