配置单元中的复杂数据类型问题

44u64gxh  于 2021-05-30  发布在  Hadoop
关注(0)|答案(2)|浏览(373)

我正在尝试使用复杂的数据类型在配置单元中创建一个表。
我的一列是字符串数组,另一列是Map数组。
将数据加载到表中之后,当我尝试查询数据时,在第三列(一个Map数组)中没有得到所需的结果。
以下是我的配置单元查询:
第一步:

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

第二步:

load data local inpath '/home/xyz/data.txt' overwrite into table transactiondb2;

第三步:

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
ee7vknir

ee7vknir1#

我自己解决的。
我们不需要显式地提到一个Map数组,默认情况下,它从一个Map中获取值

e7arh2l6

e7arh2l62#

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

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

相关问题