与一个 SparkSession 一起,应用程序可以从一个 已存在的 RDD( 中从一个百度的 R data.frame),或者一个 Hive 表中,或者从 Spark 数据源 中创建 DataFrame。
举个例子,下面基于一个 JSON 文件的内容创建一个 DataFrame :
val df = spark.read.json("examples/src/main/resources/people.json") // Displays the content of the DataFrame to stdout df.show() // +----+-------+ // | age| name| // +----+-------+ // |null|Michael| // | 30| Andy| // | 19| Justin| // +----+-------+ // 所有的示例代码可以在 Spark repo 的 “examples/src/main/scala/org/apache/spark/examples/sql/SparkSQLExample.scala” 中找到。