Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-4003] Disallow cross convention matching in TransformationRule #1986

Merged
merged 1 commit into from Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,8 +21,10 @@
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelOptRuleOperand;
import org.apache.calcite.plan.RelOptRuleOperandChildPolicy;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.rules.SubstitutionRule;
import org.apache.calcite.rel.rules.TransformationRule;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -92,6 +94,12 @@ protected VolcanoRuleCall(
// implement RelOptRuleCall
public void transformTo(RelNode rel, Map<RelNode, RelNode> equiv,
RelHintsPropagator handler) {
if (rel instanceof PhysicalNode
&& rule instanceof TransformationRule) {
throw new RuntimeException(
rel + " is a PhysicalNode, which is not allowed in " + rule);
}

rel = handler.propagate(rels[0], rel);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Transform to: rel#{} via {}{}", rel.getId(), getRule(),
Expand Down Expand Up @@ -136,7 +144,9 @@ public void transformTo(RelNode rel, Map<RelNode, RelNode> equiv,
volcanoPlanner.ensureRegistered(
entry.getKey(), entry.getValue());
}
volcanoPlanner.ensureRegistered(rel, rels[0]);
// The subset is not used, but we need it, just for debugging
//noinspection unused
RelSubset subset = volcanoPlanner.ensureRegistered(rel, rels[0]);
rels[0].getCluster().invalidateMetadataQuery();

if (volcanoPlanner.getListener() != null) {
Expand Down Expand Up @@ -349,6 +359,10 @@ private void matchRecurse(int solve) {
}

for (RelNode rel : successors) {
if (operand.getRule() instanceof TransformationRule
&& rel.getConvention() != previous.getConvention()) {
continue;
}
if (!operand.matches(rel)) {
continue;
}
Expand Down
Expand Up @@ -66,6 +66,7 @@ public void onMatch(RelOptRuleCall call) {
childProject.getInput(), childProject.getProjects(),
project.getRowType());
}
stripped = convert(stripped, project.getConvention());
call.transformTo(stripped);
}

Expand Down
Expand Up @@ -61,7 +61,8 @@ public SortRemoveRule(RelBuilderFactory relBuilderFactory) {
final RelCollation collation = sort.getCollation();
assert collation == sort.getTraitSet()
.getTrait(RelCollationTraitDef.INSTANCE);
final RelTraitSet traits = sort.getInput().getTraitSet().replace(collation);
final RelTraitSet traits = sort.getInput().getTraitSet()
.replace(collation).replace(sort.getConvention());
call.transformTo(convert(sort.getInput(), traits));
}
}
2 changes: 2 additions & 0 deletions site/_docs/history.md
Expand Up @@ -34,6 +34,8 @@ Downloads are available on the

* [<a href="https://issues.apache.org/jira/browse/CALCITE-4032">CALCITE-4032</a>]
Mark `CalcMergeRule` as `TransformationRule`
* [<a href="https://issues.apache.org/jira/browse/CALCITE-4003">CALCITE-4003</a>]
Disallow cross convention matching and `PhysicalNode` generation in `TransformationRule`

## <a href="https://github.com/apache/calcite/releases/tag/calcite-1.23.0">1.23.0</a> / 2020-05-23
{: #v1-23-0}
Expand Down