Class RewriteIntersectAllRule
java.lang.Object
org.apache.calcite.plan.RelOptRule
org.apache.calcite.plan.RelRule<RewriteIntersectAllRule.RewriteIntersectAllRuleConfig>
org.apache.flink.table.planner.plan.rules.logical.RewriteIntersectAllRule
@Enclosing
public class RewriteIntersectAllRule
extends org.apache.calcite.plan.RelRule<RewriteIntersectAllRule.RewriteIntersectAllRuleConfig>
Replaces logical
Intersect operator using a combination of union all, aggregate and table
function.
Original Query : SELECT c1 FROM ut1 INTERSECT ALL SELECT c1 FROM ut2
Rewritten Query:
SELECT c1
FROM (
SELECT c1, If (vcol_left_cnt > vcol_right_cnt, vcol_right_cnt, vcol_left_cnt) AS min_count
FROM (
SELECT
c1,
count(vcol_left_marker) as vcol_left_cnt,
count(vcol_right_marker) as vcol_right_cnt
FROM (
SELECT c1, true as vcol_left_marker, null as vcol_right_marker FROM ut1
UNION ALL
SELECT c1, null as vcol_left_marker, true as vcol_right_marker FROM ut2
) AS union_all
GROUP BY c1
)
WHERE vcol_left_cnt >= 1 AND vcol_right_cnt >= 1
)
)
LATERAL TABLE(replicate_row(min_count, c1)) AS T(c1)
Only handle the case of input size 2.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRule configuration.Nested classes/interfaces inherited from class org.apache.calcite.plan.RelRule
org.apache.calcite.plan.RelRule.Config, org.apache.calcite.plan.RelRule.Done, org.apache.calcite.plan.RelRule.MatchHandler<R extends org.apache.calcite.plan.RelOptRule>, org.apache.calcite.plan.RelRule.OperandBuilder, org.apache.calcite.plan.RelRule.OperandDetailBuilder<R extends org.apache.calcite.rel.RelNode>, org.apache.calcite.plan.RelRule.OperandTransformNested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule
org.apache.calcite.plan.RelOptRule.ConverterRelOptRuleOperand -
Field Summary
FieldsFields inherited from class org.apache.calcite.plan.RelRule
configFields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, none, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
RewriteIntersectAllRule
-
-
Method Details
-
matches
public boolean matches(org.apache.calcite.plan.RelOptRuleCall call) - Overrides:
matchesin classorg.apache.calcite.plan.RelOptRule
-
onMatch
public void onMatch(org.apache.calcite.plan.RelOptRuleCall call) - Specified by:
onMatchin classorg.apache.calcite.plan.RelOptRule
-