Skip to main content
Last updated on

MAP

Description​

Constructs a MAP<K, V> of a specific type using several groups of key-value pairs

Syntax​

MAP( <key1> , <value1> [, <key2>, <value2> ... ])

Parameters​

Optional Parameters​

  • <key1> supports multiple types (refer to MAP<K, V>) to construct the key of the map
  • <value1> to construct the value of the map

Variable Parameters​

Supports multiple groups of key-value parameters

Return Value​

Returns a specific type MAP<K, V> constructed from several groups of key-value pairs

Notes​

  1. The number of parameters must be even (can be 0), otherwise an error will be reported.
  2. Key parameters can appear repeatedly, but Doris will remove duplicate keys.
  3. Keys can be NULL, and multiple NULL keys will be deduplicated.

Examples​

  1. Regular parameters

    select map(1, "100", 0.1, 2),map(1, "100", 0.1, 2)[1];
    +-----------------------+--------------------------+
    | map(1, "100", 0.1, 2) | map(1, "100", 0.1, 2)[1] |
    +-----------------------+--------------------------+
    | {1.0:"100", 0.1:"2"} | 100 |
    +-----------------------+--------------------------+
  2. No parameters case

    select map();
    +-------+
    | map() |
    +-------+
    | {} |
    +-------+
  3. NULL parameters

    select map(null, 2, 3, null);
    +-----------------------+
    | map(null, 2, 3, null) |
    +-----------------------+
    | {null:2, 3:null} |
    +-----------------------+
  4. If there are duplicate keys, they will be deduplicated

    select map(1, 2, 2, 11, 1, 3, null, "null 1", null, "null 2");
    +--------------------------------------------------------+
    | map(1, 2, 2, 11, 1, 3, null, "null 1", null, "null 2") |
    +--------------------------------------------------------+
    | {2:"11", 1:"3", null:"null 2"} |
    +--------------------------------------------------------+