Package com.darkcollective.relix.ast


package com.darkcollective.relix.ast
Immutable AST node types for relational algebra expressions.

Overview

The package models the full vocabulary of relational algebra using three sealed interface hierarchies:

  • RelNode — relational operations that consume or produce relations (tables). Implementations cover the classic unary operators (σ, π, ρ, δ), binary set and join operators (∪ ⊎ − ∩ ÷ ×, ⋈ ⨝ ⟕ ⟖ ⟗ ⋉ ▷), and extended operators (γ, τ, λ).
  • Predicate — boolean conditions used in selections and join conditions. Includes comparison, logical connectives (∧ ∨ ¬), null testing (⊥), and set membership (∈ ∉).
  • Operand — scalar value expressions appearing in projections and predicates. Covers attribute references, literals (string, number, boolean), arithmetic expressions, function calls, set literals, and unary negation.

Design

All node types are Java records — they are value-based, thread-safe, and structurally equal (two nodes with the same fields compare as equal). Lists inside records are defensively copied to unmodifiable views. Constructor validation throws NullPointerException for null required fields and IllegalArgumentException for semantically invalid values (e.g., blank names, empty projection attribute lists).

The RelNode.prettyPrint() default method produces a Unicode relational algebra string that can be round-tripped through the parser.

Visitor pattern

Every node type exposes an accept method typed to the corresponding visitor interface in com.darkcollective.relix.ast.visitor. Implement one of the three visitor interfaces to add new traversals without modifying the node classes.

See Also:
  • Class
    Description
    Represents an aggregate function in an aggregation operation.
    Aggregate function operators used in AggregateFunction.
    Represents an aggregation operation (γ) in relational algebra.
    Allen's interval algebra relations used in IntervalJoinNode.
    Specifies the continuous LP (linear-programming) allocation mode for the OPTIMIZE ALLOCATE operator.
    Logical conjunction (∧) — true when both left and right are true.
    Represents an anti-join operation (▷).
    Binary arithmetic operators used in BinaryArithmeticExpression.
    Constructs a nested array value in a projection — [ expr, expr, … ].
    AS-OF join (ASOF) — a temporal "pick the nearest right row by time" join.
    The AST authoring surface — one factory per node kind, for tests and embedders that build a tree directly rather than parsing one.
    A column reference operand, optionally relation-qualified.
    A binary arithmetic expression (left op right) used in projections and predicates.
    A boolean literal operand (true or false).
    Transitive closure (least fixpoint) of a binary relation — the recursive "reachability" operator.
    Connected-components labelling of an undirected graph — the entity-resolution / network-island operator.
    Binary comparison operators used in ComparisonPredicate.
    A binary comparison predicate (left op right).
    Relational composition (∘) — composes two relations on their shared columns, like function composition.
    The uniform shape shared by every condition-carrying binary join: (left, right, condition, location).
    A boolean-valued operand: a Predicate used in operand position.
    Consolidation functions for the DownsampleNode time-series aggregation operator.
    Covering-reduction node — COVER [EXACT] t (R).
    A typed calendar-date literal operand, written DATE '2026-06-15'.
    Set difference (−) — returns tuples that appear in left but not in right.
    Distinct (δ) — eliminates duplicate tuples from input.
    Relational division (÷) — returns tuples from left that are associated with every tuple in right (the relational analogue of "for all").
    Time-series downsampling (DOWNSAMPLE) — groups input rows into fixed-width time buckets and consolidates numeric columns within each bucket using the chosen ConsolidationFunction.
    A typed duration literal operand, written DURATION 'PT30M'.
    Represents element-of predicates: element ∈ set_expression or element ∉ set_expression Used for set membership testing (equivalent to SQL IN/NOT IN).
    The relation with no rows and the heading of another expression — the ∅ that a provably-unsatisfiable query collapses to.
    The readable spelling of AstBuilders — comparisons by name, n-ary connectives, and literals built from Java values rather than from their source spelling.
    General monotone recursion — the least-fixpoint binder FIX.
    Full outer join (⟗) — returns all tuples from both left and right; unmatched tuples on either side are padded with nulls.
    Represents a function call in an expression.
    A single grouping key of an aggregation (γ): the Operand expression the rows are grouped by, with an optional alias for the output column.
    Set intersection (∩) — returns tuples that appear in both left and right.
    Interval join (IJOIN) — a temporal join over two interval-valued relations using an Allen's interval algebra relation.
    Replace-each-round iteration — the binder ITERATE.
    When an IterateNode stops.
    UNTIL c, … WITHIN ε PER k, … MAX n ROUNDS — stop when, for every key, every named column changed by at most tolerance since the previous round, and no key appeared or disappeared.
    ROUNDS n — apply the step exactly n times; ROUNDS 0 is the base unchanged.
    UNTIL STABLE MAX n ROUNDS — stop at the first round whose output equals its input.
    A correlated / lateral table-valued function application that produces one sub-relation per row of its left input.
    Left outer join (⟕) — returns all tuples from left, paired with matching tuples from right; unmatched left tuples are padded with nulls.
    Represents a limit operation (λ) in relational algebra.
    Describes the output materialisation strategy of a relational algebra node.
    Natural join (⋈) — joins two relations on all attributes with the same name, projecting away the duplicate join columns.
    Logical negation (¬) — true when predicate is false.
    Controls where NULL values appear when a column is used as a sort key.
    Represents a null predicate (IS NULL or IS NOT NULL) in relational algebra.
    A numeric literal operand, stored as its original string representation.
    The optimisation direction of an OptimizeNode: whether the objective is to be maximised or minimised.
    The offset window functions carried by a WindowFunction.OffsetWindow.
    Root sealed interface for scalar value expressions used in projections and predicates.
    A single linear constraint of an OptimizeNode: SUM(expr) op bound.
    Declarative optimisation (OPTIMIZE) — the goal-seeking sibling of γ.
    A sort ordering — the sequence of (column, direction) keys by which a relation's rows are ordered.
    Logical disjunction (∨) — true when at least one of left or right is true.
    Outer-union (⊔) — a schema-reconciling merge of two relations that need not be union-compatible.
    Represents a pairwise universal semi-join (USEMI), the ∀ dual of semi-join (⋉).
    Bounded variable-length path reachability — the RA-native graph-traversal operator.
    Represents a pattern-matching predicate: operand LIKE pattern or operand NOT LIKE pattern.
    Row-pivoting operator (PIVOT) — spreads distinct values of a key column into new columns.
    Root sealed interface for boolean filter conditions.
    A production stop folded into a monotone generator leaf by the optimizer's SelectionIntoGeneratorPass (GEN-001).
    Cartesian product (×) — returns every combination of a tuple from left with a tuple from right.
    Represents a projected attribute in a projection operation.
    Projection (π) — selects a subset of attributes from input, optionally computing new expressions or renaming columns.
    The ranking window functions carried by a WindowFunction.RankingWindow.
    An occurrence of a FIX-bound recursive relation name inside the body of its enclosing FixpointNode.
    A reference to a table-valued (relation-returning) user-defined function, used wherever a relation is expected — a leaf node in the relational algebra tree.
    A base relation (table) reference — a leaf node in the relational algebra tree.
    Root sealed interface for all relational algebra operation nodes.
    Rename (ρ) — renames a relation and optionally reassigns its attribute names.
    A single old → new column rename within the pair form.
    Reservoir (fixed-count) sampling (SAMPLE … ROWS) — keeps exactly count rows of input, chosen uniformly at random without replacement.
    Right outer join (⟖) — returns all tuples from right, paired with matching tuples from left; unmatched right tuples are padded with nulls.
    Bernoulli sampling (SAMPLE) — independently keeps each row of input with probability probability (a fraction in [0, 1]).
    Selection (σ) — filters the tuples of input to those satisfying predicate.
    Represents a semi-join operation (⋉).
    Gap-and-island / sessionization operator — groups an ordered stream into sessions separated by an idle gap, the famous SQL LAG/running-sum incantation expressed as a single algebraic operator.
    Represents a set literal like {1, 2, 3} or {"active", "pending"} Used in element-of predicates for set membership testing.
    Goal-seek (SOLVE) — a per-row operator that fills a single unknown column by inverting a declared arithmetic equation left = right.
    Sort direction used in a SortSpecification.
    Represents a sort operation (τ) in relational algebra.
    A single sort key: the Operand expression to order by, the direction (SortDirection.ASC / SortDirection.DESC), and the implicit NULL placement.
    The source location of an AST node — file path, 1-based line, and 1-based column of the first character of the construct.
    A string literal operand.
    Constructs a nested struct value in a projection — { name: expr, … }.
    A single struct field: a name paired with its value expression.
    Symmetric difference (∆) — returns tuples that appear in exactly one of left or right, but not in both, eliminating duplicates.
    Theta join (⨝) — inner join that keeps only tuples satisfying condition.
    Tie-break rule for AS-OF join (ASOF) when multiple right rows share the nearest match value.
    A typed wall-clock time-of-day literal operand, written TIME '13:40:00'.
    A typed timestamp literal operand, written TIMESTAMP '2026-06-15T13:40:00Z'.
    Top-k per group (TOP) — partitions input by groupingAttributes and, within each group, keeps the count highest rows by sortSpecs (after skipping offset rows).
    Optimal-path extraction over a directed, weighted graph — the cheapest (or longest) path finder.
    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.
    A nullary truth relation literal — a leaf node denoting one of the two relations whose heading is the empty (closed, zero-column) schema.
    Represents a unary operation applied to an operand.
    Multiset union (⊎) — returns all tuples from both left and right, preserving duplicates (equivalent to SQL UNION ALL).
    Set union (∪) — returns tuples that appear in left, right, or both, eliminating duplicates.
    Group-wise universal quantification (∀) — partitions input by the groupingAttributes and keeps the grouping-key tuple of each group in which every row satisfies predicate.
    Unnest (μ) — explodes an array-valued column into one row per element, carrying the other columns through (≈ SQL LATERAL UNNEST, Mongo $unwind).
    Column-folding operator (UNPIVOT) — transforms selected columns into rows.
    Why (ω) — reifies the lineage provenance of input as queryable data.
    The scope of rows fed to a WindowFunction within a partition.
    A trailing n-row sliding window — OVER n ROWS — equivalent to SQL's ROWS BETWEEN n-1 PRECEDING AND CURRENT ROW.
    The cumulative (running) frame — OVER ALL ROWS — equivalent to SQL's ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
    The full-partition frame used implicitly by ranking and offset functions — equivalent to SQL's ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
    The computation a WindowNode performs per row.
    A sliding / cumulative aggregate over an Operand argument — the same AggregateOperator + Operand pair used by γ.
    An offset function (slice 4).
    A ranking function (slice 3).
    Window operator — a non-collapsing per-partition computation that adds one column to every input row without removing or merging any.