scala 创建RDD时未找到spark错误RDD类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26634621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spark error RDD type not found when creating RDD
提问by user1189851
I am trying to create an RDD of case class objects. Eg.,
我正在尝试创建案例类对象的 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")
I am trying to complete the part from the previous example by giving
我试图通过给出来完成上一个例子中的部分
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")
I get the following error:
我收到以下错误:
<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))
Any idea on what went wrong? Thanks in advance!
知道出了什么问题吗?提前致谢!
回答by Josh Rosen
The issue here is the explicit RDD[String]type annotation. It looks like RDDisn't imported by default in spark-shell, which is why Scala is complaining that it can't find the RDDtype. Try running import org.apache.spark.rdd.RDDfirst.
这里的问题是显式RDD[String]类型注释。看起来好像RDD不是在默认情况下导入的spark-shell,这就是 Scala 抱怨它找不到RDD类型的原因。先试试跑步import org.apache.spark.rdd.RDD。

