EXPLODE_NUMBERS
Descriptionβ
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.
Syntaxβ
EXPLODE_NUMBERS(<n>)
EXPLODE_NUMBERS_OUTER(<n>)
Parametersβ
Parameter | Description |
---|---|
<n> | Integer type input |
Return Valueβ
Returns a sequence of [0, n).
- Does not return any rows when n is 0 or NULL.
Examplesβ
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 |
+------+