メインコンテンツまでスキップ
バージョン: 26.x

EXPLODE_JSON_ARRAY_INT_OUTER

説明

explode_json_array_int_outerTable関数はJSON配列を受け取ります。その実装ロジックは、JSON配列を配列型に変換してからexplode関数を呼び出して処理することです。動作はexplode_outer(cast(<json_array> as Array<BIGINT>))と同等です。 LATERAL VIEWと組み合わせて使用する必要があります。

構文

EXPLODE_JSON_ARRAY_INT_OUTER(<json>)

パラメータ

  • <json> JSON型、内容は配列である必要があります。

戻り値

  • <json>内のすべての要素で構成された単一列、複数行の結果を返します。列の型はNullable<BIGINT>です。
  • <json>がNULLまたは空の配列(要素数が0)の場合、NULLを含む1行を返します。
  • JSON配列内の要素がINT型でない場合、関数はそれらをINTに変換しようとします。INTに変換できない要素はNULLに変換されます。型変換ルールについては、JSON タイプ Conversionを参照してください。

  1. データの準備

    create table example(
    k1 int
    ) properties(
    "replication_num" = "1"
    );

    insert into example values(1);
  2. 通常のパラメータ

    select * from example lateral view explode_json_array_int_outer('[4, 5, 5.23, null]') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | 4 |
    | 1 | 5 |
    | 1 | 5 |
    | 1 | NULL |
    +------+------+
  3. Non-INT型

    select * from example 
    lateral view
    explode_json_array_int_outer('["abc", "123.4", 9223372036854775808.0, 9223372036854775295.999999]') t2 as c;
    +------+---------------------+
    | k1 | c |
    +------+---------------------+
    | 1 | NULL |
    | 1 | 123 |
    | 1 | NULL |
    | 1 | 9223372036854774784 |
    +------+---------------------+

9223372036854775808.0BIGINT の有効な範囲を超えているため、NULL に変換されます。 > 文字列 "123.4" は 123 に変換されます。 > 文字列 "abc" は INT に変換できないため、結果は NULL になります。

  1. 空の配列

    select * from example lateral view explode_json_array_int_outer('[]') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+
  2. NULLパラメータ

    select * from example lateral view explode_json_array_int_outer(NULL) t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+
  3. 非配列パラメータ

    select * from example lateral view explode_json_array_int_outer('{}') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+