可以直接使用
val conf = new SparkConf().setMaster("local").setAppName("sdf")
val sc = new SparkContext(conf)
val hiveContext = new HiveContext(sc)
val df = hiveContext.sql("drop table myhive.tablec ")
或者使用
val conf = new SparkConf().setMaster("local").setAppName("sdf")
val sc = new SparkContext(conf)
val hiveContext = new HiveContext(sc)
// val df = hiveContext.sql("drop table myhive.tablec ")
val spark = SparkSession.builder().config(conf).getOrCreate()
val df = spark.sqlContext.sql("select * from myhive.tablea").show()
使用spark时,必须按照上面的顺序,否则会报错
Exception in thread "main" org.apache.spark.sql.AnalysisException: Table or view not found: `myhive`.`tablea`; line 1 pos 14;
'Project [*]
+- 'UnresolvedRelation `myhive`.`tablea`
此外还需要将hive-site.xml,core-site.xml和hdfs-site.xml放到resources中