Package org.apache.calcite.rel.rules
Class SubQueryRemoveRule
- java.lang.Object
-
- org.apache.calcite.plan.RelOptRule
-
- org.apache.calcite.rel.rules.SubQueryRemoveRule
-
- Direct Known Subclasses:
SubQueryRemoveRule.SubQueryFilterRemoveRule
,SubQueryRemoveRule.SubQueryJoinRemoveRule
,SubQueryRemoveRule.SubQueryProjectRemoveRule
public abstract class SubQueryRemoveRule extends RelOptRule
Transform that converts IN, EXISTS and scalar sub-queries into joins.Sub-queries are represented by
RexSubQuery
expressions.A sub-query may or may not be correlated. If a sub-query is correlated, the wrapped
RelNode
will contain aRexCorrelVariable
before the rewrite, and the product of the rewrite will be aCorrelate
. The Correlate can be removed usingRelDecorrelator
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SubQueryRemoveRule.ReplaceSubQueryShuttle
Shuttle that replaces occurrences of a givenRexSubQuery
with a replacement expression.static class
SubQueryRemoveRule.SubQueryFilterRemoveRule
Rule that converts a sub-queries from filter expressions intoCorrelate
instances.static class
SubQueryRemoveRule.SubQueryJoinRemoveRule
Rule that converts sub-queries from join expressions intoCorrelate
instances.static class
SubQueryRemoveRule.SubQueryProjectRemoveRule
Rule that converts sub-queries from project expressions intoCorrelate
instances.
-
Field Summary
Fields Modifier and Type Field Description static SubQueryRemoveRule
FILTER
static SubQueryRemoveRule
JOIN
static SubQueryRemoveRule
PROJECT
-
Fields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory
-
-
Constructor Summary
Constructors Constructor Description SubQueryRemoveRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, java.lang.String description)
Creates a SubQueryRemoveRule.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RexNode
apply(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder, int inputCount, int offset)
private RexInputRef
field(RelBuilder builder, int inputCount, int offset)
Returns a reference to a particular field, by offset, across several inputs on aRelBuilder
's stack.private static java.util.List<RexNode>
fields(RelBuilder builder, int fieldCount)
Returns a list of expressions that project the firstfieldCount
fields of the top input on aRelBuilder
's stack.private RexNode
rewriteExists(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder)
Rewrites an EXISTS RexSubQuery into aJoin
.private RexNode
rewriteIn(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder, int offset)
Rewrites an IN RexSubQuery into aJoin
.private RexNode
rewriteScalarQuery(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelBuilder builder, int inputCount, int offset)
Rewrites a scalar sub-query into anAggregate
.private RexNode
rewriteSome(RexSubQuery e, RelBuilder builder)
Rewrites a SOME sub-query into aJoin
.-
Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
-
-
-
-
Field Detail
-
PROJECT
public static final SubQueryRemoveRule PROJECT
-
FILTER
public static final SubQueryRemoveRule FILTER
-
JOIN
public static final SubQueryRemoveRule JOIN
-
-
Constructor Detail
-
SubQueryRemoveRule
public SubQueryRemoveRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, java.lang.String description)
Creates a SubQueryRemoveRule.- Parameters:
operand
- root operand, must not be nulldescription
- Description, or null to guess descriptionrelBuilderFactory
- Builder for relational expressions
-
-
Method Detail
-
apply
protected RexNode apply(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder, int inputCount, int offset)
-
rewriteScalarQuery
private RexNode rewriteScalarQuery(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelBuilder builder, int inputCount, int offset)
Rewrites a scalar sub-query into anAggregate
.- Parameters:
e
- IN sub-query to rewritevariablesSet
- A set of variables used by a relational expression of the specified RexSubQuerybuilder
- Builderoffset
- Offset to shiftRexInputRef
- Returns:
- Expression that may be used to replace the RexSubQuery
-
rewriteSome
private RexNode rewriteSome(RexSubQuery e, RelBuilder builder)
Rewrites a SOME sub-query into aJoin
.- Parameters:
e
- SOME sub-query to rewritebuilder
- Builder- Returns:
- Expression that may be used to replace the RexSubQuery
-
rewriteExists
private RexNode rewriteExists(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder)
Rewrites an EXISTS RexSubQuery into aJoin
.- Parameters:
e
- EXISTS sub-query to rewritevariablesSet
- A set of variables used by a relational expression of the specified RexSubQuerylogic
- Logic for evaluatingbuilder
- Builder- Returns:
- Expression that may be used to replace the RexSubQuery
-
rewriteIn
private RexNode rewriteIn(RexSubQuery e, java.util.Set<CorrelationId> variablesSet, RelOptUtil.Logic logic, RelBuilder builder, int offset)
Rewrites an IN RexSubQuery into aJoin
.- Parameters:
e
- IN sub-query to rewritevariablesSet
- A set of variables used by a relational expression of the specified RexSubQuerylogic
- Logic for evaluatingbuilder
- Builderoffset
- Offset to shiftRexInputRef
- Returns:
- Expression that may be used to replace the RexSubQuery
-
field
private RexInputRef field(RelBuilder builder, int inputCount, int offset)
Returns a reference to a particular field, by offset, across several inputs on aRelBuilder
's stack.
-
fields
private static java.util.List<RexNode> fields(RelBuilder builder, int fieldCount)
Returns a list of expressions that project the firstfieldCount
fields of the top input on aRelBuilder
's stack.
-
-