C - Value typepublic class Sarg<C extends Comparable<C>> extends Object implements Comparable<Sarg<C>>
The name is derived from Search argument, an ancient concept in database implementation; see Access Path Selection in a Relational Database Management System — Selinger et al. 1979 or the "morning paper summary.
In RexNode, a Sarg only occur as the right-hand operand in a call to
SqlStdOperatorTable.SEARCH, wrapped in a
RexLiteral. Lifecycle methods:
RexUtil.expandSearch(org.apache.calcite.rex.RexBuilder, org.apache.calcite.rex.RexProgram, org.apache.calcite.rex.RexNode) removes
calls to SEARCH and the included Sarg, converting them to comparisons;
RexSimplify converts complex comparisons
on the same argument into SEARCH calls with an included Sarg;
RelBuilder methods,
including RelBuilder.in(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode...)
and RelBuilder.between(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode)
call RexBuilder
methods RexBuilder.makeIn(org.apache.calcite.rex.RexNode, java.util.List<? extends org.apache.calcite.rex.RexNode>)
and RexBuilder.makeBetween(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode)
that create Sarg instances directly;
SqlImplementor converts
RexCalls
to SEARCH into SqlNode AST expressions
such as comparisons, BETWEEN and IN.
SqlStdOperatorTable.SEARCH| Modifier and Type | Field and Description |
|---|---|
RexUnknownAs |
nullAs |
int |
pointCount |
com.google.common.collect.RangeSet<C> |
rangeSet |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Sarg<C> o) |
int |
complexity()
Returns a measure of the complexity of this expression.
|
boolean |
equals(@Nullable Object o) |
int |
hashCode() |
boolean |
isAll()
Returns whether this Sarg includes all values (including or not including
null).
|
boolean |
isComplementedPoints()
Returns whether this Sarg, when negated, is a collection of 1 or more
points (and perhaps an
IS NULL if
nullAs == RexUnknownAs.TRUE). |
boolean |
isNone()
Returns whether this Sarg includes no values (including or not including
null).
|
boolean |
isPoints()
Returns whether this Sarg is a collection of 1 or more
points (and perhaps an
IS NULL if
nullAs == RexUnknownAs.TRUE). |
Sarg |
negate()
Returns a Sarg that matches a value if and only this Sarg does not.
|
static <C extends Comparable<C>> |
of(boolean containsNull,
com.google.common.collect.RangeSet<C> rangeSet)
Deprecated.
|
static <C extends Comparable<C>> |
of(RexUnknownAs nullAs,
com.google.common.collect.RangeSet<C> rangeSet)
Creates a search argument.
|
StringBuilder |
printTo(StringBuilder sb,
BiConsumer<StringBuilder,C> valuePrinter)
Prints this Sarg to a StringBuilder, using the given printer to deal
with each embedded value.
|
String |
toString() |
public final com.google.common.collect.RangeSet<C extends Comparable<C>> rangeSet
public final RexUnknownAs nullAs
public final int pointCount
@Deprecated public static <C extends Comparable<C>> Sarg<C> of(boolean containsNull, com.google.common.collect.RangeSet<C> rangeSet)
public static <C extends Comparable<C>> Sarg<C> of(RexUnknownAs nullAs, com.google.common.collect.RangeSet<C> rangeSet)
public String toString()
Produces a similar result to RangeSet,
but adds "; NULL AS FALSE" or "; NULL AS TRUE" to indicate nullAs,
and simplifies point ranges.
For example, the Sarg that allows the range set
[[7..7], [9..9], (10..+∞)]
and also null is printed as
Sarg[7, 9, (10..+∞); NULL AS TRUE]public StringBuilder printTo(StringBuilder sb, BiConsumer<StringBuilder,C> valuePrinter)
public int compareTo(Sarg<C> o)
compareTo in interface Comparable<Sarg<C extends Comparable<C>>>public boolean isAll()
public boolean isNone()
public boolean isPoints()
IS NULL if
nullAs == RexUnknownAs.TRUE).
Such sargs could be translated as ref = value
or ref IN (value1, ...).
public boolean isComplementedPoints()
IS NULL if
nullAs == RexUnknownAs.TRUE).
Such sargs could be translated as ref <> value
or ref NOT IN (value1, ...).
public int complexity()
It is basically the number of values that need to be checked against (including NULL).
Examples:
x = 1, x <> 1, x > 1 have complexity 1
x > 1 or x is null has complexity 2
x in (2, 4, 6) or x > 20 has complexity 4
x between 3 and 8 or x between 10 and 20 has complexity 2
public Sarg negate()
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.