Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-20887][table-planner] Step2: fix incorrect calc merge via rele…
…ated rules
- Loading branch information
1 parent
1e1a037
commit 0f1b59c
Showing
14 changed files
with
255 additions
and
72 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...ain/java/org/apache/flink/table/planner/plan/rules/logical/FlinkProjectCalcMergeRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.table.planner.plan.rules.logical; | ||
|
||
import org.apache.flink.table.planner.plan.utils.InputRefVisitor; | ||
|
||
import org.apache.calcite.plan.RelOptRule; | ||
import org.apache.calcite.plan.RelOptRuleCall; | ||
import org.apache.calcite.rel.logical.LogicalCalc; | ||
import org.apache.calcite.rel.logical.LogicalProject; | ||
import org.apache.calcite.rel.rules.ProjectCalcMergeRule; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.calcite.rex.RexUtil; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Extends calcite's ProjectCalcMergeRule, modification: does not merge the filter references field | ||
* which generated by non-deterministic function. | ||
*/ | ||
public class FlinkProjectCalcMergeRule extends ProjectCalcMergeRule { | ||
|
||
public static final RelOptRule INSTANCE = new FlinkProjectCalcMergeRule(Config.DEFAULT); | ||
|
||
protected FlinkProjectCalcMergeRule(Config config) { | ||
super(config); | ||
} | ||
|
||
@Override | ||
public void onMatch(RelOptRuleCall call) { | ||
LogicalProject project = call.rel(0); | ||
LogicalCalc calc = call.rel(1); | ||
|
||
List<RexNode> expandProjects = | ||
calc.getProgram().getProjectList().stream() | ||
.map(p -> calc.getProgram().expandLocalRef(p)) | ||
.collect(Collectors.toList()); | ||
InputRefVisitor inputRefVisitor = new InputRefVisitor(); | ||
project.getProjects().forEach(p -> p.accept(inputRefVisitor)); | ||
boolean existNonDeterministicRef = | ||
Arrays.stream(inputRefVisitor.getFields()) | ||
.anyMatch(i -> !RexUtil.isDeterministic(expandProjects.get(i))); | ||
|
||
if (!existNonDeterministicRef) { | ||
super.onMatch(call); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkProjectMergeRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.table.planner.plan.rules.logical; | ||
|
||
import org.apache.flink.table.planner.plan.utils.FlinkRexUtil; | ||
|
||
import org.apache.calcite.plan.RelOptRule; | ||
import org.apache.calcite.plan.RelOptRuleCall; | ||
import org.apache.calcite.rel.core.Project; | ||
import org.apache.calcite.rel.rules.ProjectMergeRule; | ||
|
||
/** | ||
* Extends calcite's FilterCalcMergeRule for streaming scenario, modification: does not merge the | ||
* filter references field which generated by non-deterministic function. | ||
*/ | ||
public class FlinkProjectMergeRule extends ProjectMergeRule { | ||
|
||
public static final RelOptRule INSTANCE = new FlinkProjectMergeRule(Config.DEFAULT); | ||
|
||
protected FlinkProjectMergeRule(Config config) { | ||
super(config); | ||
} | ||
|
||
@Override | ||
public void onMatch(RelOptRuleCall call) { | ||
final Project topProject = call.rel(0); | ||
final Project bottomProject = call.rel(1); | ||
if (FlinkRexUtil.isMergeable(topProject, bottomProject)) { | ||
super.onMatch(call); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.