EXPLODE_OUTER Function
Description
The EXPLODE_OUTER function is used to expand array or map type expressions into multiple rows. Unlike EXPLODE, when the input is NULL or an empty array/empty map, EXPLODE_OUTER retains the original row and outputs NULL values, whereas EXPLODE directly discards that row.
This function can be used directly or in combination with LATERAL VIEW.
Syntax
Parameters
expr: The input array (ARRAY<T>) or map (MAP<K, V>) expression.
Return Results
- For array type input, each element in the returned result has the type
T. - For map type input, the returned result contains two columns, representing the key (
key) and value (value), with typesKandVrespectively. - When the input is NULL or an empty array/empty map, outputs one row of NULL values.
Examples
-
Expand an array, including NULL input cases:
-
Comparison with
EXPLODE(discards NULL and empty array rows): -
Expand a map type, including NULL input:
Notes
- When the input is NULL,
EXPLODE_OUTERretains the original row and outputs NULL, whereasEXPLODEdiscards that row. - When the input is an empty array
array()or empty mapmap(), the behavior is the same as NULL: retains the original row and outputs NULL. EXPLODE_OUTERis commonly used in LEFT JOIN semantic scenarios, ensuring that the main table rows are not lost even if the array/map is empty or NULL.- This function can be used directly in SELECT or in combination with
LATERAL VIEW.
