2

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

user3782579
  • 315
  • 1
  • 4
  • 15

3 Answers3

2

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;
Junayy
  • 1,130
  • 7
  • 13
1

Try this:

Insert into table_name
(
#columns you want to insert value into in lowercase
)
select columns_you_need from source_table;
Vikrant Goel
  • 654
  • 6
  • 20
Utsav Jha
  • 366
  • 4
  • 16
1

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;