Description
Currently, str_to_map requires the delimiter arguments to be foldable expressions. For example, the following doesn't work in Spark SQL:
drop table if exists maptbl; create table maptbl as select ',' as del1, ':' as del2, 'a:1,b:2,c:3' as str; insert into table maptbl select '%' as del1, '-' as del2, 'a-1%b-2%c-3' as str; select str, str_to_map(str, del1, del2) from maptbl;
You get the following error:
str_to_map's delimiters must be foldable.; line 1 pos 12;
However, the above example SQL statements do work in Hive 2.3.9. There, you get:
+--------------+----------------------------+ | str | _c1 | +--------------+----------------------------+ | a:1,b:2,c:3 | {"a":"1","b":"2","c":"3"} | | a-1%b-2%c-3 | {"a":"1","b":"2","c":"3"} | +--------------+----------------------------+ 2 rows selected (0.13 seconds)
It's unlikely that an input table would have the needed delimiters in columns. The use-case is more likely to be something like this, where the delimiters are determined based on some other value:
select str, str_to_map(str, ',', if(region = 0, ':', '#')) as m from maptbl2;