Support Questions

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

Apache Zeppelin with Hive

avatar
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.

1 ACCEPTED SOLUTION
5 REPLIES 5

avatar
Expert Contributor

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

avatar

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:

%spark

// 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)

avatar

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.show()

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

avatar
Master Guru

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

Just run your queries

%sql

select * from hivetable

%hive

select * from hivetable

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