在星火文档演示如何创建从一个RDD数据框,使用Scala的case类来推断架构.我正在尝试使用重现此概念sqlContext.createDataFrame(RDD, CaseClass),但我的DataFrame最终为空.这是我的Scala代码:
// sc is the SparkContext, while sqlContext is the SQLContext.
// Define the case class and raw data
case class Dog(name: String)
val data = Array(
Dog("Rex"),
Dog("Fido")
)
// Create an RDD from the raw data
val dogRDD = sc.parallelize(data)
// Print the RDD for debugging (this works, shows 2 dogs)
dogRDD.collect().foreach(println)
// Create a DataFrame from the RDD
val dogDF = sqlContext.createDataFrame(dogRDD, classOf[Dog])
// Print the DataFrame for debugging (this fails, shows …Run Code Online (Sandbox Code Playgroud)