Friday, March 30, 2018

HIVE - Loading Data Into Table




Once we have created the database and the Table .We are supposed to load some data inside that table. We will create a simple table and will load some data inside it.

CREATE TABLE EMPLOYEE (COL1 INT);





The table has been created with the name employee having a single column COL1.
We can check the details of the table with the help of the DESCRIBE command.



We can load data either from the local file system or from the Hadoop file system.
We will see both the example separately .First of all, we load the data from the local filesystem.

Data Loading From Local Filesystem 

Load data local inpath 'sangam/test.txt' into table employee;





Similarly ,we can load the data from the HDFS via using the below command.

Data Loading From HDFS 

Load data inpath 'hivetest/test.txt' into table employee;





We should note that when we are using the local filesystem , we need to use the local keyword .We can verify the data using the below command.





 
Since ,we have loaded the data twice once through the local filesystem and other through the HDFS .so we are getting the duplicates in the table.

Data Loading through another HIVE table
We can load from other table using the insert  and select command as we do this in the  SQL like databases;


Insert into employeenew select * from employee;

 




No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...