Class Sarg<C extends Comparable<C>>
- Type Parameters:
C
- Value type
- All Implemented Interfaces:
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;- Various
RelBuilder
methods, includingRelBuilder.in(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode...)
andRelBuilder.between(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode)
callRexBuilder
methodsRexBuilder.makeIn(org.apache.calcite.rex.RexNode, java.util.List<? extends org.apache.calcite.rex.RexNode>)
andRexBuilder.makeBetween(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode)
that create Sarg instances directly; SqlImplementor
convertsRexCall
s to SEARCH intoSqlNode
AST expressions such as comparisons,BETWEEN
andIN
.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal RexUnknownAs
final int
final com.google.common.collect.RangeSet<C>
-
Method Summary
Modifier and TypeMethodDescriptionint
int
Returns a measure of the complexity of this expression.boolean
int
hashCode()
boolean
isAll()
Returns whether this Sarg includes all values (including or not including null).boolean
Returns whether this Sarg, when negated, is a collection of 1 or more points (and perhaps anIS NULL
ifnullAs == 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 anIS NULL
ifnullAs == RexUnknownAs.TRUE
).negate()
Returns a Sarg that matches a value if and only this Sarg does not.static <C extends Comparable<C>>
Sarg<C>of
(boolean containsNull, com.google.common.collect.RangeSet<C> rangeSet) Deprecated.static <C extends Comparable<C>>
Sarg<C>of
(RexUnknownAs nullAs, com.google.common.collect.RangeSet<C> rangeSet) Creates a search argument.printTo
(StringBuilder sb, BiConsumer<StringBuilder, C> valuePrinter) Prints this Sarg to a StringBuilder, using the given printer to deal with each embedded value.toString()
-
Field Details
-
rangeSet
-
nullAs
-
pointCount
public final int pointCount
-
-
Method Details
-
of
@Deprecated public static <C extends Comparable<C>> Sarg<C> of(boolean containsNull, com.google.common.collect.RangeSet<C> rangeSet) Deprecated. -
of
public static <C extends Comparable<C>> Sarg<C> of(RexUnknownAs nullAs, com.google.common.collect.RangeSet<C> rangeSet) Creates a search argument. -
toString
Produces a similar result to
RangeSet
, but adds "; NULL AS FALSE" or "; NULL AS TRUE" to indicatenullAs
, 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]
-
printTo
Prints this Sarg to a StringBuilder, using the given printer to deal with each embedded value. -
compareTo
- Specified by:
compareTo
in interfaceComparable<C extends Comparable<C>>
-
hashCode
public int hashCode() -
equals
-
isAll
public boolean isAll()Returns whether this Sarg includes all values (including or not including null). -
isNone
public boolean isNone()Returns whether this Sarg includes no values (including or not including null). -
isPoints
public boolean isPoints()Returns whether this Sarg is a collection of 1 or more points (and perhaps anIS NULL
ifnullAs == RexUnknownAs.TRUE
).Such sargs could be translated as
ref = value
orref IN (value1, ...)
. -
isComplementedPoints
public boolean isComplementedPoints()Returns whether this Sarg, when negated, is a collection of 1 or more points (and perhaps anIS NULL
ifnullAs == RexUnknownAs.TRUE
).Such sargs could be translated as
ref <> value
orref NOT IN (value1, ...)
. -
complexity
public int complexity()Returns a measure of the complexity of this expression.It is basically the number of values that need to be checked against (including NULL).
Examples:
x = 1
,x <> 1
,x > 1
have complexity 1x > 1 or x is null
has complexity 2x in (2, 4, 6) or x > 20
has complexity 4x between 3 and 8 or x between 10 and 20
has complexity 2
-
negate
Returns a Sarg that matches a value if and only this Sarg does not.
-