以下是我的数据集:
Jun name="balaji" id=101
Mar name="kumar" id=102
创建表:
create table sample(month string,name string, id int)
row format delimited fields terminated by 'space' map keys terminated by '=';
结果:
select * from sample;
JUN name="balaji" NULL
Mar name="kumar" NULL
预期结果:
JUN balaji 101
Mar kumar 102
请帮我解决这个问题。
答案 0 :(得分:2)
创建如下表格:
create table sample(mnth string,names map<string,string>,ids map<string,int>)
row format delimited fields terminated by ' ' map keys terminated by '=';
选择查询应为:
select mnth,names["name"],ids["id"] from sample;
result:
Jun "balaji" 101
Mar "kumar" 102
如果您从示例中解雇select *
:
Jun {"name":"\"balaji\""} {"id":101}
Mar {"name":"\"kumar\""} {"id":102}
要访问地图中的每个值,您需要传递names["name"]
。