Class Sarg<C extends Comparable<C>>

java.lang.Object
org.apache.calcite.util.Sarg<C>
Type Parameters:
C - Value type
All Implemented Interfaces:
Comparable<Sarg<C>>

public class Sarg<C extends Comparable<C>> extends Object implements Comparable<Sarg<C>>
Set of values (or ranges) that are the target of a search.

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:

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    final int
     
    final com.google.common.collect.RangeSet<C>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    Returns a measure of the complexity of this expression.
    boolean
    equals(@Nullable Object o)
     
    int
     
    boolean
    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 an IS NULL if nullAs == RexUnknownAs.TRUE).
    boolean
    Returns whether this Sarg includes no values (including or not including null).
    boolean
    Returns whether this Sarg is a collection of 1 or more points (and perhaps an IS NULL if nullAs == RexUnknownAs.TRUE).
    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.
    Prints this Sarg to a StringBuilder, using the given printer to deal with each embedded value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • rangeSet

      public final com.google.common.collect.RangeSet<C extends Comparable<C>> rangeSet
    • nullAs

      public final RexUnknownAs 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

      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]
      Overrides:
      toString in class Object
    • printTo

      public StringBuilder printTo(StringBuilder sb, BiConsumer<StringBuilder,C> valuePrinter)
      Prints this Sarg to a StringBuilder, using the given printer to deal with each embedded value.
    • compareTo

      public int compareTo(Sarg<C> o)
      Specified by:
      compareTo in interface Comparable<C extends Comparable<C>>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • 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 an IS NULL if nullAs == RexUnknownAs.TRUE).

      Such sargs could be translated as ref = value or ref IN (value1, ...).

    • isComplementedPoints

      public 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).

      Such sargs could be translated as ref <> value or ref 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 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
    • negate

      public Sarg negate()
      Returns a Sarg that matches a value if and only this Sarg does not.