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;RexSimplifyconverts complex comparisons on the same argument into SEARCH calls with an included Sarg;- Various
RelBuildermethods, 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)callRexBuildermethodsRexBuilder.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; SqlImplementorconvertsRexCalls to SEARCH intoSqlNodeAST expressions such as comparisons,BETWEENandIN.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal RexUnknownAsfinal intfinal com.google.common.collect.RangeSet<C> -
Method Summary
Modifier and TypeMethodDescriptionintintReturns a measure of the complexity of this expression.booleaninthashCode()booleanisAll()Returns whether this Sarg includes all values (including or not including null).booleanReturns whether this Sarg, when negated, is a collection of 1 or more points (and perhaps anIS NULLifnullAs == RexUnknownAs.TRUE).booleanisNone()Returns whether this Sarg includes no values (including or not including null).booleanisPoints()Returns whether this Sarg is a collection of 1 or more points (and perhaps anIS NULLifnullAs == 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:
compareToin 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 NULLifnullAs == RexUnknownAs.TRUE).Such sargs could be translated as
ref = valueorref IN (value1, ...). -
isComplementedPoints
public boolean isComplementedPoints()Returns whether this Sarg, when negated, is a collection of 1 or more points (and perhaps anIS NULLifnullAs == RexUnknownAs.TRUE).Such sargs could be translated as
ref <> valueorref 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 > 1have complexity 1x > 1 or x is nullhas complexity 2x in (2, 4, 6) or x > 20has complexity 4x between 3 and 8 or x between 10 and 20has complexity 2
-
negate
Returns a Sarg that matches a value if and only this Sarg does not.
-