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

EXPLODE_MAP_OUTER

説明

explode_map_outer Table関数はmap型を受け取り、そのmapを複数の行に展開します。各行にはキーと値のペアが含まれます。 この関数はLATERAL VIEWと組み合わせて使用する必要があります。

構文

EXPLODE_MAP_OUTER(<map>)

パラメータ

  • <map> MAP型。

Return Value

  • <map>内のすべての要素で構成された単一列、複数行の結果を返します。列の型はNullable<Struct<K, V>>です。
  • <map>がNULLまたは空の場合、NULLを含む1行が返されます。

Examples

  1. データを準備

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

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

    select  * from example lateral view explode_map_outer(map("k", "v", "k2", 123, null, null)) t2 as c;
    +------+-----------------------------+
    | k1 | c |
    +------+-----------------------------+
    | 1 | {"col1":"k", "col2":"v"} |
    | 1 | {"col1":"k2", "col2":"123"} |
    | 1 | {"col1":null, "col2":null} |
    +------+-----------------------------+
  3. キー・バリューペアを個別の列に展開する

    select  * from example lateral view explode_map_outer(map("k", "v", "k2", 123, null, null)) t2 as k, v;
    +------+------+------+
    | k1 | k | v |
    +------+------+------+
    | 1 | k | v |
    | 1 | k2 | 123 |
    | 1 | NULL | NULL |
    +------+------+------+
  4. 空のオブジェクト

    select  * from example lateral view explode_map_outer(map()) t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+
  5. NULLパラメータ

    select  * from example lateral view explode_map_outer(cast('ab' as map<string,string>)) t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+