Class WindowFunctionExpression

java.lang.Object
dev.frostlake.executor.expressions.WindowFunctionExpression
All Implemented Interfaces:
Expression

public class WindowFunctionExpression extends Object implements Expression
A window function call (one carrying an 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 Details

    • WindowFunctionExpression

      public WindowFunctionExpression(String callText)
  • Method Details

    • getCallText

      public String getCallText()
      The window call's exact source text; the key under which its per-row value is supplied.
    • getPosition

      public SourcePosition getPosition()
      Where the call begins in its source, so a refusal can point at it.
    • setPosition

      public void setPosition(SourcePosition position)
    • describeCall

      public void describeCall(String name, List<Expression> callArgs)
      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-cased
      callArgs - 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 BY
      hasRowsFrame - 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 DISTINCT
      partition - 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 ascending
      nullsFirst - per sort key, the explicit NULLS FIRST (TRUE) / LAST (FALSE), or null when unspecified
    • isDistinct

      public boolean isDistinct()
    • getPartitionKeys

      public List<Expression> getPartitionKeys()
      The PARTITION BY keys, or null when the OVER clause was never described.
    • getOrderKeys

      public List<Expression> getOrderKeys()
    • getOrderAscending

      public List<Boolean> getOrderAscending()
    • getOrderNullsFirst

      public List<Boolean> 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

      public String getFunctionName()
      The window function's name, or null when this node was built without one.
    • getStarCall

      public FunctionCallExpression 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

      public void describeStar(FunctionCallExpression star)
    • getArguments

      public List<Expression> getArguments()
    • describeWithinGroup

      public void describeWithinGroup(Expression ordered)
      Record the call's WITHIN 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

      public Expression getWithinGroupOrdered()
      The WITHIN GROUP (ORDER BY …) key, or null when the call carries no such clause.
    • accept

      public <T> T accept(ExpressionVisitor<T> visitor)
      Description copied from interface: Expression
      Accept a visitor for the visitor pattern
      Specified by:
      accept in interface Expression