Table Functions
Synopsis¶
A table function is a function that returns a set of zero or more rows. Contrast this to a scalar function, which returns a single value.
Table functions are analogous to the FlatMap
operation commonly found in
functional programming or stream processing frameworks such as
Kafka Streams.
Table functions are used in the SELECT clause of a query. They cause the query to output potentially more than one row for each input value.
The current implementation of table functions only allows a single column to be returned. This column can be any valid SQL type.
Here's an example of the EXPLODE
built-in table function, which takes an
ARRAY and outputs one value for each element of the array:
1 2 |
|
The following stream:
1 2 |
|
Would emit:
1 2 3 4 5 6 7 8 |
|
When scalar values are mixed with table function return values in a SELECT
clause, the scalar values, like sensor_id
in the previous example, are
copied for each value returned from the table function.
You can also use multiple table functions in a SELECT clause. In this
situation, the results of the table functions are "zipped" together. The total
number of rows returned is equal to the greatest number of values returned from
any of the table functions. If some of the functions return fewer rows than
others, the missing values are replaced with null
.
Here's an example that illustrates using multiple table functions in a SELECT clause.
With the following input data:
1 2 |
|
And the following stream:
1 2 |
|
Would give:
1 2 3 4 5 6 7 8 9 |
|
Functions¶
CUBE_EXPLODE
¶
Applies to: array Since: 0.7.0 | |
---|---|
1 |
|
For the specified array of columns, outputs all of their possible combinations.
The CUBE_EXPLODE
function produces 2^d new rows, where d is the number of columns
given as parameter.
Duplicate entries for columns with NULL
value are skipped.
For example, given the following input records:
1 2 |
|
And the following stream:
1 2 |
|
The CUBE_EXPLODE
function produces the following output:
1 2 3 4 5 6 |
|
EXPLODE
¶
Applies to: array Since: 0.6.0 | |
---|---|
1 |
|
Outputs one value for each of the elements in array
.
The output values have the same type as the array elements.