How to load data from a text file to Hive table
In this post, I describe how to insert data from a text file to a hive table.
Suppose you have tab delimited file::
|
1 2 3 4 |
% cat /tmp/input.txt k1 v1 k2 v2 |
Create a Hive table stored as a text file.
|
1 2 3 4 |
create table test_table (k string, v string) </code><code>row format delimited </code><code>fields terminated by '\t' stored as textfile; |
Load the text file (stored locally) into the Hive table:
|
1 2 3 4 5 6 7 |
hive(test_db)> load data local inpath 'file:/homes/user/hive/input.txt' into table test_table; Loading data to table test_db.test_table OK Time taken: 0.43 seconds |
Create a Hive table stored as sequence file.
|
1 |
create table test_sq(k string, v string) stored as sequencefile; |
Now you can load into the sequence table from the text table:
|
1 |
insert into table test_sq select * from test_table; |












Pingback: Apache Pig Load ORC data from Hive Table | Learn for Master()
Pingback: Save data to Hive table Using Apache Pig | Learn for Master()
Pingback: An example to create a partitioned hive table | Learn for Master()