The explode_numbers table function takes an integer n and expands all numbers within the range into multiple rows, each containing a single number. It is commonly used to generate a sequence of consecutive numbers and is often paired with LATERAL VIEW.
explode_numbers_outer, unlike explode_numbers, adds a NULL row when the table function generates zero rows.
EXPLODE_NUMBERS(<n>) EXPLODE_NUMBERS_OUTER(<n>)
| Parameter | Description |
|---|---|
<n> | Integer type input |
Returns a sequence of [0, n).
select e1 from (select 1 k1) as t lateral view explode_numbers(5) tmp1 as e1;
+------+ | e1 | +------+ | 0 | | 1 | | 2 | | 3 | | 4 | +------+
select e1 from (select 1 k1) as t lateral view explode_numbers(0) tmp1 as e1; Empty set
select e1 from (select 1 k1) as t lateral view explode_numbers_outer(0) tmp1 as e1;
+------+ | e1 | +------+ | NULL | +------+