Class ReverseLookupRule

java.lang.Object
org.apache.calcite.plan.RelOptRule
org.apache.druid.sql.calcite.rule.ReverseLookupRule
All Implemented Interfaces:
org.apache.calcite.rel.rules.SubstitutionRule, org.apache.calcite.rel.rules.TransformationRule

public class ReverseLookupRule extends org.apache.calcite.plan.RelOptRule implements org.apache.calcite.rel.rules.SubstitutionRule
Eliminates calls to QueryLookupOperatorConversion.SQL_FUNCTION by doing reverse-lookups. Considers reversing SqlStdOperatorTable.IS_NULL and operators that match isBinaryComparison(RexNode). However, reversal is not done in all cases, such as when it would require embedding the entire lookup into the query, or when the number of keys exceeds QueryContext.getInSubQueryThreshold(). The heart of the class, where the reversal actually happens, is ReverseLookupRule.ReverseLookupShuttle.CollectReverseLookups.reverseLookup(org.apache.druid.query.lookup.LookupExtractor, java.lang.String, org.apache.druid.query.filter.InDimFilter.ValuesSet, boolean). The rest of the rule is mainly about grouping together as many LOOKUP calls as possible prior to attempting to reverse, since reversing a lookup may require iteration of the lookup. We don't want to do that more often than necessary.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule

    org.apache.calcite.plan.RelOptRule.ConverterRelOptRuleOperand
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Context parameter for tests, to allow us to confirm that this rule doesn't do too many calls to InDimFilter.optimize(boolean).
    static final String
    Context parameter to prevent creating too-large IN filters as a result of reverse lookups.
    static final int
    Context parameter for tests, to allow us to force the case where we avoid creating a bunch of ORs.

    Fields inherited from class org.apache.calcite.plan.RelOptRule

    description, operands, relBuilderFactory
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onMatch(org.apache.calcite.plan.RelOptRuleCall call)
     

    Methods inherited from class org.apache.calcite.plan.RelOptRule

    any, convert, convert, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.calcite.rel.rules.SubstitutionRule

    autoPruneOld
  • Field Details

  • Constructor Details

    • ReverseLookupRule

      public ReverseLookupRule(PlannerContext plannerContext)
  • Method Details

    • onMatch

      public void onMatch(org.apache.calcite.plan.RelOptRuleCall call)
      Specified by:
      onMatch in class org.apache.calcite.plan.RelOptRule