Generator functions
Note
To see which AWS data source integrations support these SQL functions, see Supported OpenSearch SQL commands and functions.
Function | Description |
---|---|
explode(expr) | Separates the elements of array `expr` into multiple rows, or the elements of map `expr` into multiple rows and columns. Unless specified otherwise, uses the default column name `col` for elements of the array or `key` and `value` for the elements of the map. |
explode_outer(expr) | Separates the elements of array `expr` into multiple rows, or the elements of map `expr` into multiple rows and columns. Unless specified otherwise, uses the default column name `col` for elements of the array or `key` and `value` for the elements of the map. |
inline(expr) | Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise. |
inline_outer(expr) | Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise. |
posexplode(expr) | Separates the elements of array `expr` into multiple rows with positions, or the elements of map `expr` into multiple rows and columns with positions. Unless specified otherwise, uses the column name `pos` for position, `col` for elements of the array or `key` and `value` for elements of the map. |
posexplode_outer(expr) | Separates the elements of array `expr` into multiple rows with positions, or the elements of map `expr` into multiple rows and columns with positions. Unless specified otherwise, uses the column name `pos` for position, `col` for elements of the array or `key` and `value` for elements of the map. |
stack(n, expr1, ..., exprk) | Separates `expr1`, ..., `exprk` into `n` rows. Uses column names col0, col1, etc. by default unless specified otherwise. |
Examples
-- explode SELECT explode(array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ SELECT explode(collection => array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ SELECT * FROM explode(collection => array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ -- explode_outer SELECT explode_outer(array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ SELECT explode_outer(collection => array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ SELECT * FROM explode_outer(collection => array(10, 20)); +---+ |col| +---+ | 10| | 20| +---+ -- inline SELECT inline(array(struct(1, 'a'), struct(2, 'b'))); +----+----+ |col1|col2| +----+----+ | 1| a| | 2| b| +----+----+ -- inline_outer SELECT inline_outer(array(struct(1, 'a'), struct(2, 'b'))); +----+----+ |col1|col2| +----+----+ | 1| a| | 2| b| +----+----+ -- posexplode SELECT posexplode(array(10,20)); +---+---+ |pos|col| +---+---+ | 0| 10| | 1| 20| +---+---+ SELECT * FROM posexplode(array(10,20)); +---+---+ |pos|col| +---+---+ | 0| 10| | 1| 20| +---+---+ -- posexplode_outer SELECT posexplode_outer(array(10,20)); +---+---+ |pos|col| +---+---+ | 0| 10| | 1| 20| +---+---+ SELECT * FROM posexplode_outer(array(10,20)); +---+---+ |pos|col| +---+---+ | 0| 10| | 1| 20| +---+---+ -- stack SELECT stack(2, 1, 2, 3); +----+----+ |col0|col1| +----+----+ | 1| 2| | 3|NULL| +----+----+