如何从map(字符串,字符串)字段中获取特定值?

时间:2017-09-06 18:21:58

标签: hive hiveql

我有一张包含以下两列enter image description here

的表格

event_detail列的格式是map(字符串,字符串)

我想获取在event_detail

中有值(B)的访客号码

enter image description here

1 个答案:

答案 0 :(得分:2)

查询行where event_detail["value(B)"] is not null

select visitor_number
  from table
where event_detail["value(B)"] is not null

<强>演示:

创建测试表:

hive> create table test_t(visitor_number int,event_detail map<string,string>);
OK

加载数据:

hive> insert into test_t select 123, map("value(B)","Bye") union all  select 123, map("value(G)","Jet");
OK

选择值为(B)的行:

hive> select visitor_number from test_t where event_detail["value(B)"] is not null;
OK
123