I\'m using HiveContext with SparkSQL and I\'m trying to connect to a remote Hive metastore, the only way to set the hive metastore is through including the hive-site.xml on
I too faced same problem, but resolved. Just follow this steps in Spark 2.0 Version
Step1: Copy hive-site.xml file from Hive conf folder to spark conf.
Step 2: edit spark-env.sh file and configure your mysql driver. (If you are using Mysql as a hive metastore.)
Or add MySQL drivers to Maven/SBT (If using those)
Step3: When you are creating spark session add enableHiveSupport()
val spark = SparkSession.builder.master("local").appName("testing").enableHiveSupport().getOrCreate()
Sample code:
package sparkSQL
/**
* Created by venuk on 7/12/16.
*/
import org.apache.spark.sql.SparkSession
object hivetable {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder.master("local[*]").appName("hivetable").enableHiveSupport().getOrCreate()
spark.sql("create table hivetab (name string, age int, location string) row format delimited fields terminated by ',' stored as textfile")
spark.sql("load data local inpath '/home/hadoop/Desktop/asl' into table hivetab").show()
val x = spark.sql("select * from hivetab")
x.write.saveAsTable("hivetab")
}
}
Output: