hive中怎么导入带引号的csv文件
1个回答
2016-01-30 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517195
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
昨天晚上实践了下,解决方法有几种
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)
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)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询