hadoop – 如何将键值对加载到hive表中?

以下是我的数据集:

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

请帮帮我.

最佳答案 创建这样的表:

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

如果您从样本中选择*:

   Jun  {"name":"\"balaji\""}   {"id":101}
   Mar  {"name":"\"kumar\""}    {"id":102}

要访问地图中的每个值,您需要传递名称[“name”].

点赞