Skip to main content

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​

ParameterDescription
<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 |
+------+