hive sql 行列转换

一行表多行。
sql:
select id,map_keys(sb)[0],map_values(sb)[0] from zqh_test lateral view explode(array(map(‘name’,name),map(‘age’,age),map(‘sex’,sex)))s as sb;

执行结果如下:
id _c1 _c2
2 name zqh2
2 age 31
2 sex M
1 name zqh
1 age 30
1 sex M

原表内容如下:
hive (pad_hdp)> select * from zqh_test;
OK
zqh_test.id zqh_test.name zqh_test.age zqh_test.sex
1 zqh 30 M
2 zqh2 31 M
Time taken: 0.11 seconds, Fetched: 2 row(s)

你可能感兴趣的:(hive sql 行列转换)