This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new a98508fd36 [CALCITE-6460] SortRemoveConstantKeysRule fails with
AssertionError due to mismatched collation on resulting Sort
a98508fd36 is described below
commit a98508fd36e2a213ba4772c709999f494e61bb11
Author: Ruben Quesada Lopez <[email protected]>
AuthorDate: Tue Jul 9 12:30:26 2024 +0100
[CALCITE-6460] SortRemoveConstantKeysRule fails with AssertionError due to
mismatched collation on resulting Sort
---
.../org/apache/calcite/rel/rules/SortRemoveConstantKeysRule.java | 8 +++++++-
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java | 5 +++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveConstantKeysRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveConstantKeysRule.java
index 9881e847a3..1728956ab1 100644
---
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveConstantKeysRule.java
+++
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveConstantKeysRule.java
@@ -19,6 +19,7 @@ package org.apache.calcite.rel.rules;
import org.apache.calcite.plan.RelOptPredicateList;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollationTraitDef;
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelFieldCollation;
@@ -77,8 +78,13 @@ public class SortRemoveConstantKeysRule
return;
}
+ final RelCollation collation =
+
RelCollationTraitDef.INSTANCE.canonize(RelCollations.of(collationsList));
final Sort result =
- sort.copy(sort.getTraitSet(), input, RelCollations.of(collationsList));
+ sort.copy(
+ sort.getTraitSet().replaceIf(RelCollationTraitDef.INSTANCE, () ->
collation),
+ input,
+ collation);
call.transformTo(result);
call.getPlanner().prune(sort);
}
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 46ec204a5a..101b8bbde1 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -1383,6 +1383,11 @@ class RelOptRulesTest extends RelOptTestBase {
+ "group by deptno, sal\n"
+ "order by deptno, sal desc nulls first";
sql(sql)
+ // Use VolcanoPlanner with collation to ensure the correct creation of
the new Sort
+ .withVolcanoPlanner(false, p -> {
+ p.addRelTraitDef(RelCollationTraitDef.INSTANCE);
+ RelOptUtil.registerDefaultRules(p, false, false);
+ })
.withRule(CoreRules.SORT_REMOVE_CONSTANT_KEYS)
.check();
}