Module com.darkcollective.relix.ast
Package com.darkcollective.relix.ast
Record Class AggregateFunction
java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.AggregateFunction
- Record Components:
operator- the aggregate operatorargument- the expression the operator reads (the ranking expression for ARGMAX/ARGMIN); never nullyieldExpr- for ARGMAX/ARGMIN, the expression whose value is returned at the extremal row; empty for every other operatoralias- 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 Summary
ConstructorsConstructorDescriptionAggregateFunction(AggregateOperator operator, Operand argument, Optional<Operand> yieldExpr, Optional<String> alias) Creates an instance of aAggregateFunctionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionalias()Returns the value of thealiasrecord component.static AggregateFunctionaliased(AggregateOperator operator, Operand argument, String alias) Creates an aggregate over an arbitrary expression, with an alias.static AggregateFunctionaliased(AggregateOperator operator, String attribute, String alias) Creates an aggregate over a bare column, with an alias.static AggregateFunctionarg(AggregateOperator operator, String attribute, String yieldColumn) Creates an argmax/argmin-style aggregate that ranks by columnattributeand returns columnyieldColumn, without an alias.static AggregateFunctionargAliased(AggregateOperator operator, String attribute, String yieldColumn, String alias) Creates an argmax/argmin-style aggregate over bare columns, with an alias.argument()Returns the value of theargumentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static AggregateFunctionof(AggregateOperator operator, Operand argument) Creates an aggregate over an arbitrary expression, without an alias.operator()Returns the value of theoperatorrecord component.The name of the output column this aggregate produces: thealias()when present, otherwise a syntheticoperator_argumentname (e.g.static AggregateFunctionsimple(AggregateOperator operator, String attribute) Creates an aggregate over a bare column, without an alias.final StringtoString()Returns a string representation of this record class.Returns the value of theyieldExprrecord component.
-
Constructor Details
-
Method Details
-
simple
Creates an aggregate over a bare column, without an alias. -
aliased
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 columnattributeand returns columnyieldColumn, without an alias.- Parameters:
operator-AggregateOperator.ARGMAXorAggregateOperator.ARGMINattribute- the ranking columnyieldColumn- 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.ARGMAXorAggregateOperator.ARGMINattribute- the ranking columnyieldColumn- the column to return at the extremal rowalias- the output column name- Returns:
- the aggregate function
-
of
Creates an aggregate over an arbitrary expression, without an alias. -
aliased
Creates an aggregate over an arbitrary expression, with an alias. -
outputName
The name of the output column this aggregate produces: thealias()when present, otherwise a syntheticoperator_argumentname (e.g.sum_amount,min_Abs, orsum_exprfor 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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
operator
Returns the value of theoperatorrecord component.- Returns:
- the value of the
operatorrecord component
-
argument
Returns the value of theargumentrecord component.- Returns:
- the value of the
argumentrecord component
-
yieldExpr
Returns the value of theyieldExprrecord component.- Returns:
- the value of the
yieldExprrecord component
-
alias
Returns the value of thealiasrecord component.- Returns:
- the value of the
aliasrecord component
-