hive导入CSV格式的数据

解决方法有几种
1),对csv文件做处理
2),hive定义inputstream,用正则表达式处理

2.1)cat /home/alex/test/testdata.txt
"1","alex","dba"
"2","james","dba"

2.2)hive> create table test_serde(c1 string,c2 string, c3 string) ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' WITH SERDEPROPERTIES ('input.regex' = '\"(.*)\",\"(.*)\",\"(.*)\"','output.format.string' = '%1$s\\001%2$s\\001%3$s') STORED AS TEXTFILE;
OK
Time taken: 0.09 seconds

2.3)hive> load data local inpath '/home/alex/test/testdata.txt' overwrite into table test_serde; Copying data from file:/home/alex/test/testdata.txt
Copying file: file:/home/alex/test/testdata.txt
Loading data to table default.test_serde
OK
Time taken: 0.185 seconds
2.4)hive> select * from test_serde; OK
1 alex dba
2 james dba
Time taken: 0.057 seconds, Fetched: 2 row(s)

你可能感兴趣的:(hive)