为什么Hive没有像MySQL那样的FIELDS ENCLOSED BY? [英] why don't Hive have FIELDS ENCLOSED BY like in MySQL?
问题描述
输入行:
vijay< \t> a-b-c,a-c-d,a-d-c
kumar< \t> abc,bcd
我创建了如下表格:
hive> create table user_infos(name string,path ARRAY< String> --i只需要数组)
ROW FORMAT DELIMITED FIELDS TERMINATED BY' \''收藏品
TERMINATED BY','线条终止'\ n'存为TEXTFILE;
收到的输出:
hive> select * from user_infos;
vijay[** \abc\**,** \acd\**,** \adc\**]
kumar[** \abc \**,** \bcd \**]
这里的问题是:我不想要双引号,即 \
必需输出:
vijay [abc,acd,adc]
kumar [abc,bcd]
是否有任何为什么要使用< STRONG>铜stom Serde 。任何东西都像ENCLOSED BY在mysql中一样?
我也遇到了同样的问题,因为我的字段用双引号并用分号(;)分隔。我的表名是employee1。
所以我搜索了链接,并找到了完美的解决方案。
@ ramisetty.vijay:是的,我们必须为此使用serde。请使用此链接下载serde jar: https:// github .com / downloads / IllyaYalovyy / csv-serde / csv-serde-0.9.1.jar
然后按照以下步骤使用蜂巢提示:
添加jar路径/ to / csv-serde.jar;
创建表employee1(id字符串,名称字符串,addr字符串)
行格式serde'com.bizo.hive.serde.csv.CSVSerde'
with serdeproperties(
separatorChar=\;,
quoteChar=\)
存储为文本文件
;
,然后使用以下查询从给定路径加载数据:
将数据本地inpath'path / xyz.csv'加载到表employee1中;
然后运行:
select * from employee1;
谢谢。
here is my case :
input lines:
"vijay" <\t> "a-b-c","a-c-d","a-d-c"
"kumar" <\t> "a-b-c","b-c-d""
i created table like this :
hive >create table user_infos(name string, path ARRAY<String> --i need array only)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' COLLECTION ITEMS
TERMINATED BY ',' LINES TERMINATED BY '\n' STORED AS TEXTFILE ;
output received :
hive > select * from user_infos ;
"vijay" ["**\"a-b-c\"**","**\"a-c-d\"**","**\"a-d-c\"**"]
"kumar" ["**\"a-b-c\"**","**\"b-c-d\"**"]
problem here is : i don't want double quotes i.e., \"
Required output :
vijay ["a-b-c","a-c-d","a-d-c"]
kumar ["a-b-c","b-c-d"]
Is there any why to achieve this not using custom Serde. Any thing like ENCLOSED BY like in mysql?
I was also stuck with the same issue as my fields are enclosed with double quotes and separated by semicolon(;). My table name is employee1.
So I have searched with links and I have found perfect solution for this.
@ramisetty.vijay: Yes, We have to use serde for this. Please download serde jar using this link : https://github.com/downloads/IllyaYalovyy/csv-serde/csv-serde-0.9.1.jar
then follow below steps using hive prompt :
add jar path/to/csv-serde.jar;
create table employee1(id string, name string, addr string)
row format serde 'com.bizo.hive.serde.csv.CSVSerde'
with serdeproperties(
"separatorChar" = "\;",
"quoteChar" = "\"")
stored as textfile
;
and then load data from your given path using below query:
load data local inpath 'path/xyz.csv' into table employee1;
and then run :
select * from employee1;
Thanks.
这篇关于为什么Hive没有像MySQL那样的FIELDS ENCLOSED BY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!