Class SearchOperatorConversion

java.lang.Object
org.apache.druid.sql.calcite.expression.builtin.SearchOperatorConversion
All Implemented Interfaces:
SqlOperatorConversion

public class SearchOperatorConversion extends Object implements SqlOperatorConversion
Operator that tests whether its left operand is included in the range of values covered by search arguments. This is the Druid version support for https://issues.apache.org/jira/browse/CALCITE-4173 SEARCH operator tests whether an operand belongs to the range set. A RexCall to SEARCH is converted back to SQL, typically an IN or OR.
  • Constructor Details

    • SearchOperatorConversion

      public SearchOperatorConversion()
  • Method Details

    • calciteOperator

      public org.apache.calcite.sql.SqlOperator calciteOperator()
      Description copied from interface: SqlOperatorConversion
      Returns the SQL operator corresponding to this function. Should be a singleton.
      Specified by:
      calciteOperator in interface SqlOperatorConversion
      Returns:
      operator
    • toDruidFilter

      @Nullable public DimFilter toDruidFilter(PlannerContext plannerContext, RowSignature rowSignature, @Nullable VirtualColumnRegistry virtualColumnRegistry, org.apache.calcite.rex.RexNode rexNode)
      Description copied from interface: SqlOperatorConversion
      Returns a Druid filter corresponding to a Calcite RexNode used as a filter condition.
      Specified by:
      toDruidFilter in interface SqlOperatorConversion
      Parameters:
      plannerContext - SQL planner context
      rowSignature - input row signature
      virtualColumnRegistry - re-usable virtual column references
      rexNode - filter expression rex node
      Returns:
      filter, or null if the call cannot be translated to a filter
    • toDruidExpression

      @Nullable public DruidExpression toDruidExpression(PlannerContext plannerContext, RowSignature rowSignature, org.apache.calcite.rex.RexNode rexNode)
      Description copied from interface: SqlOperatorConversion
      Translate a Calcite RexNode to a Druid expression.
      Specified by:
      toDruidExpression in interface SqlOperatorConversion
      Parameters:
      plannerContext - SQL planner context
      rowSignature - signature of the rows to be extracted from
      rexNode - expression meant to be applied on top of the rows
      Returns:
      Druid expression, or null if translation is not possible
      See Also:
    • expandSearch

      public static org.apache.calcite.rex.RexNode expandSearch(org.apache.calcite.rex.RexCall call, org.apache.calcite.rex.RexBuilder rexBuilder, int scalarInArrayThreshold)
      Like RexUtil.expandSearch(RexBuilder, RexProgram, RexNode), but with some enhancements: 1) Expands NOT IN (a.k.a. Sarg.isComplementedPoints() as !(a || b || c) rather than (!a && !b && !c), which helps us convert it to an InDimFilter later. 2) Can generate nice conversions for complement-points even if the range is not *entirely* complement-points.
    • makeIn

      @Nullable public static org.apache.calcite.rex.RexNode makeIn(org.apache.calcite.rex.RexNode arg, Collection<? extends Comparable> pointObjects, org.apache.calcite.rel.type.RelDataType pointType, boolean negate, boolean useScalarInArray, org.apache.calcite.rex.RexBuilder rexBuilder)
      Make an IN condition for an "arg" matching certain "points", as in "arg IN (points)".
      Parameters:
      arg - lhs of the IN
      pointObjects - rhs of the IN. Must match the "pointType"
      pointType - type of "pointObjects"
      negate - true for NOT IN, false for IN
      useScalarInArray - if true, use ScalarInArrayOperatorConversion.SQL_FUNCTION when there is more than one point; if false, use a stack of ORs
      rexBuilder - rex builder
      Returns:
      SQL rex nodes equivalent to the IN filter, or null if "pointObjects" is empty