Hive中的复杂数据类型问题

时间:2014-11-12 11:30:33

标签: hadoop hive hiveql

我正在尝试使用复杂的数据类型在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

2 个答案:

答案 0 :(得分:1)

我自己解决了。

我们不需要明确地提及一组地图,默认情况下它会从另一个地图中获取值

答案 1 :(得分:0)

如下所示创建表并加载数据,然后您将获得所需的输出。

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 '#';