一:准备
**在pom中配置hive**
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
二:操作
package g5.learning
import org.apache.spark.sql.SparkSession
object SparkSessionApp {
def main(args: Array[String]): Unit = {
val sparksession= SparkSession.builder().appName("SparkSessionApp")
.master("local[2]")
.enableHiveSupport()//使用到hive一定要开启这个
.getOrCreate()
// sparksession.sparkContext.parallelize(Array(1,2,3,4)).collect().foreach( println)
import sparksession.implicits._ //这个是隐式转换
val g5 = sparksession.sparkContext.parallelize(Array(("1","欢迎"),("2","你好"),("3","大白")))//这是一个rdd
.toDF("id","name ")
g5.show()
// sparksession.table("ruoze_emp").show
sparksession.stop()
}
}
三:注意
import sparksession.implicits._ //这个是隐式转换
.enableHiveSupport()//使用到hive一定要开启这个