Record Class TreeNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.TreeNode
Record Components:
input - the source adjacency relation; must not be null
keyColumn - the node-identity column; must not be blank
parentColumn - the parent-key column; must not be blank
orderSpecs - the optional sibling ordering; empty = input order; must not be null
childrenColumn - the name of the appended nested array column; must not be blank
location - the source location of this node; never null
All Implemented Interfaces:
RelNode

public record TreeNode(RelNode input, String keyColumn, String parentColumn, List<SortSpecification> orderSpecs, String childrenColumn, SourceLocation location) extends Record implements RelNode
Adjacency-to-forest nesting operator — folds a self-referential adjacency relation into a forest of nested documents, one output row per root, each carrying its whole subtree as a nested ANY document.

TREE is the recursive generalisation of COLLECT (NEST): where COLLECT gathers a single level of children into an array, TREE follows the keyColumn() → parentColumn() edge to fixpoint, assembling an unbounded-depth tree in one pass. Its marquee use is dogfooding the engine's own IR — TREE(relix.plan) renders the logical tree as a nested document — but it is general (org charts, bill-of-materials, threaded comments, file trees).

Surface syntax:

   TREE node_id BY parent_id ORDER ordinal AS children (relix.plan)
   TREE id BY manager_id AS reports (Employees)
 
  • keyColumn() — the node-identity column (e.g. node_id).
  • parentColumn() — the column pointing at the parent's key; a row whose parent-key is NULL, or references a key absent from the input, is a root (forest semantics).
  • orderSpecs() — optional sibling ordering; empty = input order.
  • childrenColumn() — the name of the added nested array column.

Output: one row per root. Each row is the root's own input columns ⊕ childrenColumn: ANY, where the children column is an array of documents of the same recursive shape. Leaves carry an empty children array. The recursive document is typed ANY (schema-on-read; there is no recursive static type).

Well-formedness: a cycle in the key→parent-key graph and a duplicate keyColumn() are user errors raised at evaluation time (the recursion engine's bounded-fixpoint cap is the cycle safety valve).

Evaluation must see the whole relation to build the forest, so TREE is a blocking operator (MaterializationMode.BAG); it never pushes down to a source and is subject to the boundedness check over unbounded inputs.

  • 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.
    • input

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

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

      public String parentColumn()
      Returns the value of the parentColumn record component.
      Returns:
      the value of the parentColumn record component
    • orderSpecs

      public List<SortSpecification> orderSpecs()
      Returns the value of the orderSpecs record component.
      Returns:
      the value of the orderSpecs record component
    • childrenColumn

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