Record Class SortSpecification

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.SortSpecification

public record SortSpecification(Operand expression, SortDirection direction) extends Record
A single sort key: the Operand expression to order by, the direction (SortDirection.ASC / SortDirection.DESC), and the implicit NULL placement.

The expression is a full scalar expression, not merely a column reference, so a relation may be ordered by a derived value — e.g. τ to_timestamp(logged) DESC (RawLogs). The common case τ name (Users) is simply an ordering by a bare AttributeOperand.

Null placement is not a surface-syntax option — the parser does not accept NULLS FIRST/NULLS LAST, so a specification carries no explicit placement; nullPlacement() gives the SQL-standard default that matches the direction.

  • Constructor Details

    • SortSpecification

      public SortSpecification(Operand expression, SortDirection direction)
      Creates an instance of a SortSpecification record class.
      Parameters:
      expression - the value for the expression record component
      direction - the value for the direction record component
    • SortSpecification

      public SortSpecification(String attribute, SortDirection direction)
      Convenience constructor for a sort key over a bare column — wraps attribute as an AttributeOperand. Keeps the many call sites (and tests) that sort by a plain column name unchanged.
  • Method Details

    • columnName

      public Optional<String> columnName()
      The input column name this key orders by, iff the key is a bare attribute reference; empty for a derived expression. Ordering-property reasoning and ORDER BY pushdown use this to distinguish a plain column from a computed key.
      Returns:
      the unqualified column name, or empty for an expression key
    • nullPlacement

      public NullPlacement nullPlacement()
      The effective NullPlacement for this sort key. Returns the SQL-standard default: NullPlacement.NULLS_LAST for SortDirection.ASC and NullPlacement.NULLS_FIRST for SortDirection.DESC.

      This matches the existing sort-executor behaviour, and is used by the merge-join comparator to guarantee consistent NULL ordering on both merge inputs.

      Returns:
      the effective null placement; never null
    • 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
    • direction

      public SortDirection direction()
      Returns the value of the direction record component.
      Returns:
      the value of the direction record component