【发布时间】:2018-01-06 09:35:33
【问题描述】:
我有一个场景,我需要将HiveContext 作为参数传递给另一个函数。以下是我的代码以及我遇到问题的地方:
Object Sample {
def main(args:Array[String]){
val fileName = "SampleFile.txt"
val conf = new SparkConf().setMaster("local").setAppName("LoadToHivePart")
conf.set("spark.ui.port","4041")
val sc=new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val hc = new org.apache.spark.sql.hive.HiveContext(sc)
hc.setConf("hive.metastore.uris","thrift://127.0.0.1:9083")
test(hc,fileName)
sc.stop()
}
def test(hc:String, fileName: String){
//code.....
}
}
根据上面的代码,我无法将 HiveContext 变量“hc”从 main 传递给另一个函数。还尝试过:
def test(hc:HiveContext, fileName:String){}
但两者都显示错误。
【问题讨论】:
-
错误是什么?
-
如果您使用的是 Spark 2,则无论如何都不应该使用这些
标签: scala hadoop apache-spark spark-dataframe hivecontext