diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java index db5d83960d0..a9c08865f29 100644 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java +++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java @@ -300,8 +300,7 @@ protected CassandraSortRule(CassandraSortRuleConfig config) { public RelNode convert(Sort sort, CassandraFilter filter) { final RelTraitSet traitSet = - sort.getTraitSet().replace(CassandraRel.CONVENTION) - .replace(sort.getCollation()); + sort.getTraitSet().replace(CassandraRel.CONVENTION); return new CassandraSort(sort.getCluster(), traitSet, convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)), sort.getCollation()); diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java index d897cce52c0..540dafcda19 100644 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java +++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraSort.java @@ -60,7 +60,7 @@ public CassandraSort(RelOptCluster cluster, RelTraitSet traitSet, @Override public Sort copy(RelTraitSet traitSet, RelNode input, RelCollation newCollation, @Nullable RexNode offset, @Nullable RexNode fetch) { - return new CassandraSort(getCluster(), traitSet, input, collation); + return new CassandraSort(getCluster(), traitSet, input, newCollation); } @Override public void implement(Implementor implementor) { diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java index 7cea6575cb4..0e823b8d07d 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java @@ -16,10 +16,17 @@ */ package org.apache.calcite.adapter.enumerable; +import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptRuleCall; import org.apache.calcite.plan.RelRule; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelCollationTraitDef; +import org.apache.calcite.rel.RelDistributionTraitDef; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Sort; +import org.apache.calcite.rel.metadata.RelMdCollation; +import org.apache.calcite.rel.metadata.RelMdDistribution; +import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.immutables.value.Value; @@ -46,19 +53,28 @@ protected EnumerableLimitRule(Config config) { @Override public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); + final RelOptCluster cluster = sort.getCluster(); + final RelMetadataQuery mq = cluster.getMetadataQuery(); + if (sort.offset == null && sort.fetch == null) { return; } - RelNode input = sort.getInput(); - if (!sort.getCollation().getFieldCollations().isEmpty()) { - // Create a sort with the same sort key, but no offset or fetch. - input = - sort.copy(sort.getTraitSet(), input, sort.getCollation(), null, null); - } + + final RelNode input = sort.getCollation().getFieldCollations().isEmpty() + ? sort.getInput() + : sort.copy(sort.getTraitSet(), sort.getInput(), sort.getCollation(), null, null); + final RelTraitSet traitSet = + cluster.traitSetOf(EnumerableConvention.INSTANCE) + .replaceIfs(RelCollationTraitDef.INSTANCE, + () -> RelMdCollation.limit(mq, sort)) + .replaceIf(RelDistributionTraitDef.INSTANCE, + () -> RelMdDistribution.limit(mq, input)); call.transformTo( - EnumerableLimit.create( + new EnumerableLimit( + cluster, + traitSet, convert(call.getPlanner(), input, - input.getTraitSet().replace(EnumerableConvention.INSTANCE)), + input.getTraitSet().replace(EnumerableConvention.INSTANCE)), sort.offset, sort.fetch)); } diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java index 1a033380018..7d0912ca8c4 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java @@ -42,7 +42,9 @@ public EnumerableLimitSortRule(Config config) { final Sort sort = call.rel(0); RelNode input = sort.getInput(); final Sort o = - EnumerableLimitSort.create( + new EnumerableLimitSort( + sort.getCluster(), + sort.getTraitSet().replace(EnumerableConvention.INSTANCE), convert(call.getPlanner(), input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)), sort.getCollation(), sort.offset, sort.fetch); diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java index be23b6602e8..118bd429ff0 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java @@ -58,6 +58,14 @@ public static EnumerableSort create(RelNode child, RelCollation collation, fetch); } + /** Creates an EnumerableSort. */ + public static EnumerableSort create(RelNode child, RelCollation collation, + RelTraitSet traitSet, @Nullable RexNode offset, @Nullable RexNode fetch) { + final RelOptCluster cluster = child.getCluster(); + return new EnumerableSort(cluster, traitSet, child, collation, offset, + fetch); + } + @Override public EnumerableSort copy( RelTraitSet traitSet, RelNode newInput, diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java index 14a9c8671a0..46fde260400 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java @@ -52,6 +52,7 @@ protected EnumerableSortRule(Config config) { input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)), sort.getCollation(), + sort.getTraitSet().replace(EnumerableConvention.INSTANCE), null, null); } diff --git a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java index 1a0f840af0c..1d955b19874 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java +++ b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java @@ -63,8 +63,9 @@ static RelTrait of(RelTraitDef def, } else if (traitList.size() == 1) { return def.canonize(traitList.get(0)); } else { + // make sure traits in RelCompositeTrait is strictly ordered final RelMultipleTrait[] traits = - traitList.toArray(new RelMultipleTrait[0]); + traitList.stream().sorted().toArray(RelMultipleTrait[]::new); for (int i = 0; i < traits.length; i++) { traits[i] = (T) def.canonize(traits[i]); } diff --git a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java index b91b660752e..71f0ce16337 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java +++ b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java @@ -562,6 +562,10 @@ public boolean contains(RelTrait trait) { public boolean containsIfApplicable(RelTrait trait) { // Note that '==' is sufficient, because trait should be canonized. final RelTrait trait1 = getTrait(trait.getTraitDef()); + if (trait1 instanceof RelCompositeTrait) { + List traitList = ((RelCompositeTrait) trait1).traitList(); + return traitList.contains(trait); + } return trait1 == null || trait1 == trait; } diff --git a/core/src/main/java/org/apache/calcite/rel/core/Sort.java b/core/src/main/java/org/apache/calcite/rel/core/Sort.java index 5f83f32c2ef..89897e2b2c7 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/Sort.java +++ b/core/src/main/java/org/apache/calcite/rel/core/Sort.java @@ -85,7 +85,7 @@ protected Sort( this.fetch = fetch; this.hints = ImmutableList.copyOf(hints); - assert traits.containsIfApplicable(collation) + assert collation.getFieldCollations().isEmpty() || traits.containsIfApplicable(collation) : "traits=" + traits + ", collation=" + collation; assert !(fetch == null && offset == null diff --git a/core/src/main/java/org/apache/calcite/rel/logical/LogicalSort.java b/core/src/main/java/org/apache/calcite/rel/logical/LogicalSort.java index 31b8b4b006d..169ac64e775 100644 --- a/core/src/main/java/org/apache/calcite/rel/logical/LogicalSort.java +++ b/core/src/main/java/org/apache/calcite/rel/logical/LogicalSort.java @@ -68,9 +68,13 @@ public LogicalSort(RelInput input) { public static LogicalSort create(RelNode input, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) { RelOptCluster cluster = input.getCluster(); - collation = RelCollationTraitDef.INSTANCE.canonize(collation); - RelTraitSet traitSet = - input.getTraitSet().replace(Convention.NONE).replace(collation); + final RelCollation canonize = RelCollationTraitDef.INSTANCE.canonize(collation); + + RelTraitSet traitSet = input.getTraitSet().replace(Convention.NONE); + if (!canonize.getFieldCollations().isEmpty()) { + // Preserve input collation if only offset and fetch + traitSet = traitSet.replaceIf(RelCollationTraitDef.INSTANCE, () -> canonize); + } return new LogicalSort(cluster, traitSet, input, collation, offset, fetch); } diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java index 6ffe9c1f62d..c292ca7729e 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java @@ -207,8 +207,10 @@ private RelMdCollation() {} public @Nullable ImmutableList collations(Sort sort, RelMetadataQuery mq) { - return copyOf( - RelMdCollation.sort(sort.getCollation())); + List collations = + Util.first(sort.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE), + RelMdCollation.sort(sort.getCollation())); + return copyOf(collations); } public @Nullable ImmutableList collations(SortExchange sort, diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java index e4e0b328225..00cb4d10641 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java @@ -456,51 +456,23 @@ public Boolean areColumnsUnique(Values rel, RelMetadataQuery mq, ImmutableBitSet columns, boolean ignoreNulls) { columns = decorateWithConstantColumnsFromPredicates(columns, rel, mq); for (RelNode rel2 : rel.getRels()) { - if (rel2 instanceof Aggregate - || rel2 instanceof Filter - || rel2 instanceof Values - || rel2 instanceof Sort - || rel2 instanceof TableScan - || simplyProjects(rel2, columns)) { - try { - final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls); - if (unique != null) { - if (unique) { - return true; - } - } else { - return null; + try { + final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls); + if (unique != null) { + if (unique) { + return true; } - } catch (CyclicMetadataException e) { - // Ignore this relational expression; there will be non-cyclic ones - // in this set. + } else { + return null; } + } catch (CyclicMetadataException e) { + // Ignore this relational expression; there will be non-cyclic ones + // in this set. } } return false; } - private static boolean simplyProjects(RelNode rel, ImmutableBitSet columns) { - if (!(rel instanceof Project)) { - return false; - } - Project project = (Project) rel; - final List projects = project.getProjects(); - for (int column : columns) { - if (column >= projects.size()) { - return false; - } - if (!(projects.get(column) instanceof RexInputRef)) { - return false; - } - final RexInputRef ref = (RexInputRef) projects.get(column); - if (ref.getIndex() != column) { - return false; - } - } - return true; - } - /** Splits a column set between left and right sets. */ private static Pair splitLeftAndRightColumns(int leftCount, final ImmutableBitSet columns) { diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java index ef0687f6e36..8324904a2f3 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java @@ -607,7 +607,9 @@ public RelOptPredicateList getPredicates(Values values, RelMetadataQuery mq) { public RelOptPredicateList getPredicates(RelSubset r, RelMetadataQuery mq) { if (!Bug.CALCITE_1048_FIXED) { - return RelOptPredicateList.EMPTY; + // FIXME: This is a short-term fix and may disable some applicable rules. + // A complete solution will come with [CALCITE-1048]. + return mq.getPulledUpPredicates(r.stripped()); } final RexBuilder rexBuilder = r.getCluster().getRexBuilder(); RelOptPredicateList list = null; 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 2a996523637..270aa90141b 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 @@ -16,9 +16,11 @@ */ package org.apache.calcite.rel.rules; +import org.apache.calcite.plan.ConventionTraitDef; import org.apache.calcite.plan.RelOptPredicateList; import org.apache.calcite.plan.RelOptRuleCall; import org.apache.calcite.plan.RelRule; +import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelCollation; import org.apache.calcite.rel.RelCollationTraitDef; import org.apache.calcite.rel.RelCollations; @@ -28,14 +30,18 @@ import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rex.RexBuilder; +import com.google.common.collect.ImmutableList; + import org.immutables.value.Value; import java.util.List; import java.util.stream.Collectors; +import static java.util.Objects.requireNonNull; + /** * Planner rule that removes keys from a - * a {@link org.apache.calcite.rel.core.Sort} if those keys are known to be + * {@link org.apache.calcite.rel.core.Sort} if those keys are known to be * constant, or removes the entire Sort if all keys are constant. * *

Requires {@link RelCollationTraitDef}. @@ -73,15 +79,29 @@ protected SortRemoveConstantKeysRule(Config config) { // No active collations. Remove the sort completely if (collationsList.isEmpty() && sort.offset == null && sort.fetch == null) { - call.transformTo(input); + final RelTraitSet traits = sort.getInput().getTraitSet() + .replaceIfs(RelCollationTraitDef.INSTANCE, + () -> sort.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE)); + + // We won't copy the RelTraitSet for every node in the RelSubset, + // so stripped is probably a good choice. + RelNode stripped = input.stripped(); + call.transformTo( + convert(stripped.copy(traits, stripped.getInputs()), + traits.replaceIf(ConventionTraitDef.INSTANCE, sort::getConvention))); call.getPlanner().prune(sort); return; } final RelCollation collation = RelCollations.of(collationsList); + RelCollation sortCollation = sort.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE); + final Sort result = sort.copy( - sort.getTraitSet().replaceIf(RelCollationTraitDef.INSTANCE, () -> collation), + sort.getTraitSet(). + replaceIfs(RelCollationTraitDef.INSTANCE, + () -> ImmutableList.of(collation, + requireNonNull(sortCollation, "sortCollation"))), input, collation); call.transformTo(result); diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java index 861a719094f..7a2572f3cf4 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java @@ -62,6 +62,11 @@ public SortRemoveRule(RelBuilderFactory relBuilderFactory) { // Don't remove sort if would also remove OFFSET or LIMIT. return; } + + // Composite trait not support in change trait + if (!sort.getTraitSet().allSimple()) { + return; + } // Express the "sortedness" requirement in terms of a collation trait and // we can get rid of the sort. This allows us to use rels that just happen // to be sorted but get the same effect. diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java index 4f4838d7aba..c16db452fd4 100644 --- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java +++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java @@ -3176,12 +3176,13 @@ void testInnerJoinValues(String format) { .enable(CalciteAssert.DB != CalciteAssert.DatabaseInstance.ORACLE) .explainContains("" + "EnumerableAggregate(group=[{0}], m0=[COUNT($1)])\n" - + " EnumerableAggregate(group=[{1, 3}])\n" - + " EnumerableHashJoin(condition=[=($0, $2)], joinType=[inner])\n" - + " EnumerableCalc(expr#0..9=[{inputs}], expr#10=[CAST($t4):INTEGER], expr#11=[1997], expr#12=[=($t10, $t11)], time_id=[$t0], the_year=[$t4], $condition=[$t12])\n" - + " EnumerableTableScan(table=[[foodmart2, time_by_day]])\n" - + " EnumerableCalc(expr#0..7=[{inputs}], time_id=[$t1], unit_sales=[$t7])\n" - + " EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])") + + " EnumerableCalc(expr#0=[{inputs}], expr#1=[1997:SMALLINT], expr#2=[CAST($t1):SMALLINT], c0=[$t2], unit_sales=[$t0])\n" + + " EnumerableAggregate(group=[{1}])\n" + + " EnumerableHashJoin(condition=[=($0, $2)], joinType=[semi])\n" + + " EnumerableCalc(expr#0..7=[{inputs}], time_id=[$t1], unit_sales=[$t7])\n" + + " EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])\n" + + " EnumerableCalc(expr#0..9=[{inputs}], expr#10=[CAST($t4):INTEGER], expr#11=[1997], expr#12=[=($t10, $t11)], time_id=[$t0], the_year=[$t4], $condition=[$t12])\n" + + " EnumerableTableScan(table=[[foodmart2, time_by_day]])\n") .returns("c0=1997; m0=6\n"); } 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 cb15194c038..6cb742b0145 100644 --- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java @@ -1377,6 +1377,17 @@ private void checkSemiOrAntiJoinProjectTranspose(JoinRelType type) { .check(); } + @Test void testSortRemoveAllKeysConstantInVolcano() { + final String sql = "select count(*) as c\n" + + "from sales.emp\n" + + "where deptno = 10\n" + + "group by deptno, sal\n" + + "order by deptno desc nulls last"; + sql(sql) + .withVolcanoPlanner(false) + .check(); + } + @Test void testSortRemovalOneKeyConstant() { final String sql = "select count(*) as c\n" + "from sales.emp\n" diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml index ec4d69b9c08..e778b65381b 100644 --- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml @@ -15041,6 +15041,34 @@ LogicalProject(C=[$0]) LogicalProject(DEPTNO=[$7], SAL=[$5]) LogicalFilter(condition=[=($7, 10)]) LogicalTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + + + + + + + + + + + diff --git a/core/src/test/resources/sql/sub-query.iq b/core/src/test/resources/sql/sub-query.iq index 7bfedac3a85..515fe141bac 100644 --- a/core/src/test/resources/sql/sub-query.iq +++ b/core/src/test/resources/sql/sub-query.iq @@ -922,10 +922,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project literal IN null non-correlated @@ -958,10 +957,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS FALSE($t2)], expr#5=[null:BOOLEA EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null IN literal non-correlated @@ -994,10 +992,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null IN required @@ -1030,10 +1027,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null IN nullable @@ -1066,10 +1062,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project literal IN required @@ -1135,10 +1130,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS FALSE($t2)], expr#5=[null:BOOLEA EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null NOT IN null non-correlated @@ -1171,10 +1165,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[null:BOOLEAN EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project literal NOT IN null non-correlated @@ -1207,10 +1200,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[IS FALSE($t2 EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null NOT IN literal non-correlated @@ -1243,10 +1235,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[null:BOOLEAN EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null NOT IN required @@ -1279,10 +1270,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[null:BOOLEAN EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null NOT IN nullable @@ -1315,10 +1305,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[null:BOOLEAN EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project literal NOT IN required @@ -1384,10 +1373,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[IS FALSE($t2 EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test project null IN required is unknown @@ -1420,10 +1408,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter null IN null @@ -1571,10 +1558,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], SAL=[$t1], $conditio EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter literal NOT IN null non-correlated @@ -1592,10 +1578,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[NOT($t2)], e EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[false], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter null NOT IN literal non-correlated @@ -1613,10 +1598,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], SAL=[$t1], $conditio EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter null NOT IN required @@ -1634,10 +1618,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], SAL=[$t1], $conditio EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter null NOT IN nullable @@ -1655,10 +1638,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], SAL=[$t1], $conditio EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter literal NOT IN required @@ -1676,10 +1658,8 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[NOT($t2)], e EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t4, $t0)], cs=[$t3], $condition=[$t5]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[1:BIGINT], expr#5=[10], expr#6=[=($t5, $t0)], cs=[$t3], $f1=[$t4], $condition=[$t6]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter literal NOT IN nullable @@ -1697,10 +1677,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t3)], expr#5=[NOT($t2)], e EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], expr#4=[10], expr#5=[=($t0, $t4)], cs=[$t3], $condition=[$t5]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test filter null IN required is unknown @@ -1732,10 +1711,9 @@ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[null:BOOLEAN], expr#5=[IS NOT NULL( EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5]) EnumerableTableScan(table=[[scott, EMP]]) EnumerableLimit(fetch=[1]) - EnumerableSort(sort0=[$0], dir0=[DESC]) - EnumerableAggregate(group=[{0}], c=[COUNT()]) - EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) - EnumerableTableScan(table=[[scott, DEPT]]) + EnumerableAggregate(group=[{0}], c=[COUNT()]) + EnumerableCalc(expr#0..2=[{inputs}], expr#3=[true], cs=[$t3]) + EnumerableTableScan(table=[[scott, DEPT]]) !plan #------------------------------- @@ -2970,11 +2948,10 @@ EnumerableCalc(expr#0..1=[{inputs}], expr#2=[IS NULL($t1)], DEPTNO=[$t0], $condi EnumerableNestedLoopJoin(condition=[true], joinType=[left]) EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0]) EnumerableTableScan(table=[[scott, DEPT]]) - EnumerableAggregate(group=[{0}]) - EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], expr#3=[1], expr#4=[>($t1, $t3)], i=[$t2], $condition=[$t4]) - EnumerableAggregate(group=[{7}], c=[COUNT()]) - EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[35], expr#10=[=($t8, $t9)], proj#0..7=[{exprs}], $condition=[$t10]) - EnumerableTableScan(table=[[scott, EMP]]) + EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], expr#3=[1], expr#4=[>($t1, $t3)], i=[$t2], $condition=[$t4]) + EnumerableAggregate(group=[{7}], c=[COUNT()]) + EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[35], expr#10=[=($t8, $t9)], proj#0..7=[{exprs}], $condition=[$t10]) + EnumerableTableScan(table=[[scott, EMP]]) !plan # Previous, as scalar sub-query. @@ -2996,11 +2973,10 @@ EnumerableCalc(expr#0..1=[{inputs}], expr#2=[IS NULL($t1)], DEPTNO=[$t0], U=[$t2 EnumerableNestedLoopJoin(condition=[true], joinType=[left]) EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0]) EnumerableTableScan(table=[[scott, DEPT]]) - EnumerableAggregate(group=[{0}]) - EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], expr#3=[1], expr#4=[>($t1, $t3)], i=[$t2], $condition=[$t4]) - EnumerableAggregate(group=[{7}], c=[COUNT()]) - EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[35], expr#10=[=($t8, $t9)], proj#0..7=[{exprs}], $condition=[$t10]) - EnumerableTableScan(table=[[scott, EMP]]) + EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], expr#3=[1], expr#4=[>($t1, $t3)], i=[$t2], $condition=[$t4]) + EnumerableAggregate(group=[{7}], c=[COUNT()]) + EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[35], expr#10=[=($t8, $t9)], proj#0..7=[{exprs}], $condition=[$t10]) + EnumerableTableScan(table=[[scott, EMP]]) !plan # singleton keys which a uniqueness constraint indicates that the relation is already unique. @@ -3702,16 +3678,16 @@ select deptno from dept d1 where exists ( (4 rows) !ok -EnumerableCalc(expr#0..3=[{inputs}], DEPTNO=[$t2]) - EnumerableHashJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[inner]) +EnumerableCalc(expr#0..1=[{inputs}], DEPTNO=[$t0]) + EnumerableHashJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[semi]) + EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}]) + EnumerableTableScan(table=[[scott, DEPT]]) EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}]) EnumerableMergeJoin(condition=[=($0, $2)], joinType=[inner]) EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0]) EnumerableTableScan(table=[[scott, DEPT]]) EnumerableCalc(expr#0..2=[{inputs}], expr#3=[IS NOT NULL($t1)], DNAME=[$t1], DEPTNO=[$t0], $condition=[$t3]) EnumerableTableScan(table=[[scott, DEPT]]) - EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}]) - EnumerableTableScan(table=[[scott, DEPT]]) !plan # Test case for CALCITE-5683 which throws an exception during the de-correlation phase diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java index 22da4febe8a..f02490e3c9e 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java @@ -24,7 +24,6 @@ import org.apache.calcite.plan.RelOptRuleCall; import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.InvalidRelException; -import org.apache.calcite.rel.RelCollations; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.convert.ConverterRule; import org.apache.calcite.rel.core.Sort; @@ -220,7 +219,7 @@ protected ElasticsearchSortRule(Config config) { final Sort sort = (Sort) relNode; final RelTraitSet traitSet = sort.getTraitSet().replace(out).replace(sort.getCollation()); return new ElasticsearchSort(relNode.getCluster(), traitSet, - convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)), sort.getCollation(), + convert(sort.getInput(), sort.getInput().getTraitSet().replace(out)), sort.getCollation(), sort.offset, sort.fetch); } } diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSort.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSort.java index 320e7aa3839..854e15dd89a 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSort.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSort.java @@ -57,7 +57,7 @@ public class ElasticsearchSort extends Sort implements ElasticsearchRel { @Override public Sort copy(RelTraitSet traitSet, RelNode input, RelCollation relCollation, @Nullable RexNode offset, @Nullable RexNode fetch) { - return new ElasticsearchSort(getCluster(), traitSet, input, collation, + return new ElasticsearchSort(getCluster(), traitSet, input, relCollation, offset, fetch); } diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java index b8beb854e0f..bf2738d4feb 100644 --- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java +++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java @@ -223,8 +223,7 @@ protected GeodeSortLimitRule(GeodeSortLimitRuleConfig config) { final Sort sort = call.rel(0); final RelTraitSet traitSet = sort.getTraitSet() - .replace(GeodeRel.CONVENTION) - .replace(sort.getCollation()); + .replace(GeodeRel.CONVENTION); GeodeSort geodeSort = new GeodeSort(sort.getCluster(), traitSet, diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java index c9b33252d98..d6a17cf829c 100644 --- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java +++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java @@ -66,7 +66,7 @@ public class GeodeSort extends Sort implements GeodeRel { @Override public Sort copy(RelTraitSet traitSet, RelNode input, RelCollation newCollation, RexNode offset, RexNode fetch) { - return new GeodeSort(getCluster(), traitSet, input, collation, fetch); + return new GeodeSort(getCluster(), traitSet, input, newCollation, fetch); } @Override public void implement(GeodeImplementContext geodeImplementContext) { diff --git a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbFilter.java b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbFilter.java index 37c5c57c8ce..0c584a116a0 100644 --- a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbFilter.java +++ b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbFilter.java @@ -25,7 +25,9 @@ import org.apache.calcite.rel.RelWriter; import org.apache.calcite.rel.core.Filter; import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexNode; +import org.apache.calcite.rex.RexUtil; import com.alibaba.innodb.java.reader.schema.TableDef; @@ -96,4 +98,9 @@ public static InnodbFilter create(RelOptCluster cluster, RelTraitSet traitSet, public RelCollation getImplicitCollation() { return indexCondition.getImplicitCollation(); } + + @Override public RexNode getCondition() { + RexBuilder rexBuilder = getCluster().getRexBuilder(); + return RexUtil.composeConjunction(rexBuilder, indexCondition.getPushDownConditions()); + } } diff --git a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbRules.java b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbRules.java index 8c66c0b4b6a..c319c3f3dfa 100644 --- a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbRules.java +++ b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbRules.java @@ -231,8 +231,7 @@ private static class AbstractInnodbSortRule RelNode convert(Sort sort) { final RelTraitSet traitSet = - sort.getTraitSet().replace(InnodbRel.CONVENTION) - .replace(sort.getCollation()); + sort.getTraitSet().replace(InnodbRel.CONVENTION); return new InnodbSort(sort.getCluster(), traitSet, convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)), sort.getCollation()); diff --git a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbSort.java b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbSort.java index 44fa6da3fe8..268605b859a 100644 --- a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbSort.java +++ b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbSort.java @@ -60,7 +60,7 @@ public class InnodbSort extends Sort implements InnodbRel { @Override public Sort copy(RelTraitSet traitSet, RelNode input, RelCollation newCollation, RexNode offset, RexNode fetch) { - return new InnodbSort(getCluster(), traitSet, input, collation); + return new InnodbSort(getCluster(), traitSet, input, newCollation); } @Override public void implement(Implementor implementor) { diff --git a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbToEnumerableConverter.java b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbToEnumerableConverter.java index 858ddbb3a0d..a30273ac41c 100644 --- a/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbToEnumerableConverter.java +++ b/innodb/src/main/java/org/apache/calcite/adapter/innodb/InnodbToEnumerableConverter.java @@ -73,8 +73,7 @@ protected InnodbToEnumerableConverter( @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { - final RelOptCost cost = requireNonNull(super.computeSelfCost(planner, mq)); - return cost.multiplyBy(.1); + return requireNonNull(super.computeSelfCost(planner, mq)); } static List innodbFieldNames(final RelDataType rowType) {