public final class TableFunctionLayout extends Object
UNNEST, a Hive-family
LATERAL VIEW), and which of the call's arguments each one is computed from. One rule for every consumer:
TableNamespace takes a function's column names from it, and TTable.getLateralColumnNames() and its
siblings publish the whole layout to the SQL-LR producer (plan 09 slice 11).
A column's inputs are the indexes, in getArguments(), of the arguments whose values make its value
("0,1"); the empty string says the column is computed over the rows the call generates and has no value of
an argument in it (an ordinal: WITH ORDINALITY, WITH OFFSET, FLATTEN's SEQ and
INDEX, posexplode's position). getRowInputs() lists the arguments whose values decide how
many rows the call generates. An argument that is in neither (a FLATTEN option) feeds nothing: the layout never says
"every argument flows into every column".
A call whose columns the vendor fixes has a layout: an unqualified built-in of the vendor
(myschema.flatten(...) is a user function that shares the name). So does a user table function the catalog
declares before the call (declaredColumns(gudusoft.gsqlparser.stmt.TCreateFunctionStmt), recorded on the call by recordDeclared(gudusoft.gsqlparser.nodes.TTable, gudusoft.gsqlparser.sqlenv.TSQLEnv)): its names only,
which arguments make them and decide its rows being its body's. Any other function, a call with a shape the rule
below does not settle (STRING_SPLIT with a non-constant enable_ordinal), has none. A call
whose rows are settled but not its columns (an UNNEST of several arrays without a column list naming one
column per array) has a layout without names: its rows still come from its arrays.
| Modifier and Type | Field and Description |
|---|---|
static String |
OVER_ROWS
The inputs of a column computed over the generated rows (an ordinal), with no argument value in it.
|
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
declaredColumns(TCreateFunctionStmt function)
The columns a CREATE FUNCTION declares its table result to have, in order: a
RETURNS TABLE (c ...) or
RETURNS @t TABLE (c ...) column list, else the output names of its query (SQL Server's inline
RETURN (SELECT ...), BigQuery's {@code CREATE TABLE FUNCTION ... |
List<TParseTreeNode> |
getArguments()
The arguments, in order: the call's own expressions, or the arrays of an
UNNEST (an expression, or the
column name of BigQuery's and Presto's UNNEST(t.arr)). |
List<String> |
getInputs()
Per column, the arguments whose values make it (
"0,1"), or OVER_ROWS; null when the names are
settled but the arguments are not (a FLATTEN call whose arguments the rule does not read). |
List<String> |
getNames()
The column names, in order; an element is null for a column the vendor leaves without a name a query can use
(BigQuery's element of an unaliased
UNNEST). |
String |
getRowInputs()
The arguments whose values decide the generated rows (
"0,1"; empty when none). |
boolean |
isClosed()
Whether the columns listed are all the call's columns: false when the element type of an array is not known
(an
UNNEST of a column may hold a STRUCT or ROW whose fields are columns of their own). |
static TableFunctionLayout |
of(TTable table)
The layout of a FROM item, or null when the item is not a call whose columns or rows this rule settles.
|
static void |
recordDeclared(TTable table,
TSQLEnv env)
Records on a function call in FROM the columns the catalog declares for the function it calls (a CREATE FUNCTION
of the input registered before the call, or the catalog's metadata), so every consumer of the layout reads the
columns resolver2 resolved the call with; nothing for a built-in this rule lays out, or an unknown function.
|
static List<TParseTreeNode> |
unnestArrays(TUnnestClause clause)
The arrays of an
UNNEST, in order: its expressions, or the column names the legacy form keeps
(UNNEST(t.arr) of BigQuery and Presto: a column list, no expression). |
public static final String OVER_ROWS
public List<String> getNames()
UNNEST). Null when only the rows are settled (an UNNEST of
several arrays without a column list for each): the call then has no column this rule names.public List<String> getInputs()
"0,1"), or OVER_ROWS; null when the names are
settled but the arguments are not (a FLATTEN call whose arguments the rule does not read).public String getRowInputs()
"0,1"; empty when none).public boolean isClosed()
UNNEST of a column may hold a STRUCT or ROW whose fields are columns of their own).public List<TParseTreeNode> getArguments()
UNNEST (an expression, or the
column name of BigQuery's and Presto's UNNEST(t.arr)).public static TableFunctionLayout of(TTable table)
getNames() is null settles the rows only.public static List<String> declaredColumns(TCreateFunctionStmt function)
RETURNS TABLE (c ...) or
RETURNS @t TABLE (c ...) column list, else the output names of its query (SQL Server's inline
RETURN (SELECT ...), BigQuery's CREATE TABLE FUNCTION ... AS SELECT ...); null when it declares
no table result or a column has no name (a wildcard, an expression without an alias). Registered with the
function in the catalog; a call of it in FROM has these columns (recordDeclared(gudusoft.gsqlparser.nodes.TTable, gudusoft.gsqlparser.sqlenv.TSQLEnv)).public static void recordDeclared(TTable table, TSQLEnv env)
public static List<TParseTreeNode> unnestArrays(TUnnestClause clause)
UNNEST, in order: its expressions, or the column names the legacy form keeps
(UNNEST(t.arr) of BigQuery and Presto: a column list, no expression).