EXPLODE_JSON_ARRAY_INT
説明
explode_json_array_intTable関数はJSON配列を受け取ります。その実装ロジックは、JSON配列を配列型に変換してから処理のためにexplode関数を呼び出すことです。この動作はexplode(cast(<json_array> as Array<BIGINT>))と同等です。
この関数はLATERAL VIEWと組み合わせて使用する必要があります。
構文
EXPLODE_JSON_ARRAY_INT(<json>)
パラメータ
<json>JSON型、内容は配列である必要があります。
戻り値
<json>内のすべての要素で構成される単一列、複数行の結果を返します。列の型はNullable<BIGINT>です。<json>がNULLまたは空の配列(要素数が0)の場合、0行が返されます。- JSON配列内の要素がINT型でない場合、関数はそれらをINTに変換を試みます。INTに変換できない要素はNULLに変換されます。型変換ルールについては、JSON タイプ Conversionを参照してください。
例
-
データの準備
create table example(
k1 int
) properties(
"replication_num" = "1"
);
insert into example values(1); -
通常のパラメータ
select * from example lateral view explode_json_array_int('[4, 5, 5.23, null]') t2 as c;+------+------+
| k1 | c |
+------+------+
| 1 | 4 |
| 1 | 5 |
| 1 | 5 |
| 1 | NULL |
+------+------+ -
Non-INT型
select * from example
lateral view
explode_json_array_int('["abc", "123.4", 9223372036854775808.0, 9223372036854775295.999999]') t2 as c;+------+---------------------+
| k1 | c |
+------+---------------------+
| 1 | NULL |
| 1 | 123 |
| 1 | NULL |
| 1 | 9223372036854774784 |
+------+---------------------+
9223372036854775808.0はBIGINTの有効範囲を超えているため、NULLに変換されます。 > 文字列"123.4"は123に変換されます。 > 文字列"abc"はINTに変換できないため、結果はNULLになります。
-
空の配列
select * from example lateral view explode_json_array_int('[]') t2 as c;Empty set (0.03 sec) -
NULLパラメータ
select * from example lateral view explode_json_array_int(NULL) t2 as c;Empty set (0.03 sec) -
非配列パラメータ
select * from example lateral view explode_json_array_int('{}') t2 as c;Empty set (0.03 sec)