cwalet
cwalet

Reputation: 189

hive load data:how to specify file column separator and dynamic partition columns?

well I had some question on loading mysql data into hive2, and don't know how to specify the separator, I tried for serval times but got nothing.

Here below is the hive table,id is the partition column,

0: jdbc:hive2://localhost/> desc test;  
+-----------+------------+----------+  
| col_name  | data_type  | comment  |  
+-----------+------------+----------+  
| a         | string     |          |  
| id        | int        |          |  
+-----------+------------+----------+

When i execute

load data local inpath 'file:///root/test' into table test partition (id=1);

it says:

Invalid path ''file:///root/test'': No files matching path file

but it do exists.

I wish to dynamic partitioned by the specified file,so i add the very column into the file like this:

root@<namenode|~>:#cat /root/test  
a,1  
b,2

but it also failed,the docs say nothing about this,i guess it doesn't support right now. dose anyone got some idea in it? any help will be appreciated!

Upvotes: 2

Views: 10626

Answers (1)

BasicHorizon
BasicHorizon

Reputation: 171

If you want to specify column sperators it uses the command;

ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','

Replace the ',' with your separator

Also if you want to partition a Hive table you specify the column which you want to terminate on using;

CREATE TABLE Foo (bar int )
PARTITIONED BY (testpartition string)  
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','

Upvotes: 2

Related Questions