Record Class PivotNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.PivotNode
Record Components:
valueColumn - the column whose values fill the new pivot cells; must not be blank
keyColumn - the column whose distinct values become new column headers; must not be blank
groupKeys - the PER grouping columns; empty means one global group; must not be null
input - the source relation; must not be null
location - the source location of this node; never null
All Implemented Interfaces:
RelNode

public record PivotNode(String valueColumn, String keyColumn, List<String> groupKeys, RelNode input, SourceLocation location) extends Record implements RelNode
Row-pivoting operator (PIVOT) — spreads distinct values of a key column into new columns.

The PIVOT operator groups rows by the optional groupKeys() (or treats the whole relation as one group when groupKeys() is empty), finds the distinct values of keyColumn(), and emits one output row per group. Each distinct key value becomes a new column whose cell value is taken from valueColumn().

Because the output schema depends on the runtime data (the distinct key values are not known at parse time), PIVOT always produces an open, schema-on-read Schema.open() as its output schema. Column names in the output are the string representations of the distinct key values.

Surface syntax:

   PIVOT revenue BY month PER region (MonthlySales)
   PIVOT amount BY category (Transactions)
 

PIVOT is a blocking operator (MaterializationMode.BAG) — it must consume the entire input before it can emit any output, since it needs to discover the full set of distinct key values first. It is never pushed down to a source.

  • Constructor Details

  • Method Details

    • accept

      public <R> R accept(RelNodeVisitor<R> visitor)
      Specified by:
      accept in interface RelNode
    • 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.
    • valueColumn

      public String valueColumn()
      Returns the value of the valueColumn record component.
      Returns:
      the value of the valueColumn record component
    • keyColumn

      public String keyColumn()
      Returns the value of the keyColumn record component.
      Returns:
      the value of the keyColumn record component
    • groupKeys

      public List<String> groupKeys()
      Returns the value of the groupKeys record component.
      Returns:
      the value of the groupKeys record component
    • input

      public RelNode input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • location

      public SourceLocation location()
      Returns the value of the location record component.
      Specified by:
      location in interface RelNode
      Returns:
      the value of the location record component