Spark sql registerAsTable无法注册表

spark-shell 

val sqlContext = new org.apache.spark.sql.SQLContext(sc)
 import sqlContext._
 case class sogouDate(times:String,id:String,searchWord:String,retrunNumber:Int,clickNumber:Int,url:String)
 val sogou = sc.textFile("hdfs://SYH-1:8020/user/root/logs/15-08-04/sogou.1438622252122").map(_.split('\t')).map(w => sogouDate(w(0).toString,w(1).toString,w(2).toString,w(3).toInt,w(4).toInt,w(5).toString))
 sogou.registerAsTable("sogouDates")

scala> sogou.registerAsTable("sogouDates")
<console>:40:  error: value registerAsTable is not a member of org.apache.spark.rdd.RDD[sogouDate]
              sogou.registerAsTable("sogouDates")
                    ^

 

1.我明明导入包import sqlContext._  

 在registerAsTable隐式转换时

 error: value registerAsTable is not a member of org.apache.spark.rdd.RDD[sogouDate]
              sogou.registerAsTable("sogouDates")

2.我显示转换也不行

val sogouSchema = sqlContext.createSchemaRDD(sogou)

error: value createSchemaRDD is not a member of org.apache.spark.sql.SQLContext

不知道哪里有问题

songyh20 - 一句话介绍

赞同来自:

spark 1.3.0 1.4.1    上面练习的代码是使用 程超老师录播视频中的示例,并没有按照最新直播的示例。spark 最近的版本此api发生了变化。 不是registerAsTable,而是registerTempTable   正确代码如下:   val sqlContext = new org.apache.spark.sql.SQLContext(sc) import sqlContext.implicits._ case class Person(name: String, age: Int) val people = sc.textFile("examples/src/main/resources/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt)).toDF() people.registerTempTable("people") sqlContext.sql("select * from  people").show      

cenyuhai - 大数据工程师@滴滴快车

赞同来自:

你那个是什么版本的spark,这是官方的例子: 详细请看:http://spark.apache.org/docs/l ... .html val sqlContext = new org.apache.spark.sql.SQLContext(sc) import sqlContext.implicits._ sc.textFile("examples/src/main/resources/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt)).toDF()  people.registerTempTable("people")  

要回复问题请先登录注册