Sarah
Sarah

Reputation: 161

how to obtain a particular value from a map(string,string) field?

I have a table with the following two columns enter image description here

The format of event_detail column is map(string,string)

I want to obtain the visitor numbers who have value(B) in the event_detail

enter image description here

Upvotes: 3

Views: 4942

Answers (1)

leftjoin
leftjoin

Reputation: 38325

Query rows where event_detail["value(B)"] is not null:

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

Demo:

Create test table:

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

load data:

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

Select rows with value(B):

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

Upvotes: 4

Related Questions