代码:
package sparksql_hive
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.hive.HiveContext
object test {
def main(args: Array[String]): Unit = {
System.setProperty("HADOOP_USER_NAME", "cry")
val sparkConf = new SparkConf()
sparkConf.setAppName("test").setMaster("local")
val sparkContext = new SparkContext(sparkConf)
val hiveContext = new HiveContext(sparkContext)
hiveContext.sql("select count(*) as total from myhive.student").show()
sparkContext.stop()
}
}
------------------------------------------------------
注意如图:需要假如的三个文件: