Hive Tutorial PDF
Hive Tutorial PDF
i
Apache Hive
This is a brief tutorial that provides an introduction on how to use Apache Hive
HiveQL with Hadoop Distributed File System. This tutorial can be your first step
towards becoming a successful Hadoop Developer with Hive.
Audience
This tutorial is prepared for professionals aspiring to make a career in Big Data
Analytics using Hadoop Framework. ETL developers and professionals who are into
analytics in general may as well use this tutorial to good effect.
Prerequisites
Before proceeding with this tutorial, you need a basic knowledge of Core Java,
Database concepts of SQL, Hadoop File system, and any of Linux operating system
flavors.
All the content and graphics published in this e-book are the property of Tutorials
Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy,
distribute or republish any contents or a part of contents of this e-book in any
manner without written consent of the publisher. We strive to update the contents
of our website and tutorials as timely and as precisely as possible, however, the
contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides
no guarantee regarding the accuracy, timeliness or completeness of our website
or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at [email protected].
i
Apache Hive
Table of Contents
About the Tutorial ····································································································································· i
Audience ··················································································································································· i
Prerequisites ············································································································································· i
1. INTRODUCTION ···················································································································· 1
Hadoop ···················································································································································· 1
Literals ··················································································································································· 24
ii
Apache Hive
7. ALTER TABLE······················································································································· 36
9. PARTITIONING ···················································································································· 47
iii
Apache Hive
Example ················································································································································· 59
Example ················································································································································· 61
Syntax ···················································································································································· 62
Example ················································································································································· 62
Syntax ···················································································································································· 66
Example ················································································································································· 66
Syntax ···················································································································································· 70
Example ················································································································································· 70
Syntax ···················································································································································· 74
Example ················································································································································· 74
JOIN ······················································································································································· 75
iv
1. INTRODUCTION Apache Hive
The term ‘Big Data’ is used for collections of large datasets that include huge volume, high
velocity, and a variety of data that is increasing day by day. Using traditional data
management systems, it is difficult to process Big Data. Therefore, the Apache Software
Foundation introduced a framework called Hadoop to solve Big Data management and
processing challenges.
Hadoop
Hadoop is an open-source framework to store and process Big Data in a distributed
environment. It contains two modules, one is MapReduce and another is Hadoop Distributed
File System (HDFS).
The Hadoop ecosystem contains different sub-projects (tools) such as Sqoop, Pig, and Hive
that are used to help Hadoop modules.
Sqoop: It is used to import and export data to and fro between HDFS and RDBMS.
The traditional approach using Java MapReduce program for structured, semi-
structured, and unstructured data.
The scripting approach for MapReduce to process structured and semi structured data
using Pig.
The Hive Query Language (HiveQL or HQL) for MapReduce to process structured data
using Hive.
What is Hive?
Hive is a data warehouse infrastructure tool to process structured data in Hadoop. It resides
on top of Hadoop to summarize Big Data, and makes querying and analyzing easy.
5
Apache Hive
Initially Hive was developed by Facebook, later the Apache Software Foundation took it up
and developed it further as an open source under the name Apache Hive. It is used by
different companies. For example, Amazon uses it in Amazon Elastic MapReduce.
Hive is not
A relational database
A design for OnLine Transaction Processing (OLTP)
A language for real-time queries and row-level updates
Features of Hive
Here are the features of Hive:
Architecture of Hive
The following component diagram depicts the architecture of Hive:
This component diagram contains different units. The following table describes each unit:
6
Apache Hive
User Interface Hive is a data warehouse infrastructure software that can create
interaction between user and HDFS. The user interfaces that Hive
supports are Hive Web UI, Hive command line, and Hive HD Insight
(In Windows server).
Meta Store Hive chooses respective database servers to store the schema or
Metadata of tables, databases, columns in a table, their data
types, and HDFS mapping.
HiveQL Process HiveQL is similar to SQL for querying on schema info on the
Engine Metastore. It is one of the replacements of traditional approach for
MapReduce program. Instead of writing MapReduce program in
Java, we can write a query for MapReduce job and process it.
Execution Engine The conjunction part of HiveQL process Engine and MapReduce is
Hive Execution Engine. Execution engine processes the query and
generates results as same as MapReduce results. It uses the flavor
of MapReduce.
HDFS or HBASE Hadoop distributed file system or HBASE are the data storage
techniques to store data into file system.
Working of Hive
The following diagram depicts the workflow between Hive and Hadoop.
7
Apache Hive
The following table defines how Hive interacts with Hadoop framework:
1 Execute Query
The Hive interface such as Command Line or Web UI sends query to Driver
(any database driver such as JDBC, ODBC, etc.) to execute.
2 Get Plan
The driver takes the help of query compiler that parses the query to check
the syntax and query plan or the requirement of query.
3 Get Metadata
4 Send Metadata
5 Send Plan
8
Apache Hive
The compiler checks the requirement and resends the plan to the driver.
Up to here, the parsing and compiling of a query is complete.
6 Execute Plan
7 Execute Job
8 Fetch Result
9 Send Results
10 Send Results
9
2. HIVE INSTALLATION Apache Hive
All Hadoop sub-projects such as Hive, Pig, and HBase support Linux operating system.
Therefore, you need to install any Linux flavored OS. The following simple steps are executed
for Hive installation:
$ java –version
If Java is already installed on your system, you get to see the following response:
If java is not installed in your system, then follow the steps given below for installing java.
Installing Java
Step I:
Download java (JDK <latest version> - X64.tar.gz) by visiting the following link
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.
Step II:
Generally, you will find the downloaded java file in the Downloads folder. Verify it and extract
the jdk-7u71-linux-x64.gz file using the following commands.
$ cd Downloads/
$ ls
jdk-7u71-linux-x64.gz
10
Apache Hive
$ ls
jdk1.7.0_71 jdk-7u71-linux-x64.gz
Step III:
To make java available to all the users, you have to move it to the location “/usr/local/”. Open
root, and type the following commands.
$ su
password:
# mv jdk1.7.0_71 /usr/local/
# exit
Step IV:
For setting up PATH and JAVA_HOME variables, add the following commands to ~/.bashrc
file.
export JAVA_HOME=/usr/local/jdk1.7.0_71
export PATH=PATH:$JAVA_HOME/bin
Now apply all the changes into the current running system.
$ source ~/.bashrc
Step V:
Use the following commands to configure java alternatives:
11
Apache Hive
12
Apache Hive
13