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
FieldsModifier and TypeFieldDescriptionstatic final StringContext parameter for tests, to allow us to confirm that this rule doesn't do too many calls toInDimFilter.optimize(boolean).static final StringContext parameter to prevent creating too-large IN filters as a result of reverse lookups.static final intContext 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 -
Method Summary
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, unorderedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.calcite.rel.rules.SubstitutionRule
autoPruneOld
-
Field Details
-
CTX_MAX_OPTIMIZE_COUNT
Context parameter for tests, to allow us to confirm that this rule doesn't do too many calls toInDimFilter.optimize(boolean). This is important because certain lookup implementations, most prominentlyMapLookupExtractor, do a full iteration of the map for each call toLookupExtractor.unapplyAll(java.util.Set<java.lang.String>), which may be called byInDimFilter.optimize(boolean).- See Also:
-
CTX_THRESHOLD
Context parameter to prevent creating too-large IN filters as a result of reverse lookups.- See Also:
-
DEFAULT_THRESHOLD
public static final int DEFAULT_THRESHOLDContext parameter for tests, to allow us to force the case where we avoid creating a bunch of ORs.- See Also:
-
-
Constructor Details
-
ReverseLookupRule
-
-
Method Details
-
onMatch
public void onMatch(org.apache.calcite.plan.RelOptRuleCall call) - Specified by:
onMatchin classorg.apache.calcite.plan.RelOptRule
-