Class WindowFunctionExpression
- All Implemented Interfaces:
Expression
OVER clause) that appears nested inside a larger
expression — e.g. revenue - LAG(revenue) OVER (ORDER BY yr) in a SELECT item, or an inline
ROW_NUMBER() OVER (...) in a QUALIFY predicate.
Window functions are not evaluated per row by ExpressionEvaluatorVisitor; they are computed
over a whole partition by the window stage. This node lets a window call keep its place in the
expression AST (instead of being string-substituted out and re-parsed): the window stage precomputes
each call's per-row value and supplies it through the evaluator's result context, keyed by the call's
exact source text (getCallText()). The evaluator resolves this node to that value.
Carrying the call as a node — rather than swapping its text for a synthetic name and re-parsing — keeps the AST the single source of truth about the expression's structure.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Taccept(ExpressionVisitor<T> visitor) Accept a visitor for the visitor patternvoiddescribeCall(String name, List<Expression> callArgs) Record what the call IS, read off the parse tree when this node was built.voiddescribeOver(boolean distinctCall, List<Expression> partition, List<Expression> order, List<Boolean> ascending, List<Boolean> nullsFirst) Describe the OVER clause itself, so a message can re-print the call the way live's plan spells it — every key qualified, every sort key with its direction and null placement, the frame and the null treatment dropped — rather than as the source text it was written in.voidvoiddescribeWindow(boolean hasOrderBy, boolean hasRowsFrame) Record the SHAPE of the OVER clause, read off the same parse tree.voiddescribeWithinGroup(Expression ordered) Record the call'sWITHIN GROUP (ORDER BY …)key, which is where an ORDERED aggregate's VALUES come from — for a percentile the arguments carry only the fraction, so a node without this has nothing to type from but the fraction, and typed the fraction.The window call's exact source text; the key under which its per-row value is supplied.The window function's name, or null when this node was built without one.The PARTITION BY keys, or null when the OVER clause was never described.Where the call begins in its source, so a refusal can point at it.The star this window call's sole argument is — carrying its qualifier, EXCLUDE and ILIKE — as a star-shaped call the arity walk expands exactly as it expands the plain star call; null when the argument list is not a lone star.TheWITHIN GROUP (ORDER BY …)key, or null when the call carries no such clause.booleanbooleanWhether the OVER clause carries an ORDER BY.booleanWhether the OVER clause carries a ROWS frame of its own.voidsetPosition(SourcePosition position)
-
Constructor Details
-
WindowFunctionExpression
-
-
Method Details
-
getCallText
The window call's exact source text; the key under which its per-row value is supplied. -
getPosition
Where the call begins in its source, so a refusal can point at it. -
setPosition
-
describeCall
Record what the call IS, read off the parse tree when this node was built. Evaluation never uses it — the value still arrives by call text — but the static channel needs the name and arguments to type the window functions that hand their argument back, and re-parsing the text to recover them would make the text the source of truth again.- Parameters:
name- the function's name, upper-casedcallArgs- its argument expressions
-
describeWindow
public void describeWindow(boolean hasOrderBy, boolean hasRowsFrame) Record the SHAPE of the OVER clause, read off the same parse tree. AVG declares a different width over a window that carries a bare ORDER BY than over one that does not, and an explicit frame puts it back — a distinction nothing but these two flags can make, and one the call text must not be re-read to recover.- Parameters:
hasOrderBy- whether the OVER clause carries an ORDER BYhasRowsFrame- whether it carries a ROWS frame of its own — a RANGE frame does NOT count, because live treats a RANGE-framed window as CUMULATIVE for width purposes
-
isOrdered
public boolean isOrdered()Whether the OVER clause carries an ORDER BY. -
describeOver
public void describeOver(boolean distinctCall, List<Expression> partition, List<Expression> order, List<Boolean> ascending, List<Boolean> nullsFirst) Describe the OVER clause itself, so a message can re-print the call the way live's plan spells it — every key qualified, every sort key with its direction and null placement, the frame and the null treatment dropped — rather than as the source text it was written in.- Parameters:
distinctCall- whether the call wrote DISTINCTpartition- the PARTITION BY keys, in order (empty when none)order- the ORDER BY keys, in order (empty when none)ascending- per sort key, whether it is ascendingnullsFirst- per sort key, the explicit NULLS FIRST (TRUE) / LAST (FALSE), or null when unspecified
-
isDistinct
public boolean isDistinct() -
getPartitionKeys
The PARTITION BY keys, or null when the OVER clause was never described. -
getOrderKeys
-
getOrderAscending
-
getOrderNullsFirst
-
isRowsFramed
public boolean isRowsFramed()Whether the OVER clause carries a ROWS frame of its own.A RANGE frame deliberately does NOT count: live-verified,
OVER (ORDER BY y RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)declares the same width as a bare ORDER BY, while the ROWS spelling of the same span narrows it. The distinction is the FRAME KEYWORD, not what the frame actually spans. -
getFunctionName
The window function's name, or null when this node was built without one. -
getStarCall
The star this window call's sole argument is — carrying its qualifier, EXCLUDE and ILIKE — as a star-shaped call the arity walk expands exactly as it expands the plain star call; null when the argument list is not a lone star. -
describeStar
-
getArguments
-
describeWithinGroup
Record the call'sWITHIN GROUP (ORDER BY …)key, which is where an ORDERED aggregate's VALUES come from — for a percentile the arguments carry only the fraction, so a node without this has nothing to type from but the fraction, and typed the fraction.- Parameters:
ordered- the WITHIN GROUP ORDER BY expression, or null when the call has no such clause
-
getWithinGroupOrdered
TheWITHIN GROUP (ORDER BY …)key, or null when the call carries no such clause. -
accept
Description copied from interface:ExpressionAccept a visitor for the visitor pattern- Specified by:
acceptin interfaceExpression
-