Support Questions
Find answers, ask questions, and share your expertise
Alert: Please see the Cloudera blog for information on the Cloudera Response to CVE-2021-4428

Apache Zeppelin with Hive

Expert Contributor

I heard about Zeppelin in the past and now I wish to use it. I would like to visualize my data in Hive using Zeppelin. I am using CDH though πŸ™‚ , but I can install and configure it. I just want to know the basic steps to pull the hive tables to Zeppelin.


Expert Contributor

Thank you @Lester Martin. I am gonna try it in my VM.

Hello Alex:

You can access Hive tables via Zeppelin in two ways:

1) Use Zeppelin's native Hive interpreter directly by starting a code block with '%sql' interpreter command and issuing commands like 'show tables' or 'select * from table'

2) Via Spark by creating HiveContext and then loading hive table into DataFrame, like this:


// sc is an existing SparkContext.
val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)

sqlContext.sql("CREATE TABLE IF NOT EXISTS src (key INT, value STRING)")
sqlContext.sql("LOAD DATA LOCAL INPATH 'examples/src/main/resources/kv1.txt' INTO TABLE src")

// Queries are expressed in HiveQL
sqlContext.sql("FROM src SELECT key, value").collect().foreach(println)

FYI: Here is the quickest way to discover if you have access to your Hive "default" database tables:

val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)
val tables = sqlContext.sql("show tables")

tables: org.apache.spark.sql.DataFrame = [tableName: string, isTemporary: boolean]
|sample_07|      false|
|sample_08|      false|

Super Guru

In the installed Zeppelin setup on HDP 2.4 it's available.

Just run your queries


select * from hivetable


select * from hivetable

You should be able to connect the Hive interpreter standard way.