EXPLODE_NUMBERS_OUTER
Description
The explode_numbers_outer function accepts an integer and maps each number in the range to a separate row. It should be used together with LATERAL VIEW to flatten nested data structures into a standard flat table format. The main difference between explode_numbers_outer and explode_numbers is how they handle null values.
Syntax
EXPLODE_NUMBERS_OUTER(<int>)
Parameters
<int>Integer type
Return Value
- Returns an integer column
[0, n), with column typeNullable<INT>. - If
<int>is NULL, 0, or negative, 1 row with NULL is returned.
Examples
- Regular parameters
select * from (select 1 as k1) t1 lateral view explode_numbers_outer(10) t2 as c;+------+------+| k1 | c |+------+------+| 1 | 0 || 1 | 1 || 1 | 2 || 1 | 3 || 1 | 4 || 1 | 5 || 1 | 6 || 1 | 7 || 1 | 8 || 1 | 9 |+------+------+
- Parameter 0
select * from (select 1 as k1) t1 lateral view explode_numbers_outer(0) t2 as c;+------+------+| k1 | c |+------+------+| 1 | NULL |+------+------+
- NULL parameter
select * from (select 1 as k1) t1 lateral view explode_numbers_outer(NULL) t2 as c;+------+------+| k1 | c |+------+------+| 1 | NULL |+------+------+
- Negative parameter
select * from (select 1 as k1) t1 lateral view explode_numbers_outer(-1) t2 as c;+------+------+| k1 | c |+------+------+| 1 | NULL |+------+------+