Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Spark: If I use SparkSession, Am I Using Hive Context?

avatar
New Contributor

I can use SparkSession to get the list of tables in Hive, or access a Hive table as shown in the code below. Now my question is if in this case, I'm using Spark with Hive Context?

Or is it that to use hive context in Spark, I must directly use HiveContext object to access tables, and perform other Hive related functions?

spark.catalog.listTables.show
val personnelTable = spark.catalog.getTable("personnel")
3 REPLIES 3

avatar
Super Collaborator

I assume you're on Spark 2?

SparkSession, without explicitly creating SparkConf, SparkContext or SQLContext, encapsulates them within itself.

Also SparkSession has merged SQLContext and HiveContext in one object in Spark 2.0.

When building a session object, for example:

val spark = SparkSession .builder() .appName( "SparkSessionZipsExample" ) .config( "spark.sql.warehouse.dir" , warehouseLocation) .enableHiveSupport() .getOrCreate()

.enableHiveSupport() provides HiveContext functions. So you're able to use catalog functions since spark has provided connectivity to hive metastore on doing .enableHiveSupport()

https://spark.apache.org/docs/2.0.1/api/java/org/apache/spark/sql/SparkSession.Builder.html#enableHi...

You'll get more clarity by reading this https://databricks.com/blog/2016/08/15/how-to-use-sparksession-in-apache-spark-2-0.html

avatar
New Contributor

Thanks for the reply. Does this mean that spark object in spark-shell already has enableHiveSupport() enabled? or the spark.sql(), and spark.catalog that spark object provides are implemented by SparkSession even without enableHiveSupport()?

avatar
New Contributor

Yes, spark-shell has enableHiveSupport() already enabled