hive中怎么导入带引号的csv文件
1个回答
展开全部
解决方法有几种
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 ('inp缉订光寡叱干癸吮含经ut.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)
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 ('inp缉订光寡叱干癸吮含经ut.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)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询