Hive 中的复杂数据类型问题
Posted
技术标签:
【中文标题】Hive 中的复杂数据类型问题【英文标题】:Complex Data Type issue in Hive 【发布时间】:2014-11-12 11:30:33 【问题描述】:我正在尝试使用复杂数据类型在 Hive 中创建一个表。
我的一个专栏是一个字符串数组,另一个是一个地图数组。
将数据加载到表中后,当我尝试查询数据时,在第三列(地图数组)中没有得到所需的结果。
以下是我的 Hive 查询:
第 1 步:
create table transactiondb2(order_id int,billtype array<string>,paymenttype array<map<string,int>>)ROW FORMAT
DELIMITED FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY '|'
MAP KEYS TERMINATED BY '#';
第 2 步:
load data local inpath '/home/xyz/data.txt' overwrite into table transactiondb2;
第 3 步:
select * from transactiondb2;
我的输出如下:
好的
1 ["A","B"] ["credit":null,"10":null,"cash":null,"25":null,"emi":null,"30":null]
2 ["C","D"] ["credit":null,"157":null,"cash":null,"45":null,"emi":null,"35":null]
3 ["X","Y"] ["credit":null,"25":null,"cash":null,"38":null,"emi":null,"50":null]
4 ["E","F"] ["credit":null,"89":null,"cash":null,"105":null,"emi":null,"85":null]
5 ["Z","A"] ["credit":null,"7":null,"cash":null,"79":null,"emi":null,"105":null]
6 ["D","Y"] ["credit":null,"30":null,"cash":null,"100":null,"emi":null,"101":null]
7 ["A","Z"] ["credit":null,"50":null,"cash":null,"9":null,"emi":null,"85":null]
8 ["B","Z"] ["credit":null,"70":null,"cash":null,"38":null,"emi":null,"90":null]
而我的输入文件数据如下:
1 A|B credit#10|cash#25|emi#30
2 C|D credit#157|cash#45|emi#35
3 X|Y credit#25|cash#38|emi#50
4 E|F credit#89|cash#105|emi#85
5 Z|A credit#7|cash#79|emi#105
6 D|Y credit#30|cash#100|emi#101
7 A|Z credit#50|cash#9|emi#85
8 B|Z credit#70|cash#38|emi#90
【问题讨论】:
【参考方案1】:我自己解决了。
默认情况下,我们不需要明确提及一组地图,它会从一个地图中获取值
【讨论】:
【参考方案2】:如下图创建表格并加载数据,即可得到想要的输出。
create table complex(id int,bill array<string>,paytype map<string,int>)
ROW FORMAT
DELIMITED FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY '|'
MAP KEYS TERMINATED BY '#';
【讨论】:
以上是关于Hive 中的复杂数据类型问题的主要内容,如果未能解决你的问题,请参考以下文章