Monday, August 25, 2014

Apache Hive Working Example

# Opening Hive Terminal

Open terminal and simply type "hive"

# Listing all the databases

hive> show databases;
OK
default
Time taken: 0.022 seconds, Fetched: 1 row(s)

# Creating a New Databases in Hive

hive> CREATE DATABASE employee;
OK
Time taken: 0.069 seconds

# Listing the created databases

hive> show databases;    
OK
default
employee
Time taken: 0.012 seconds, Fetched: 2 row(s)

# Choosing/Selecting the Database

hive> use employee;
OK
Time taken: 0.018 seconds

# Creating a new Table in Database

hive> CREATE TABLE country_list (name STRING);
OK
Time taken: 0.083 seconds

# Listing the tables present in Databases

hive> show tables;
OK
country_list
Time taken: 0.03 seconds, Fetched: 1 row(s)

# Loading a dataset into Hive from HDFS

hive> LOAD DATA INPATH '/user/bigdata/hive/country_example.tsv' OVERWRITE INTO TABLE country_list;
Loading data to table employee.country_list
Deleted hdfs://bigdata-karthik9000/user/hive/warehouse/employee.db/country_list
Table employee.country_list stats: [numFiles1, numRows0, totalSize38, rawDataSize0]
OK
Time taken: 0.179 seconds

# Selecting all the values from Tables

hive> select * from country_list;
OK
Atlantis
Albania
China
France
Russia

Time taken: 0.056 seconds, Fetched: 6 row(s)
hive>

# Besides i have loaded the TSV file into the Hadoop HDFS

bigdata@bigdata-karthik~$ hadoop fs -ls /user/bigdata/hive
bigdata@bigdata-karthik~$ hadoop fs -put /home/bigdata/Downloads/hive/country_example.tsv /user/bigdata/hive
bigdata@bigdata-karthik~$ hadoop fs -ls /user/bigdata/hive
Found 1 items
-rw-r--r--   1 bigdata supergroup         38 2014-07-14 18:14 /user/bigdata/hive/country_example.tsv
bigdata@bigdata-karthik~$ 

1 comment: