Hive中创建结构体数组以及map
Posted 平常心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive中创建结构体数组以及map相关的知识,希望对你有一定的参考价值。
ROW FORMAT DELIMITED 分隔符设置开始语句
FIELDS TERMINATED BY:设置字段与字段之间的分隔符
COLLECTION ITEMS TERMINATED BY:设置一个复杂类型(array,struct)字段的各个item之间的分隔符
MAP KEYS TERMINATED BY:设置一个复杂类型(Map)字段的key value之间的分隔符
LINES TERMINATED BY:设置行与行之间的分隔符
例:
Hive> create table t(id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>)
> row format delimited
> fields terminated by ‘\t‘
> collection items terminated by ‘,‘
> map keys terminated by ‘:‘
> lines terminated by ‘\n‘;
OK
Time taken: 0.287 seconds
ROW FORMAT DELIMITED 必须在其它分隔设置之前,也就是分隔符设置语句的最前
LINES TERMINATED BY必须在其它分隔设置之后,也就是分隔符设置语句的最后,否则会报错
hive> create table t (id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>)
> row format delimited
> fields terminated by ‘\t‘
> lines terminated by ‘\n‘
> collection items terminated by ‘,‘
> map keys terminated by ‘:‘;
FAILED: ParseException line 5:0 missing EOF at ‘collection‘ near ‘‘\n‘‘
for example:
编辑本地文件:f.txt 内容为:1,2 1,2,3,4,5 1:value_1,2:value_2
导入本地文件:load data local inpath ‘/f.txt‘ into table t;
查询表数据:select * from t;
{"id1":1,"id2":2} ["1","2","3","4","5"] {1:"value_1",2:"value_2"}
参考链接:
http://blog.csdn.net/lichao23jordan/article/details/50378144
以上是关于Hive中创建结构体数组以及map的主要内容,如果未能解决你的问题,请参考以下文章