Record Class GroupingKey

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.GroupingKey
Record Components:
expression - the expression the rows are grouped by; never null
alias - the optional output column name

public record GroupingKey(Operand expression, Optional<String> alias) extends Record
A single grouping key of an aggregation (γ): the Operand expression the rows are grouped by, with an optional alias for the output column.

The expression is a full scalar expression, not merely a column reference, so a group may be formed over a derived value — e.g. γ YEAR(occurred_at) → yr, COUNT(id) → n (Events) groups by the parsed year. The common case γ customer_id, SUM(amount) (Orders) is simply a grouping over an AttributeOperand.

Examples:

  • Bare column: customer_id
  • Aliased column: customer_id → cust
  • Derived key: DATE_TRUNC('day', ts) → day
  • Constructor Summary

    Constructors
    Constructor
    Description
    GroupingKey(Operand expression, Optional<String> alias)
    Creates an instance of a GroupingKey record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the alias record component.
    aliased(Operand expression, String alias)
    A grouping key over an arbitrary expression, with an alias.
    column(String attribute)
    A grouping key over a bare column, without an alias.
    The input column name this key groups by, iff the key is a bare attribute reference (the alias, which only renames the output, is irrelevant here); empty for any derived expression.
    columns(List<String> attributes)
    Wraps a list of bare column names as grouping keys (order preserved).
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the expression record component.
    final int
    Returns a hash code value for this object.
    boolean
    Whether this key is a bare, unaliased column reference — the classic grouping form whose output column equals the input column.
    of(Operand expression)
    A grouping key over an arbitrary expression, without an alias.
    The name of the output column this grouping key produces: the alias() when present, otherwise the (unqualified) attribute name for a bare column, the function name for a function call, or the synthetic group for any other expression.
    The input columns of keys, iff every key is a bare attribute reference; empty if any key is a derived expression.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GroupingKey

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

    • column

      public static GroupingKey column(String attribute)
      A grouping key over a bare column, without an alias.
    • of

      public static GroupingKey of(Operand expression)
      A grouping key over an arbitrary expression, without an alias.
    • aliased

      public static GroupingKey aliased(Operand expression, String alias)
      A grouping key over an arbitrary expression, with an alias.
    • columns

      public static List<GroupingKey> columns(List<String> attributes)
      Wraps a list of bare column names as grouping keys (order preserved).
    • outputName

      public String outputName()
      The name of the output column this grouping key produces: the alias() when present, otherwise the (unqualified) attribute name for a bare column, the function name for a function call, or the synthetic group for any other expression. Schema inference and the optimizer use this so the produced column name is consistent everywhere.
      Returns:
      the output column name; never blank
    • columnName

      public Optional<String> columnName()
      The input column name this key groups by, iff the key is a bare attribute reference (the alias, which only renames the output, is irrelevant here); empty for any derived expression. Statistics lookups, streaming-γ gating, and SQL GROUP BY pushdown use this to distinguish a plain column from a computed key.
      Returns:
      the unqualified column name, or empty for an expression key
    • isPlainColumn

      public boolean isPlainColumn()
      Whether this key is a bare, unaliased column reference — the classic grouping form whose output column equals the input column.
      Returns:
      true if the key is an unaliased AttributeOperand
    • plainColumns

      public static Optional<List<String>> plainColumns(List<GroupingKey> keys)
      The input columns of keys, iff every key is a bare attribute reference; empty if any key is a derived expression. Used where a grouping can only be reasoned about (ordering-based streaming, GROUP BY pushdown) when it is entirely over plain columns.
      Parameters:
      keys - the grouping keys; must not be null
      Returns:
      the ordered column names, or empty if any key is an expression
    • 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.
    • expression

      public Operand expression()
      Returns the value of the expression record component.
      Returns:
      the value of the expression record component
    • alias

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