HCatalog Load Operation


HCatalog Load Operation

Generally, after creating a table in SQL, we can insert data using the Insert statement. But in HCatalog, we insert data using the LOAD DATA statement.
While inserting data into HCatalog, it is better to use LOAD DATA to store bulk records. There are two ways to load data: one is from local file system and second is from Hadoop file system.

Step 1 - Open a new terminal (CTRL + ALT + T) and Change the directory to /usr/local/hive/hcatalog/bin




$ cd $HCAT_HOME/bin

Step 2 - Creating a new employee table




$ ./hcat -e "CREATE TABLE IF NOT EXISTS employee( eid int, name String, salary String, destination String) \
COMMENT 'Employee details' \
ROW FORMAT DEIMITED \
FIELDS TERMINATED BY ' ' \
LINES TERMINATED BY '\n' \
STORED AS TEXTFILE;"


Step 3 - Check whether it is created or not. It shows all the tables that are present.




$ ./hcat -e "show tables;"

Step 4 - Create a new sample.txt file to load into employee table.




$ gedit sample.txt

Add the following lines to sample.txt save and close.

sample.txt




1201 Gopal 45000 Technicalmanager
1202 Manisha 45000 Proofreader
1203 Masthanvali 40000 Technicalwriter
1204 Kiran 40000 HrAdmin
1205 Kranthi 30000 OpAdmin


Step 5 - Execute the load operation. In my case the sample.txt file is saved in /home/hduser/Desktop/HCATALOG/ folder.




$ ./hcat -e "LOAD DATA LOCAL INPATH '/home/hduser/Desktop/HCATALOG/sample.txt' OVERWRITE INTO TABLE employee;"

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *