2
votes

I am interested in loading specific columns into a table created in Hive.

Is it possible to load the specific columns directly or I should load all the data and create a second table to SELECT the specific columns?

Thanks

3

3 Answers

2
votes

Yes you have to load all the data like this :

LOAD DATA [LOCAL] INPATH /Your/Path [OVERWRITE] INTO TABLE yourTable;

LOCAL means that your file is on your local system and not in HDFS, OVERWRITE means that the current data in the table will be deleted.

So you create a second table with only the fields you need and you execute this query :

INSERT OVERWRITE TABLE yourNewTable 
yourSelectStatement 
FROM yourOldTable;
1
votes

It is suggested to create an External Table in Hive and map the data you have and then create a new table with specific columns and use the create table as command

create table table_name as select statement from table_name; 

For example the statement looks like this

create table employee as select id as id,emp_name as name from emp;
1
votes

Try this:

Insert into table_name
(
#columns you want to insert value into in lowercase
)
select columns_you_need from source_table;