EXPLODE_JSON_ARRAY_JSON_OUTER
説明
explode_json_array_json_outerTable関数はJSON配列を受け取ります。その実装ロジックは、JSON配列を配列型に変換してからexplode_outer関数を呼び出して処理することです。この動作はexplode_outer(cast(<json_array> as Array<JSON>))と等価です。
この関数はLATERAL VIEWと組み合わせて使用する必要があります。
構文
EXPLODE_JSON_ARRAY_JSON_OUTER(<json>)
パラメータ
<json>JSON型、内容は配列である必要があります。
戻り値
<json>内のすべての要素で構成される単一列、複数行の結果を返します。列の型はNullable<JSON>です。<json>がNULLまたは空の配列(要素数が0)の場合、NULLを含む1行が返されます。
例
-
データを準備する
create table example(
k1 int
) properties(
"replication_num" = "1"
);
insert into example values(1); -
通常パラメータ
select * from example lateral view explode_json_array_json_outer('[4, "abc", {"key": "value"}, 5.23, null]') t2 as c;+------+-----------------+
| k1 | c |
+------+-----------------+
| 1 | 4 |
| 1 | "abc" |
| 1 | {"key":"value"} |
| 1 | 5.23 |
| 1 | NULL |
+------+-----------------+ -
空の配列
select * from example lateral view explode_json_array_json_outer('[]') t2 as c;+------+------+
| k1 | c |
+------+------+
| 1 | NULL |
+------+------+ -
NULLパラメータ
select * from example lateral view explode_json_array_json_outer(NULL) t2 as c;+------+------+
| k1 | c |
+------+------+
| 1 | NULL |
+------+------+ -
非配列パラメータ
select * from example lateral view explode_json_array_json_outer('{}') t2 as c;+------+------+
| k1 | c |
+------+------+
| 1 | NULL |
+------+------+