Skip to main content

EXPLODE_JSON_ARRAY_STRING_OUTER

Description

The explode_json_array_string_outer table function accepts a JSON array. Its implementation logic is to convert the JSON array to an array type and then call the explode_outer function for processing. The behavior is equivalent to: explode_outer(cast(<json_array> as Array<STRING>)). It should be used together with LATERAL VIEW.

Syntax

EXPLODE_JSON_ARRAY_STRING_OUTER(<json>)

Parameters

  • <json> JSON type, the content should be an array.

Return Value

  • Returns a single-column, multi-row result composed of all elements in <json>. The column type is Nullable<STRING>.
  • If <json> is NULL or an empty array (number of elements is 0), 1 row with NULL is returned.
  • If the elements in the JSON array are not of STRING type, the function will try to convert them to STRING. If conversion to STRING fails, the element will be converted to NULL. For type conversion rules, please refer to JSON Type Conversion.

Examples

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

    insert into example values(1);
  2. Regular parameters
    select * from example lateral view explode_json_array_string_outer('[4, "5", "abc", 5.23, null]') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | 4 |
    | 1 | 5 |
    | 1 | abc |
    | 1 | 5.23 |
    | 1 | NULL |
    +------+------+
  3. Empty array
    select * from example lateral view explode_json_array_string_outer('[]') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+
  4. NULL parameter
    select * from example lateral view explode_json_array_string_outer(NULL) t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+
  5. Non-array parameter
    select * from example lateral view explode_json_array_string_outer('{}') t2 as c;
    +------+------+
    | k1 | c |
    +------+------+
    | 1 | NULL |
    +------+------+