hive map类型转多行

map类型转多行
将{“a”:“b”,“c”:“d”,“e”:“f”}转成3行

SELECT  a.c1,
        a.c_map,
        b.map_key,
        b.map_value
FROM    (
            SELECT  'test' AS c1,
                    MAP('a', 'b', 'c', 'd', 'e', 'f') AS c_map
        ) a
LATERAL VIEW
        EXPLODE(c_map) b AS map_key,
        map_value;

输出结果

c1             c_map               map_key  map_value       
test    {"a":"b","c":"d","e":"f"}       a       b                                                       
test    {"a":"b","c":"d","e":"f"}       c       d                                                       
test    {"a":"b","c":"d","e":"f"}       e       f  

hive udf

你可能感兴趣的:(hive,hive,hadoop,数据仓库)