How to check if table exists in Hive using Spark?

How to check if table exists in Hive using Spark?

Spark 2.0 or higher

// Create SparkSession object with enabled Hive support
val spark = SparkSession
.appName("Check table")
// Select database where you will search for table
spark.sqlContext.sql("use bigdata_etl")
res4: Boolean = true

Since Spark 1.6 to 2.0

// Get HiveContext from SparkContext
val sparkConf = new SparkConf().setAppName("Check table")
val sc = new SparkContext(sparkConf)
val hiveContext = new HiveContext(sc)
hiveContext.sql("use bigdata_etl")

If table will exist you will give the “true”, otherwise “false”

If you enjoyed this post please leave the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.

Thanks in advanced!

Please follow and like us:

Leave a Reply

Close Menu
Social media & sharing icons powered by UltimatelySocial

Enjoy this blog? Please spread the word :)