SQLContext.gerorCreate 不是一个值
SQLContext.gerorCreate is not a value
我收到错误 SQLContext.gerorCreate 不是对象 org.apache.spark.SQLContext 的值。这是我的代码
import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.Seconds
import org.apache.spark.streaming.kafka.KafkaUtils
import org.apache.spark.sql.functions
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types
import org.apache.spark.SparkContext
import java.io.Serializable
case class Sensor(id:String,date:String,temp:String,press:String)
object consum {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName("KafkaWordCount").setMaster("local[2]")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val sc=new SparkContext(sparkConf)
val lines = KafkaUtils.createStream(ssc, "localhost:2181", "spark-streaming-consumer-group", Map("hello" -> 5))
def parseSensor(str:String): Sensor={
val p=str.split(",")
Sensor(p(0),p(1),p(2),p(3))
}
val data=lines.map(_._2).map(parseSensor)
val sqlcontext=new SQLContext(sc)
import sqlcontext.implicits._
data.foreachRDD { rdd=>
val sensedata=sqlcontext.getOrCreate(rdd.sparkContext)
}
我也试过 SQLContext.getOrCreate 但同样的错误。
没有为 SparkContext
和 SQLContext
定义这样的 getOrCreate
函数。
getOrCreate
函数是为 SparkSession
个实例定义的,从中创建了 SparkSession
个实例。我们 从使用 getOrCreate
方法调用 .
创建的 SparkSession
实例中 获取 sparkContext
实例或 sqlContext
实例
希望解释清楚。
已更新
我上面做的解释适用于更高版本的spark。在 the blog as the OP is referencing, the author is using spark 1.6 and the api doc of 1.6.3 中明确指出
Get the singleton SQLContext if it exists or create a new one using the given SparkContext
我收到错误 SQLContext.gerorCreate 不是对象 org.apache.spark.SQLContext 的值。这是我的代码
import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.Seconds
import org.apache.spark.streaming.kafka.KafkaUtils
import org.apache.spark.sql.functions
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types
import org.apache.spark.SparkContext
import java.io.Serializable
case class Sensor(id:String,date:String,temp:String,press:String)
object consum {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName("KafkaWordCount").setMaster("local[2]")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val sc=new SparkContext(sparkConf)
val lines = KafkaUtils.createStream(ssc, "localhost:2181", "spark-streaming-consumer-group", Map("hello" -> 5))
def parseSensor(str:String): Sensor={
val p=str.split(",")
Sensor(p(0),p(1),p(2),p(3))
}
val data=lines.map(_._2).map(parseSensor)
val sqlcontext=new SQLContext(sc)
import sqlcontext.implicits._
data.foreachRDD { rdd=>
val sensedata=sqlcontext.getOrCreate(rdd.sparkContext)
}
我也试过 SQLContext.getOrCreate 但同样的错误。
没有为 SparkContext
和 SQLContext
定义这样的 getOrCreate
函数。
getOrCreate
函数是为 SparkSession
个实例定义的,从中创建了 SparkSession
个实例。我们 从使用 getOrCreate
方法调用 .
SparkSession
实例中 获取 sparkContext
实例或 sqlContext
实例
希望解释清楚。
已更新
我上面做的解释适用于更高版本的spark。在 the blog as the OP is referencing, the author is using spark 1.6 and the api doc of 1.6.3 中明确指出
Get the singleton SQLContext if it exists or create a new one using the given SparkContext