なぜ次のエラーが発生するのですか?RDDでSpark/ScalaコンパイラがtoDFを見つけられないのはなぜですか[Map [Int、Int]]?
scala> import sqlContext.implicits._
import sqlContext.implicits._
scala> val rdd = sc.parallelize(1 to 10).map(x => (Map(x -> 0), 0))
rdd: org.apache.spark.rdd.RDD[(scala.collection.immutable.Map[Int,Int], Int)] = MapPartitionsRDD[20] at map at <console>:27
scala> rdd.toDF
res8: org.apache.spark.sql.DataFrame = [_1: map<int,int>, _2: int]
scala> val rdd = sc.parallelize(1 to 10).map(x => Map(x -> 0))
rdd: org.apache.spark.rdd.RDD[scala.collection.immutable.Map[Int,Int]] = MapPartitionsRDD[23] at map at <console>:27
scala> rdd.toDF
<console>:30: error: value toDF is not a member of org.apache.spark.rdd.RDD[scala.collection.immutable.Map[Int,Int]]
rdd.toDF
ので、ここで起こっているまさに、toDFは、データフレームにタイプ(scala.collection.immutable.Map[Int,Int], Int)
のRDDを変換ではなく、タイプscala.collection.immutable.Map[Int,Int]
のことができます。何故ですか?
def createDataFrame[A <: Product : TypeTag](rdd: RDD[A]): DataFrame
と
:あなたはcreateDataFrame
方法の2つの異なる実装を見つけることができます
org.apache.spark.sql.SQLContext
ソースを見てみる場合は、
sqlContext.createDataFrame(1 to 10).map(x => Map(x -> 0))
を使用できない理由と同じ理由で