0

我有一个流式应用程序,当我尝试调用HiveContext.getOrCreate时,它出错了以下stmt。 “在包蜂巢对象HiveContext不能在包访问org.apache.spark.sql.hiveHiveContext单身对象

我需要HiveContext代替SQLContext我的应用程序和创建新HiveContext每次不会是一个可行的解决方案。

这里是我的代码片段:

object sampleStreamingApp { 

    def createStreamingContext(checkpointDirectory: String): StreamingContext = { 
    val conf = new SparkConf().setAppName("sampleStreaming") 
    val sc = new SparkContext(conf) 
    val ssc = new StreamingContext(sc, Milliseconds(5000)) 
    ssc.checkpoint(checkpointDirectory) 
    val smDStream = ssc.textFileStream("/user/hdpuser/data") 
    val smSplitted = smDStream.map(x => x.split(";")).map(x => Row.fromSeq(x)) 
    smSplitted.foreachRDD { rdd => 
      val sqlContext = HiveContext.getOrCreate(rdd.sparkContext) 
      import sqlContext.implicits._ 
      <other code logic goes here> 
     } 
    } 
    ssc 
} 

def main(args: Array[String]) { 
    val checkpointDirectory = "hdfs://localhost:8020/user/dfml/checkpointing/AAA" 
    val ssc = StreamingContext.getActiveOrCreate(checkpointDirectory,() => createStreamingContext(checkpointDirectory)) 

    ssc.start() 
    ssc.awaitTermination() 
    } 
} 

任何帮助,将不胜感激

回答

0

对象HiveContext是私有的,因此它无法访问。