找不到registerTempTable

时间:2016-06-06 17:26:42

标签: scala apache-spark

我在这里关注一个Spark示例http://spark.apache.org/docs/latest/sql-programming-guide.html

val people = sc.textFile("../spark-training/simple-app/examples/src/main/resources/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt))
people.registerTempTable("people")

我收到registerTempTable无法识别的错误。

在查看了一些Github项目后,在我看来,我有必要的导入:

import org.apache.spark.{SparkConf, SparkContext}

val conf = new SparkConf().setAppName("Select people")
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext._

build.sbt

name := "exercises"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.0.0"

libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.6.1"

我错过了什么?

1 个答案:

答案 0 :(得分:2)

在您的代码中,人们是RDD。 .hours_entered > i { position: absolute; top: 12px; left: 44px; } 是数据帧api,而不是RDD api。您的代码会从示例末尾删除`toDF()'位。你的第一行应该如下

registerTempTable