Record Class AggregateFunction

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.AggregateFunction
Record Components:
operator - the aggregate operator
argument - the expression the operator reads (the ranking expression for ARGMAX/ARGMIN); never null
yieldExpr - for ARGMAX/ARGMIN, the expression whose value is returned at the extremal row; empty for every other operator
alias - the optional output column name

public record AggregateFunction(AggregateOperator operator, Operand argument, Optional<Operand> yieldExpr, Optional<String> alias) extends Record
Represents an aggregate function in an aggregation operation. An aggregate function applies an operator (SUM, AVG, COUNT, MIN, MAX, COLLECT, ARGMAX, ARGMIN) to an Operand argument, with an optional alias for the result.

The argument is a full scalar expression, not merely a column reference, so an aggregate may be computed over a derived value — e.g. SUM(price * qty) or MIN(Abs(delta)). The common case SUM(amount) is simply an aggregate over an AttributeOperand.

The ARGMAX/ARGMIN operators additionally carry a yield expression: ARGMAX(rank, yield) ranks rows by argument and returns the yieldExpr value of the extremal row. For every other operator the yield expression is empty.

Examples:

  • Simple aggregate: SUM(salary)
  • Derived aggregate: SUM(price * qty), MIN(Abs(delta))
  • Aliased aggregate: SUM(salary) → total_salary
  • Argmax: ARGMAX(amount, order_id) → biggest_order
  • Constructor Details

    • AggregateFunction

      public AggregateFunction(AggregateOperator operator, Operand argument, Optional<Operand> yieldExpr, Optional<String> alias)
      Creates an instance of a AggregateFunction record class.
      Parameters:
      operator - the value for the operator record component
      argument - the value for the argument record component
      yieldExpr - the value for the yieldExpr record component
      alias - the value for the alias record component
  • Method Details

    • simple

      public static AggregateFunction simple(AggregateOperator operator, String attribute)
      Creates an aggregate over a bare column, without an alias.
    • aliased

      public static AggregateFunction aliased(AggregateOperator operator, String attribute, String alias)
      Creates an aggregate over a bare column, with an alias.
    • arg

      public static AggregateFunction arg(AggregateOperator operator, String attribute, String yieldColumn)
      Creates an argmax/argmin-style aggregate that ranks by column attribute and returns column yieldColumn, without an alias.
      Parameters:
      operator - AggregateOperator.ARGMAX or AggregateOperator.ARGMIN
      attribute - the ranking column
      yieldColumn - the column to return at the extremal row
      Returns:
      the aggregate function
    • argAliased

      public static AggregateFunction argAliased(AggregateOperator operator, String attribute, String yieldColumn, String alias)
      Creates an argmax/argmin-style aggregate over bare columns, with an alias.
      Parameters:
      operator - AggregateOperator.ARGMAX or AggregateOperator.ARGMIN
      attribute - the ranking column
      yieldColumn - the column to return at the extremal row
      alias - the output column name
      Returns:
      the aggregate function
    • of

      public static AggregateFunction of(AggregateOperator operator, Operand argument)
      Creates an aggregate over an arbitrary expression, without an alias.
    • aliased

      public static AggregateFunction aliased(AggregateOperator operator, Operand argument, String alias)
      Creates an aggregate over an arbitrary expression, with an alias.
    • outputName

      public String outputName()
      The name of the output column this aggregate produces: the alias() when present, otherwise a synthetic operator_argument name (e.g. sum_amount, min_Abs, or sum_expr for a complex expression). Schema inference and the optimizer use this so the produced column name is consistent everywhere.
      Returns:
      the output column name; never blank
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • operator

      public AggregateOperator operator()
      Returns the value of the operator record component.
      Returns:
      the value of the operator record component
    • argument

      public Operand argument()
      Returns the value of the argument record component.
      Returns:
      the value of the argument record component
    • yieldExpr

      public Optional<Operand> yieldExpr()
      Returns the value of the yieldExpr record component.
      Returns:
      the value of the yieldExpr record component
    • alias

      public Optional<String> alias()
      Returns the value of the alias record component.
      Returns:
      the value of the alias record component