1. 程式人生 > >scala學習-Description Resource Path Location Type value toDF is not a member of org.apache.spark.rdd.R

scala學習-Description Resource Path Location Type value toDF is not a member of org.apache.spark.rdd.R

編譯如下程式碼時,出現value toDF is not a member of org.apache.Spark.rdd.RDD[People] 錯誤

val rdd : RDD[People]= sparkSession.sparkContext.textFile(hdfsFile,2).map(line => line.split(“,”)).map(arr => People(arr(0),arr(1).trim.toInt))

rdd.toDF

  1. import sqlContext.implicits._ 語句需要放在獲取sqlContext物件的語句之後

  2. case class People(name : String, age : Int) 的定義需要放在方法的作用域之外(即Java的成員變數位置)

實際上只需要做到第二點即可解決錯誤(第一點做到可能就不會報錯了)