I have a table like this
+-----+------------------------------+
| id | mapCol |
+-----+------------------------------+
| id1 | {key1:val1, key2:val2} |
| id2 | {key1:val3, key2:val4} |
+-----+------------------------------+
so i can easily perform a query like
select explode(mapCol) as (key, val) from myTab where id='id1'
and i get
+--------+-----+
| key | val |
+--------+-----+
| key1 | val1|
| key2 | val2|
+--------+-----+
I want to generate a table like this
+-----+------+-----+
|id | key | val |
+-----+------+-----+
| id1 | key1 | val1|
| id1 | key2 | val2|
| id2 | key1 | val3|
| id2 | key2 | val4|
+-----+------------+
note that I want to display the id
alongwith the exploded rows. Also, for multiple id's, the key
may be repeated, hence I want the rows to reflect that. Basically, id
+ key
should be unique.
How would i write a query for this? I tried
select explode(mapCol) as (key, val), id from myTab
but i got
FAILED: SemanticException 1:66 Only a single expression in the SELECT clause is supported with UDTF's