Class ConnectByExpander
[START WITH <pred>] CONNECT BY [PRIOR] c = [PRIOR] c.
The expansion walks the FROM clause's rows as a forest: the rows matching START WITH are the roots
(without START WITH every row is its own root, live-verified), and a row becomes a child of the row
above it whenever the CONNECT BY predicate holds with PRIOR bound to the parent and every other
reference bound to the candidate child. Each emitted row carries its own values plus two pseudo-column
groups, both hidden from SELECT * exactly as Snowflake hides them:
LEVEL— 1 for a root, +1 per step down;CONNECT_BY_ROOT$<col>— the root row's value of every source column, which is whatConnectByRootExpressionreads.
Snowflake applies WHERE to the EXPANDED rows (live-verified: filtering out a parent still keeps its children), so this runs before the WHERE stage and everything downstream sees an ordinary relation.
Snowflake performs no cycle detection — a cyclic hierarchy simply runs until the warehouse times out
(live-verified). An in-memory engine cannot hang, so the walk is bounded by MAX_DEPTH, the same
guard value the recursive-CTE fixpoint loop uses, and reports the cycle instead.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringTheLEVELpseudo-column's name.static final intMaximum hierarchy depth before the walk is reported as cyclic.static final StringThe out-of-the-way name a source column calledLEVELtakes in the expanded relation, so the nameLEVELresolves to the depth pseudo-column. -
Constructor Summary
ConstructorsConstructorDescriptionConnectByExpander(QueryExecutor executor, FunctionRegistry functionRegistry, Catalog catalog) -
Method Summary
Modifier and TypeMethodDescriptionexpand(List<Row> baseRows, Table baseTable, Table expandedTable, FrostlakeParser.ConnectByClauseContext clause, Map<String, Table> aliasToTable, List<Table> allTables) ExpandbaseRowsinto the hierarchy described by the clause, in depth-first pre-order (parent immediately before its subtree).expandedTable(Table baseTable) The relation the expansion produces: the source columns followed by theLEVELdepth pseudo-column and the hiddenCONNECT_BY_ROOT$<col>pseudo-columns.
-
Field Details
-
MAX_DEPTH
public static final int MAX_DEPTHMaximum hierarchy depth before the walk is reported as cyclic.- See Also:
-
LEVEL_COLUMN
TheLEVELpseudo-column's name.- See Also:
-
SHADOWED_LEVEL_COLUMN
The out-of-the-way name a source column calledLEVELtakes in the expanded relation, so the nameLEVELresolves to the depth pseudo-column.- See Also:
-
-
Constructor Details
-
ConnectByExpander
public ConnectByExpander(QueryExecutor executor, FunctionRegistry functionRegistry, Catalog catalog)
-
-
Method Details
-
expandedTable
The relation the expansion produces: the source columns followed by theLEVELdepth pseudo-column and the hiddenCONNECT_BY_ROOT$<col>pseudo-columns. The pseudo-column SHADOWS a source column of the same name — live, both the bareleveland the QUALIFIEDt.levelanswer the depth inside a CONNECT BY query, even over a table whose ownLEVELcolumn holds other values — so a clashing source column is renamed out of resolution here. Without a clash the depth column stays hidden fromSELECT *, exactly as before; with one it takes the source column's star slot. -
expand
public List<Row> expand(List<Row> baseRows, Table baseTable, Table expandedTable, FrostlakeParser.ConnectByClauseContext clause, Map<String, Table> aliasToTable, List<Table> allTables) ExpandbaseRowsinto the hierarchy described by the clause, in depth-first pre-order (parent immediately before its subtree). The result's rows matchexpandedTable(dev.frostlake.metastore.model.Table)'s shape.
-