2014-10-29 483 views
5

我正在嘗試創建case類對象的RDD。 。例如,spark創建RDD時找不到RDD類型

// sqlContext from the previous example is used in this example. 
// createSchemaRDD is used to implicitly convert an RDD to a SchemaRDD. 
import sqlContext.createSchemaRDD 

val people: RDD[Person] = ... // An RDD of case class objects, from the previous example. 

// The RDD is implicitly converted to a SchemaRDD by createSchemaRDD, allowing it to be stored using  Parquet. 
people.saveAsParquetFile("people.parquet") 

我試着給

case class Person(name: String, age: Int) 

    // Create an RDD of Person objects and register it as a table. 
    val people: RDD[Person] = sc.textFile("/user/root/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt)) 
    people.registerAsTable("people") 

我收到以下錯誤,完成部分從前面的例子:

<console>:28: error: not found: type RDD 
     val people: RDD[Person] =sc.textFile("/user/root/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt)) 

上出了什麼問題的任何想法? 在此先感謝!

回答

21

這裏的問題是明確的RDD[String]類型註釋。它看起來像RDD默認情況下不在spark-shell中導入,這就是爲什麼Scala抱怨它無法找到RDD類型。先嚐試運行import org.apache.spark.rdd.RDD

+0

謝謝你,喬希。 – user1189851 2014-10-29 16:49:46