Record Class UnnestNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.UnnestNode
Record Components:
column - the name of the array column to unnest; must not be blank
outer - whether to preserve input rows whose array is empty/missing
ordinalityColumn - the name of the appended 1-based index column, or empty for no ordinality; never null
input - the source relation; must not be null
location - the source location of this node; never null
All Implemented Interfaces:
RelNode

public record UnnestNode(String column, boolean outer, Optional<String> ordinalityColumn, RelNode input, SourceLocation location) extends Record implements RelNode
Unnest (μ) — explodes an array-valued column into one row per element, carrying the other columns through (≈ SQL LATERAL UNNEST, Mongo $unwind). This is the bridge that makes nested data relationally queryable.

For each input row, the value of column() is treated as an array; the operator emits one output row per element with column bound to that element (and the remaining columns unchanged). The outer() flag selects the behaviour when the value is an empty array, NULL, missing, or not an array:

  • inner (outer == false) — emit no rows (drop the input row);
  • outer (outer == true) — emit a single row with column bound to NULL.

When ordinalityColumn() is present (the SQL WITH ORDINALITY variant — μ items WITH ORDINALITY pos), an extra NUMBER column of that name is appended carrying each element's 1-based position in its array. In the outer no-element case the ordinality is NULL alongside the NULL element.

Example: μ items (Orders) — one row per element of items; μ items WITH ORDINALITY pos (Orders) — likewise, plus a pos column numbering the elements from 1.

  • Constructor Details

    • UnnestNode

      public UnnestNode(String column, boolean outer, Optional<String> ordinalityColumn, RelNode input, SourceLocation location)
      Creates an instance of a UnnestNode record class.
      Parameters:
      column - the value for the column record component
      outer - the value for the outer record component
      ordinalityColumn - the value for the ordinalityColumn record component
      input - the value for the input record component
      location - the value for the location record component
    • UnnestNode

      public UnnestNode(String column, RelNode input)
      Convenience constructor for tests: inner unnest, no ordinality, SourceLocation.UNKNOWN.
    • UnnestNode

      public UnnestNode(String column, boolean outer, RelNode input)
      Convenience constructor for tests: no ordinality, SourceLocation.UNKNOWN.
  • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • column

      public String column()
      Returns the value of the column record component.
      Returns:
      the value of the column record component
    • outer

      public boolean outer()
      Returns the value of the outer record component.
      Returns:
      the value of the outer record component
    • ordinalityColumn

      public Optional<String> ordinalityColumn()
      Returns the value of the ordinalityColumn record component.
      Returns:
      the value of the ordinalityColumn 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