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

EXPLODE_MAP

説明

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

構文

EXPLODE_MAP(<map>)

パラメータ

  • <map> MAP型。

戻り値

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

  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(map()) t2 as c;
    Empty set (0.03 sec)
  5. NULLパラメータ

    select  * from example lateral view explode_map(NULL) t2 as c;
    Empty set (0.03 sec)