diff --git a/core/src/main/java/org/apache/calcite/rel/RelCollations.java b/core/src/main/java/org/apache/calcite/rel/RelCollations.java index feea59687ec..e5107e42060 100644 --- a/core/src/main/java/org/apache/calcite/rel/RelCollations.java +++ b/core/src/main/java/org/apache/calcite/rel/RelCollations.java @@ -270,7 +270,7 @@ public static RelCollation shift(RelCollation collation, int offset) { for (RelFieldCollation fc : collation.getFieldCollations()) { fieldCollations.add(fc.shift(offset)); } - return new RelCollationImpl(fieldCollations.build()); + return RelCollationTraitDef.INSTANCE.canonize(new RelCollationImpl(fieldCollations.build())); } /** Creates a copy of this collation that changes the ordinals of input diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinCopyRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinCopyRule.java index b8dc3e5dd1d..b4bc4b549a6 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinCopyRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinCopyRule.java @@ -96,9 +96,7 @@ public SortJoinCopyRule(Class sortClass, if (leftFieldCollation.isEmpty()) { newLeftInput = join.getLeft(); } else { - final RelCollation leftCollation = - RelCollationTraitDef.INSTANCE.canonize( - RelCollations.of(leftFieldCollation)); + final RelCollation leftCollation = RelCollations.of(leftFieldCollation); // If left table already sorted don't add a sort if (RelMdUtil.checkInputForCollationAndLimit( metadataQuery, @@ -121,9 +119,8 @@ public SortJoinCopyRule(Class sortClass, newRightInput = join.getRight(); } else { final RelCollation rightCollation = - RelCollationTraitDef.INSTANCE.canonize( - RelCollations.shift(RelCollations.of(rightFieldCollation), - -join.getLeft().getRowType().getFieldCount())); + RelCollations.shift(RelCollations.of(rightFieldCollation), + -join.getLeft().getRowType().getFieldCount()); // If right table already sorted don't add a sort if (RelMdUtil.checkInputForCollationAndLimit( metadataQuery, diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java index 8fd7cff880d..e3d2d5b3c58 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java @@ -19,7 +19,6 @@ 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; import org.apache.calcite.rel.RelNode; @@ -145,9 +144,7 @@ public SortJoinTransposeRule(Class sortClass, newRightInput = join.getRight(); } else { final RelCollation rightCollation = - RelCollationTraitDef.INSTANCE.canonize( - RelCollations.shift(sort.getCollation(), - -join.getLeft().getRowType().getFieldCount())); + RelCollations.shift(sort.getCollation(), -join.getLeft().getRowType().getFieldCount()); // If the input is already sorted and we are not reducing the number of tuples, // we bail out if (RelMdUtil.checkInputForCollationAndLimit(mq, join.getRight(), 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 1728956ab17..2a996523637 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 @@ -78,8 +78,7 @@ protected SortRemoveConstantKeysRule(Config config) { return; } - final RelCollation collation = - RelCollationTraitDef.INSTANCE.canonize(RelCollations.of(collationsList)); + final RelCollation collation = RelCollations.of(collationsList); final Sort result = sort.copy( sort.getTraitSet().replaceIf(RelCollationTraitDef.INSTANCE, () -> collation),