Search This Blog

Step by step guide for creating a table in Apache Hive

This article covers how to create a table,how to check schema of the table and how to run Hive query.


1)
Create a local file named employe on the unix like below.

Sample : employee data.


Balu,300000,10,2014-02-01
Radha,350000,15,2014-02-05
Nitya,325000,15,2015-02-06
Bubly,350000,25,2015-05-01
Pandu,300000,35,2014-06-01
Nirupam,350000,40,2016-01-01
Sai,400000,25,2015-05-02
Bala,400000,20,2016-10-10




2)
Create a directory called employee in HDFS.

hdfs dfs -mkdir /user/hdfs/employee





3)
 Upload the above file (step 1) to above HDFS directory employee.

hdfs dfs -put employee /user/hdfs/employee






4) Confirm the local file employee is uploaded into HDFS directory employee.
hdfs dfs -ls /user/hdfs/employee





5)
Open hive prompt or beeline prompt. Hive prompt is outdated , Try to use beeline.





6)
Create table called employee in Hive using hive prompt .

create table employee(name string,salary int,deptno int,DOJ date)
row format delimited fields terminated by ',' location '/user/hdfs/employee';





7)

Check table is created in Hive.
show tables;



8)

Check the columns (schema) in table employee;
describe employee;


9)

Display any two rows in the table employee.

select * from employee limit 2;




No comments:

Post a Comment