Inserting Data into Hive Table Inserting Data into Hive Table hadoop hadoop

Inserting Data into Hive Table


I think the best way is:
a) Copy data into HDFS (if it is not already there)
b) Create external table over your CSV like this

CREATE EXTERNAL TABLE TableName (id int, name string)ROW FORMAT DELIMITED   FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'STORED AS TEXTFILELOCATION 'place in HDFS';

c) You can start using TableName already by issuing queries to it.
d) if you want to insert data into other Hive table:

insert overwrite table finalTable select * from table name;


There's no direct way to insert 1 record at a time from the terminal, however, here's an easy straight forward workaround which I usually use when I want to test something:

Assuming that t is a table with at least 1 record. It doesn't matter what is the type or number of columns.

INSERT INTO TABLE fooSELECT '12', 'xyz'FROM tLIMIT 1;


Hive apparently supports INSERT...VALUES starting in Hive 0.14.

Please see the section 'Inserting into tables from SQL' at: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML