Package com.darkcollective.relix.ast
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:
-
ClassDescriptionRepresents 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 inIntervalJoinNode.Specifies the continuous LP (linear-programming) allocation mode for theOPTIMIZE ALLOCATEoperator.Logical conjunction (∧) — true when bothleftandrightare true.Represents an anti-join operation (▷).Binary arithmetic operators used inBinaryArithmeticExpression.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 (trueorfalse).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 inComparisonPredicate.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: aPredicateused in operand position.Consolidation functions for theDownsampleNodetime-series aggregation operator.Covering-reduction node —COVER [EXACT] t (R).A typed calendar-date literal operand, writtenDATE '2026-06-15'.Set difference (−) — returns tuples that appear inleftbut not inright.Distinct (δ) — eliminates duplicate tuples frominput.Relational division (÷) — returns tuples fromleftthat are associated with every tuple inright(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 chosenConsolidationFunction.A typed duration literal operand, writtenDURATION '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 ofAstBuilders— comparisons by name, n-ary connectives, and literals built from Java values rather than from their source spelling.General monotone recursion — the least-fixpoint binderFIX.Full outer join (⟗) — returns all tuples from bothleftandright; unmatched tuples on either side are padded with nulls.Represents a function call in an expression.A single grouping key of an aggregation (γ): theOperandexpression the rows are grouped by, with an optional alias for the output column.Set intersection (∩) — returns tuples that appear in bothleftandright.Interval join (IJOIN) — a temporal join over two interval-valued relations using an Allen's interval algebra relation.Replace-each-round iteration — the binderITERATE.When anIterateNodestops.UNTIL c, … WITHIN ε PER k, … MAX n ROUNDS— stop when, for every key, every named column changed by at mosttolerancesince the previous round, and no key appeared or disappeared.ROUNDS n— apply the step exactlyntimes;ROUNDS 0is 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 fromleft, paired with matching tuples fromright; 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 whenpredicateis false.Controls whereNULLvalues 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 anOptimizeNode: whether the objective is to be maximised or minimised.The offset window functions carried by aWindowFunction.OffsetWindow.Root sealed interface for scalar value expressions used in projections and predicates.A single linear constraint of anOptimizeNode: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 ofleftorrightis 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 patternoroperand 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'sSelectionIntoGeneratorPass(GEN-001).Cartesian product (×) — returns every combination of a tuple fromleftwith a tuple fromright.Represents a projected attribute in a projection operation.Projection (π) — selects a subset of attributes frominput, optionally computing new expressions or renaming columns.The ranking window functions carried by aWindowFunction.RankingWindow.An occurrence of aFIX-bound recursive relation name inside the body of its enclosingFixpointNode.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 singleold → newcolumn rename within the pair form.Reservoir (fixed-count) sampling (SAMPLE … ROWS) — keeps exactlycountrows ofinput, chosen uniformly at random without replacement.Right outer join (⟖) — returns all tuples fromright, paired with matching tuples fromleft; unmatched right tuples are padded with nulls.Bernoulli sampling (SAMPLE) — independently keeps each row ofinputwith probabilityprobability(a fraction in[0, 1]).Selection (σ) — filters the tuples ofinputto those satisfyingpredicate.Represents a semi-join operation (⋉).Gap-and-island / sessionization operator — groups an ordered stream into sessions separated by an idle gap, the famous SQLLAG/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 equationleft = right.Sort direction used in aSortSpecification.Represents a sort operation (τ) in relational algebra.A single sort key: theOperandexpression to order by, the direction (SortDirection.ASC/SortDirection.DESC), and the implicitNULLplacement.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 ofleftorright, but not in both, eliminating duplicates.Theta join (⨝) — inner join that keeps only tuples satisfyingcondition.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, writtenTIME '13:40:00'.A typed timestamp literal operand, writtenTIMESTAMP '2026-06-15T13:40:00Z'.Top-k per group (TOP) — partitionsinputbygroupingAttributesand, within each group, keeps thecounthighest rows bysortSpecs(after skippingoffsetrows).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 nestedANYdocument.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 bothleftandright, preserving duplicates (equivalent to SQLUNION ALL).Set union (∪) — returns tuples that appear inleft,right, or both, eliminating duplicates.Group-wise universal quantification (∀) — partitionsinputby thegroupingAttributesand keeps the grouping-key tuple of each group in which every row satisfiespredicate.Unnest (μ) — explodes an array-valued column into one row per element, carrying the other columns through (≈ SQLLATERAL UNNEST, Mongo$unwind).Column-folding operator (UNPIVOT) — transforms selected columns into rows.Why (ω) — reifies the lineage provenance ofinputas queryable data.The scope of rows fed to aWindowFunctionwithin a partition.A trailingn-row sliding window —OVER n ROWS— equivalent to SQL'sROWS BETWEEN n-1 PRECEDING AND CURRENT ROW.The cumulative (running) frame —OVER ALL ROWS— equivalent to SQL'sROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.The full-partition frame used implicitly by ranking and offset functions — equivalent to SQL'sROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.The computation aWindowNodeperforms per row.A sliding / cumulative aggregate over anOperandargument — the sameAggregateOperator+Operandpair 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.