hive iterate over elements in array after splitting, or split on 2 separators

Viewed 22

is there a way to split a string in hive on 2 separators and in order, or perform and split, and iterate over each element in the array and split again?

For example:

string in question =

"123=apples;456=oranges"

If I split, SELECT split("123=apples;456=oranges", ";") I'll get an array ["123=apples", "456=oranges"], but I'd also like to split on = within this new array.

Looking to do this in pure SQL for Hive.

2 Answers
select map_values(str_to_map("123=apples;456=oranges", ";", "="))
_c0
["apples","oranges"]

The split in Hive actually support the regex string in Java regular expression, you can just do it by

SELECT split("123=apples;456=oranges", "\=|\;")
Related