LATERAL VIEW 使用语法
原文链接: https://www.deeplearn.me/2892.html
select a.id, b.son_order_path from f_jz_change_order_top_son a LATERAL VIEW explode(split(son_order_path, ',')) b as son_order_path
FROM 子句可以有多个 LATERAL VIEW 子句。 后续的 LATERAL VIEWS 可以引用出现在 LATERAL VIEW 左侧的任何表格中的列。
如下所示:
SELECT * FROM exampleTableLATERAL VIEW explode(col1) myTable1 AS myCol1LATERAL VIEW explode(myCol1) myTable2 AS myCol2; |
上面的示例 sql 中后面一个直接饮用之前的输出结果作为输入,假设有以下数据表:
| Array<int> col1 | Array<string> col2 |
| [1, 2] | [a”, “b”, “c”] |
| [3, 4] | [d”, “e”, “f”] |
查询语句
SELECT myCol1, col2 FROM baseTableLATERAL VIEW explode(col1) myTable1 AS myCol1; |
将会生成:
| int mycol1 | Array<string> col2 |
| 1 | [a”, “b”, “c”] |
| 2 | [a”, “b”, “c”] |
| 3 | [d”, “e”, “f”] |
| 4 | [d”, “e”, “f”] |
值会分开。