Hive - Split delimited columns over multiple rows, select based on position

烂漫一生 提交于 2019-12-05 14:37:09

You can use posexplode() to create position index columns for your split arrays. Then, select only those rows where the position indices are equal.

SELECT id, col3, col4
  FROM test
  lateral VIEW posexplode(split(col1,'\002')) col1 AS pos3, col3
  lateral VIEW posexplode(split(col2,'\002')) col2 AS pos4, col4
  WHERE pos3 = pos4;

Output:

id col3 col4
1  5    7
1  6    8

Reference: Hive language manual - posexplode()

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!