AstBuilders — comparisons by name, n-ary
connectives, and literals built from Java values rather than
from their source spelling.
AstBuilders follows one rule: a factory takes the record's own
components, in the record's own order. That rule is what keeps it honest, and it
is also what makes a hand-written expression verbose — a comparison names an
enum constant, and a number literal is a String because a
NumberOperand stores the digits as written. This class is the layer that
reads well at a call site, built entirely out of those same factories, so there
is one set of nodes and no second authority:
// AstBuilders — the record's own shape
cmp(attr("id"), ComparisonOperator.EQUAL, num("42"))
// Expr — the same node
eq(attr("id"), num(42))
This is how a value is bound to a query
The question every embedder asks first is how to put a value into a query safely. The answer is that a value never becomes text at all:
// Never necessary, and this is the shape that invents an injection surface
// where the language never had one:
// "σ id = " + orderId + " (Orders)"
// The value becomes a NumberOperand node, and nothing is parsed:
select(eq(attr("id"), num(orderId)), rel("Orders"))
That is why num(long), lit(Object) and the
java.time overloads exist: a caller holds a long, an
Instant or a BigDecimal, and formatting one into a string so a
builder can parse it back is exactly the round trip this surface removes.
Extends AstBuilders, so one extends Expr — or one static
import — reaches every factory as well as everything here.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PredicateThe conjunction of every given predicate, folded left so it nests the way a parseda ∧ b ∧ cdoes.static PredicateThe conjunction of every predicate inpredicates, folded left.static PredicateThe disjunction of every given predicate, folded left.static PredicateThe disjunction of every predicate inpredicates, folded left.static DateOperandA date literal from aLocalDate.static BinaryArithmeticExpressionleft / right.static DurationOperandA duration literal from aDuration.static ComparisonPredicateleft = right.static ComparisonPredicateleft ≥ right.static ComparisonPredicateleft > right.static ElementOfPredicateelement ∈ {values…}, with the set literal built for you.static NullPredicateoperand IS NOT NULL.static NullPredicateoperand IS NULL.static ComparisonPredicateleft ≤ right.static OperandThe literal operand for a Java value, chosen by its runtime type.static ComparisonPredicateleft < right.static BinaryArithmeticExpressionleft - right.static ComparisonPredicateleft ≠ right.static NumberOperandnum(double value) A numeric literal from a Java floating-point value.static NumberOperandnum(long value) A numeric literal from a Java integer value.static NumberOperandnum(BigDecimal value) A numeric literal from an exact decimal value.static BinaryArithmeticExpressionleft + right.static TimeOperandA time literal from aLocalTime.static BinaryArithmeticExpressionleft * right.static TimestampOperandA timestamp literal from anInstant.Methods inherited from class com.darkcollective.relix.ast.AstBuilders
agg, agg, aggOf, allocation, and, antiJoin, argAgg, argAgg, arith, arrayOf, asc, asOfJoin, asOfJoin, attr, attrs, bool, closure, closure, closure, closure, cluster, cmp, cols, composition, condition, constraint, cover, cover, date, desc, difference, distinct, division, downsample, downsample, downsample, downsample, duration, elementOf, emptyOf, emptyRel, field, fixpoint, fullJoin, func, groupBy, groupByKeys, intersection, intervalJoin, iterate, join, key, key, lateral, leftJoin, like, limit, limit, naturalJoin, not, notElementOf, notLike, nullPred, num, optimize, optimize, or, outerUnion, pairwiseUniversal, path, path, path, pivot, produceBound, product, project, projected, projected, recRef, rel, rel, rename, rename, renamePair, reservoirSample, reservoirSample, rightJoin, rounds, sample, sample, select, semiJoin, sessionize, sessionize, set, solve, sort, sortKey, str, structOf, symmetricDifference, time, timestamp, topK, topK, trace, trace, trace, tree, tree, tvf, unary, union, unionAll, unitRel, universal, unnest, unnest, unnest, unpivot, untilConverged, untilStable, why, window
-
Constructor Details
-
Expr
public Expr()
-
-
Method Details
-
num
A numeric literal from a Java integer value.- Parameters:
value- the value- Returns:
- the operand
-
num
A numeric literal from a Java floating-point value.Rendered through
BigDecimal.valueOf(double)with trailing zeros stripped, so the literal reads as the shortest decimal that round-trips rather than as the binary expansion — and5.0spells5, sinceDouble.toStringkeeps a trailing zero the value does not carry. Usenum(BigDecimal)where the scale is itself meaningful.- Parameters:
value- the value- Returns:
- the operand
-
num
A numeric literal from an exact decimal value.- Parameters:
value- the value; must not be null- Returns:
- the operand
-
date
A date literal from aLocalDate.- Parameters:
value- the date; must not be null- Returns:
- the operand
-
time
A time literal from aLocalTime.- Parameters:
value- the time; must not be null- Returns:
- the operand
-
timestamp
A timestamp literal from anInstant.- Parameters:
value- the instant; must not be null- Returns:
- the operand
-
duration
A duration literal from aDuration.- Parameters:
value- the duration; must not be null- Returns:
- the operand
-
lit
The literal operand for a Java value, chosen by its runtime type.For binding a value whose type is only known at runtime — a parameter map, a UI field, a row read from somewhere else. When the type is known, the specific factory says more at the call site.
nullbecomes aNullPredicate's business rather than an operand: there is no null literal in the operand hierarchy, so it is rejected here instead of silently becoming the string"null".- Parameters:
value- the Java value; must not be null- Returns:
- the matching literal operand
- Throws:
IllegalArgumentException- ifvalueis null or has no literal form
-
eq
left = right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
ne
left ≠ right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
lt
left < right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
le
left ≤ right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
gt
left > right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
ge
left ≥ right.- Parameters:
left- the left operandright- the right operand- Returns:
- the predicate
-
allOf
The conjunction of every given predicate, folded left so it nests the way a parseda ∧ b ∧ cdoes.AstBuilders.andis strictly binary becauseAndPredicateis; this is the n-ary spelling a caller assembling a filter list needs.- Parameters:
predicates- at least one predicate- Returns:
- the single predicate when one is given, else the left-folded conjunction
- Throws:
IllegalArgumentException- if no predicate is given
-
allOf
The conjunction of every predicate inpredicates, folded left.- Parameters:
predicates- at least one predicate- Returns:
- the single predicate when one is given, else the left-folded conjunction
- Throws:
IllegalArgumentException- if the list is empty
-
anyOf
The disjunction of every given predicate, folded left.- Parameters:
predicates- at least one predicate- Returns:
- the single predicate when one is given, else the left-folded disjunction
- Throws:
IllegalArgumentException- if no predicate is given
-
anyOf
The disjunction of every predicate inpredicates, folded left.- Parameters:
predicates- at least one predicate- Returns:
- the single predicate when one is given, else the left-folded disjunction
- Throws:
IllegalArgumentException- if the list is empty
-
isNull
operand IS NULL.- Parameters:
operand- the operand to test- Returns:
- the predicate
-
isNotNull
operand IS NOT NULL.- Parameters:
operand- the operand to test- Returns:
- the predicate
-
in
element ∈ {values…}, with the set literal built for you.- Parameters:
element- the operand tested for membershipvalues- the set members- Returns:
- the predicate
-
plus
left + right.- Parameters:
left- the left operandright- the right operand- Returns:
- the expression
-
minus
left - right.- Parameters:
left- the left operandright- the right operand- Returns:
- the expression
-
times
left * right.- Parameters:
left- the left operandright- the right operand- Returns:
- the expression
-
dividedBy
left / right.- Parameters:
left- the left operandright- the right operand- Returns:
- the expression
-