hive中怎么导入带引号的csv文件
发布网友
发布时间:2022-04-10 15:25
我来回答
共1个回答
热心网友
时间:2022-04-10 16:55
昨天晚上实践了下,解决方法有几种
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)