You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2024/04/01 08:05:42 UTC

(ignite-3) branch ignite-21580 created (now 76aea21355)

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a change to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


      at 76aea21355 Remove unwanted project

This branch includes the following new commits:

     new db9417f625 Fix wrong memory estimation for IgniteAggregate.
     new c0f8daa13c fix tests
     new 2ba68566f6 Fix typo
     new 80e48e1a15 Fix Collation pass-through for sorted map aggregate
     new 001a1be2f2 Fix distinct row count calculation.
     new 677ac061c5 Fix tests
     new 99a1e43cc2 Fix aggregate row count estimation.
     new cf13d61517 Fix tests.
     new 29b86f766c fixup! Fix aggregate row count estimation.
     new 76aea21355 Remove unwanted project

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(ignite-3) 01/10: Fix wrong memory estimation for IgniteAggregate.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit db9417f62571ebc1d5f0057a0cb9a9a16a748ff3
Author: amashenkov <an...@gmail.com>
AuthorDate: Wed Mar 27 16:28:05 2024 +0300

    Fix wrong memory estimation for IgniteAggregate.
---
 .../org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
index 637d2aca19..484ad1f0c8 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
@@ -78,10 +78,13 @@ public abstract class IgniteAggregate extends Aggregate implements IgniteRel {
 
         if (!aggCalls.isEmpty()) {
             double grps = estimateRowCount(mq);
-            double rows = input.estimateRowCount(mq);
 
             for (AggregateCall aggCall : aggCalls) {
                 if (aggCall.isDistinct()) {
+                    Double distinctRowCount = mq.getDistinctRowCount(getInput(), ImmutableBitSet.of(aggCall.getArgList()), null);
+
+                    double rows = distinctRowCount == null ? input.estimateRowCount(mq) : distinctRowCount;
+
                     mem += IgniteCost.AGG_CALL_MEM_COST * rows / grps;
                 } else {
                     mem += IgniteCost.AGG_CALL_MEM_COST;


(ignite-3) 07/10: Fix aggregate row count estimation.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 99a1e43cc2437acffb64c3d2e3bce210c146ef26
Author: amashenkov <an...@gmail.com>
AuthorDate: Sun Mar 31 13:24:10 2024 +0300

    Fix aggregate row count estimation.
---
 .../ignite/internal/sql/engine/rel/IgniteAggregate.java       | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
index 78a0a3d67b..240d142868 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
@@ -66,7 +66,14 @@ public abstract class IgniteAggregate extends Aggregate implements IgniteRel {
 
         // Estimation of the groups count is not available.
         // Use heuristic estimation for result rows count.
-        return super.estimateRowCount(mq);
+        int groupCount = groupSet.cardinality();
+        if (groupCount == 0) {
+            return 1;
+        } else {
+            double rowCount = mq.getRowCount(input);
+            rowCount *= 1.0 - Math.pow(.75, groupCount);
+            return rowCount;
+        }
     }
 
     /**
@@ -85,7 +92,7 @@ public abstract class IgniteAggregate extends Aggregate implements IgniteRel {
                     Double distinctRowCount = mq.getDistinctRowCount(getInput(), aggGroup, null);
 
                     double distinctRows = distinctRowCount != null ? distinctRowCount
-                            : mq.getRowCount(getInput()) * (1 - Math.pow(0.5, aggGroup.cardinality()));
+                            : mq.getRowCount(getInput()) * (1 - Math.pow(0.75, aggGroup.cardinality()));
 
                     mem += IgniteCost.AGG_CALL_MEM_COST * distinctRows / grps;
                 } else {


(ignite-3) 10/10: Remove unwanted project

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 76aea213550eaa8e8be0e9d9061fde4d7ed13c22
Author: amashenkov <an...@gmail.com>
AuthorDate: Mon Apr 1 11:05:26 2024 +0300

    Remove unwanted project
---
 .../apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java
index ec8c2819e4..5b8900a035 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java
@@ -461,7 +461,7 @@ public class MapReduceAggregates {
             return rexBuilder.makeCast(typeFactory.createSqlType(SqlTypeName.BIGINT), ref, true, false);
         };
 
-        return new MapReduceAgg(argList, call, sum0, exprBuilder);
+        return new MapReduceAgg(argList, call, sum0, USE_INPUT_FIELD);
     }
 
     private static MapReduceAgg createSimpleAgg(AggregateCall call, int reduceArgumentOffset) {


(ignite-3) 03/10: Fix typo

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 2ba68566f6b1afd3f00428532f526669ce42792e
Author: amashenkov <an...@gmail.com>
AuthorDate: Wed Mar 27 20:34:26 2024 +0300

    Fix typo
---
 .../ignite/internal/sql/engine/metadata/cost/IgniteCostFactory.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/cost/IgniteCostFactory.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/cost/IgniteCostFactory.java
index 81a623715d..78d481846d 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/cost/IgniteCostFactory.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/cost/IgniteCostFactory.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.sql.engine.metadata.cost;
 
 import org.apache.calcite.plan.RelOptCost;
 import org.apache.calcite.plan.RelOptCostFactory;
+import org.jetbrains.annotations.TestOnly;
 
 /**
  * Ignite cost factory. Creates a desired cost with regards to the weight of each particular resource.
@@ -47,8 +48,9 @@ public class IgniteCostFactory implements RelOptCostFactory {
     }
 
     /**
-     * Cerates a factory with provided weights. Each weight should be non negative value.
+     * Crates a factory with provided weights. Each weight should be non negative value.
      */
+    @TestOnly
     public IgniteCostFactory(double cpuWeight, double memoryWeight, double ioWeight, double networkWeight) {
         if (cpuWeight < 0 || memoryWeight < 0 || ioWeight < 0 || networkWeight < 0) {
             throw new IllegalArgumentException("Weight should be non negative: cpu=" + cpuWeight


(ignite-3) 09/10: fixup! Fix aggregate row count estimation.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 29b86f766c16828a78da6d36fa2c223f4a3c4e47
Author: amashenkov <an...@gmail.com>
AuthorDate: Mon Apr 1 11:05:04 2024 +0300

    fixup! Fix aggregate row count estimation.
---
 .../engine/metadata/IgniteMdDistinctRowCount.java  | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
index 6b1cce64c2..ea69593144 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.sql.engine.metadata;
 import org.apache.calcite.plan.Convention;
 import org.apache.calcite.plan.volcano.RelSubset;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
 import org.apache.calcite.rel.metadata.CyclicMetadataException;
 import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMdDistinctRowCount;
@@ -29,6 +30,7 @@ import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.util.BuiltInMethod;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.NumberUtil;
+import org.checkerframework.checker.nullness.qual.Nullable;
 
 /**
  * IgniteMdDistinctRowCount.
@@ -40,6 +42,26 @@ public class IgniteMdDistinctRowCount extends RelMdDistinctRowCount {
             ReflectiveRelMetadataProvider.reflectiveSource(
                     BuiltInMethod.DISTINCT_ROW_COUNT.method, new IgniteMdDistinctRowCount());
 
+    @Override
+    public @Nullable Double getDistinctRowCount(Aggregate rel, RelMetadataQuery mq, ImmutableBitSet groupKey, @Nullable RexNode predicate) {
+        // Estimation of the groups count is not available.
+        // Use heuristic estimation for result rows count.
+        int groupCount = groupKey.cardinality();
+        if (groupCount == 0) {
+            return 1.0;
+        } else {
+            Double groupsCnt = mq.getDistinctRowCount(rel.getInput(), groupKey, predicate);
+
+            if (groupsCnt != null) {
+                return groupsCnt;
+            }
+
+            double rowCount = mq.getRowCount(rel.getInput());
+            rowCount *= 1.0 - Math.pow(.75, groupCount);
+            return rowCount;
+        }
+    }
+
     /** {@inheritDoc} */
     @Override
     public Double getDistinctRowCount(


(ignite-3) 05/10: Fix distinct row count calculation.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 001a1be2f26c9914ebf8db0ad8c94d37a42b85db
Author: amashenkov <an...@gmail.com>
AuthorDate: Fri Mar 29 19:23:37 2024 +0300

    Fix distinct row count calculation.
---
 .../engine/metadata/IgniteMdDistinctRowCount.java  | 27 +++++++++++++++++-----
 .../internal/sql/engine/rel/IgniteAggregate.java   |  8 ++++---
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
index 9530ee5059..6b1cce64c2 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdDistinctRowCount.java
@@ -17,7 +17,10 @@
 
 package org.apache.ignite.internal.sql.engine.metadata;
 
+import org.apache.calcite.plan.Convention;
 import org.apache.calcite.plan.volcano.RelSubset;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.metadata.CyclicMetadataException;
 import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMdDistinctRowCount;
 import org.apache.calcite.rel.metadata.RelMetadataProvider;
@@ -25,6 +28,7 @@ import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.util.BuiltInMethod;
 import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.NumberUtil;
 
 /**
  * IgniteMdDistinctRowCount.
@@ -44,14 +48,25 @@ public class IgniteMdDistinctRowCount extends RelMdDistinctRowCount {
             ImmutableBitSet groupKey,
             RexNode predicate
     ) {
-        if (groupKey.cardinality() == 0) {
-            return 1d;
+        RelNode best = rel.getBest();
+        if (best != null) {
+            return mq.getDistinctRowCount(best, groupKey, predicate);
         }
 
-        double rowCount = mq.getRowCount(rel);
-
-        rowCount *= 1.0 - Math.pow(.5, groupKey.cardinality());
+        if (rel.getConvention() == Convention.NONE) {
+            return null;
+        }
 
-        return rowCount;
+        Double d = null;
+        for (RelNode r2 : rel.getRels()) {
+            try {
+                Double d2 = mq.getDistinctRowCount(r2, groupKey, predicate);
+                d = NumberUtil.min(d, d2);
+            } catch (CyclicMetadataException e) {
+                // Ignore this relational expression; there will be non-cyclic ones
+                // in this set.
+            }
+        }
+        return d;
     }
 }
diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
index 484ad1f0c8..78a0a3d67b 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
@@ -81,11 +81,13 @@ public abstract class IgniteAggregate extends Aggregate implements IgniteRel {
 
             for (AggregateCall aggCall : aggCalls) {
                 if (aggCall.isDistinct()) {
-                    Double distinctRowCount = mq.getDistinctRowCount(getInput(), ImmutableBitSet.of(aggCall.getArgList()), null);
+                    ImmutableBitSet aggGroup = ImmutableBitSet.of(aggCall.getArgList());
+                    Double distinctRowCount = mq.getDistinctRowCount(getInput(), aggGroup, null);
 
-                    double rows = distinctRowCount == null ? input.estimateRowCount(mq) : distinctRowCount;
+                    double distinctRows = distinctRowCount != null ? distinctRowCount
+                            : mq.getRowCount(getInput()) * (1 - Math.pow(0.5, aggGroup.cardinality()));
 
-                    mem += IgniteCost.AGG_CALL_MEM_COST * rows / grps;
+                    mem += IgniteCost.AGG_CALL_MEM_COST * distinctRows / grps;
                 } else {
                     mem += IgniteCost.AGG_CALL_MEM_COST;
                 }


(ignite-3) 06/10: Fix tests

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 677ac061c5718c8146f0d94d347e33880bcab130
Author: amashenkov <an...@gmail.com>
AuthorDate: Fri Mar 29 19:24:17 2024 +0300

    Fix tests
---
 .../sql/engine/planner/AggregatePlannerTest.java         | 16 ++++++----------
 .../planner/MapReduceSortAggregatePlannerTest.java       |  5 +----
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
index ae8bec9b37..d3ab2e6750 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
@@ -468,7 +468,7 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
         Predicate<AggregateCall> countReduce = (a) ->
                 Objects.equals(a.getAggregation().getName(), "$SUM0") && a.getArgList().equals(List.of(1));
 
-        Predicate<RelNode> nonColocatedGroupBy = hasChildThat(isInstanceOf(IgniteReduceHashAggregate.class)
+        Predicate<RelNode> nonColocatedGroupBy = nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
                 .and(in -> hasAggregates(countReduce).test(in.getAggregateCalls()))
                 .and(input(isInstanceOf(IgniteExchange.class)
                         .and(input(isInstanceOf(IgniteMapHashAggregate.class)
@@ -809,15 +809,11 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkCountDistinctHash(TestCase testCase) throws Exception {
         assertPlan(testCase, nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                .and(nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
-                        .and(hasGroupSets(IgniteReduceHashAggregate::getGroupSets, 0))
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(hasDistribution(single())
-                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
-                                                .and(hasGroupSets(IgniteMapHashAggregate::getGroupSets, 1))
-                                        ))
-                                )
-                        ))
+                .and(hasNoGroupSets(IgniteColocatedHashAggregate::getGroupSets))
+                .and(hasAggregate())
+                .and(hasDistinctAggregate())
+                .and(input(isInstanceOf(IgniteExchange.class)
+                        .and(hasDistribution(single()))
                 ))
         ));
     }
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
index 5329cccbc0..578e8be72f 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
@@ -520,13 +520,10 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
         Predicate<IgniteReduceSortAggregate> inputAgg = isInstanceOf(IgniteReduceSortAggregate.class)
                 .and(hasGroupSets(IgniteReduceSortAggregate::getGroupSets, 0))
                 .and(hasCollation(RelCollations.of(0)))
-                .and(input(isInstanceOf(IgniteExchange.class)
-                        .and(hasCollation(RelCollations.of(0)))
-                        .and(hasDistribution(single()))
                         .and(input(isInstanceOf(IgniteMapSortAggregate.class)
                                 .and(hasCollation(RelCollations.of(1)))
                                 .and(hasGroupSets(Aggregate::getGroupSets, 1))
-                ))));
+                ));
 
         assertPlan(TestCase.CASE_24_1, nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
                         .and(hasNoGroupSets(IgniteReduceSortAggregate::getGroupSets))


(ignite-3) 08/10: Fix tests.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit cf13d61517d090a972fdbca83b913640e2406af7
Author: amashenkov <an...@gmail.com>
AuthorDate: Sun Mar 31 13:40:05 2024 +0300

    Fix tests.
---
 .../sql/engine/planner/AggregatePlannerTest.java   | 172 +++++++++++----------
 .../planner/MapReduceHashAggregatePlannerTest.java | 103 ++++++------
 .../planner/MapReduceSortAggregatePlannerTest.java |  64 ++++----
 3 files changed, 173 insertions(+), 166 deletions(-)

diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
index d3ab2e6750..b1ea5b2287 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.internal.sql.engine.rel.IgniteCorrelatedNestedLoopJoin;
 import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
 import org.apache.ignite.internal.sql.engine.rel.IgniteLimit;
 import org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin;
+import org.apache.ignite.internal.sql.engine.rel.IgniteProject;
 import org.apache.ignite.internal.sql.engine.rel.IgniteSort;
 import org.apache.ignite.internal.sql.engine.rel.IgniteTableScan;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteColocatedHashAggregate;
@@ -116,9 +117,8 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
         checkSimpleAggWithGroupByHash(TestCase.CASE_5A);
         checkSimpleAggWithGroupByHash(TestCase.CASE_5B);
 
-        // TODO replace with calls to test methods after https://issues.apache.org/jira/browse/IGNITE-20083 is resolved
-        assumeRun("checkSimpleAggWithGroupByHash", TestCase.CASE_6A);
-        assumeRun("checkSimpleAggWithGroupByHash", TestCase.CASE_6B);
+        checkSimpleAggWithGroupByHash(TestCase.CASE_6A);
+        checkSimpleAggWithGroupByHash(TestCase.CASE_6B);
 
         checkSimpleAggWithColocatedGroupByHash(TestCase.CASE_5C);
         checkSimpleAggWithColocatedGroupByHash(TestCase.CASE_5D);
@@ -248,22 +248,8 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
     public void distinctAggregateInWhereClause() throws Exception {
         checkGroupWithNoAggregateSingle(TestCase.CASE_15);
 
-        assertPlan(TestCase.CASE_15A,
-                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                        .and(not(hasAggregate()))
-                        .and(hasGroups())
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(input(isTableScan("TEST")))
-                        ))
-                ));
-        assertPlan(TestCase.CASE_15B,
-                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                        .and(not(hasAggregate()))
-                        .and(hasGroups())
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(input(isTableScan("TEST")))
-                        ))
-                ));
+        checkGroupWithNoAggregateHash(TestCase.CASE_15A);
+        checkGroupWithNoAggregateHash(TestCase.CASE_15B);
     }
 
     /**
@@ -365,14 +351,14 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
      */
     @Test
     public void aggregateWithOrderByGroupColumns() throws Exception {
-        checkGroupsWithOrderByGroupColumnsSingle(TestCase.CASE_19_1, TraitUtils.createCollation(List.of(0, 1)));
-        checkGroupsWithOrderByGroupColumnsSingle(TestCase.CASE_19_2, TraitUtils.createCollation(List.of(1, 0)));
+        checkGroupsWithOrderByGroupColumnsSingle(TestCase.CASE_19_1, TraitUtils.createCollation(List.of(0)));
+        checkGroupsWithOrderByGroupColumnsSingle(TestCase.CASE_19_2, TraitUtils.createCollation(List.of(1)));
 
-        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_1A, TraitUtils.createCollation(List.of(0, 1)));
-        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_2A, TraitUtils.createCollation(List.of(1, 0)));
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_1A, TraitUtils.createCollation(List.of(0)));
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_2A, TraitUtils.createCollation(List.of(1)));
 
-        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_1B, TraitUtils.createCollation(List.of(0, 1)));
-        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_2B, TraitUtils.createCollation(List.of(1, 0)));
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_1B, TraitUtils.createCollation(List.of(0)));
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_19_2B, TraitUtils.createCollation(List.of(1)));
     }
 
     /**
@@ -380,32 +366,10 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
      */
     @Test
     public void aggregateWithGroupBySubsetOrderByColumns() throws Exception {
-        assertPlan(TestCase.CASE_20,
-                isInstanceOf(IgniteSort.class)
-                        .and(s -> s.collation().equals(TraitUtils.createCollation(List.of(0, 1, 2))))
-                        .and(nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(input(isTableScan("TEST")))
-                        ))
-        );
+        checkGroupsWithOrderByGroupColumnsSingle(TestCase.CASE_20, TraitUtils.createCollation(List.of(0, 1, 2)));
 
-        assertPlan(TestCase.CASE_20A,
-                isInstanceOf(IgniteSort.class)
-                        .and(s -> s.collation().equals(TraitUtils.createCollation(List.of(0, 1, 2))))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(input(isInstanceOf(IgniteExchange.class)
-                                        .and(input(isTableScan("TEST")))
-                                ))
-                        ))
-        );
-        assertPlan(TestCase.CASE_20B,
-                isInstanceOf(IgniteSort.class)
-                        .and(s -> s.collation().equals(TraitUtils.createCollation(List.of(0, 1, 2))))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(input(isInstanceOf(IgniteExchange.class)
-                                        .and(input(isTableScan("TEST")))
-                                ))
-                        ))
-        );
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_20A, TraitUtils.createCollation(List.of(0, 1, 2)));
+        checkGroupsWithOrderByGroupColumnsHash(TestCase.CASE_20B, TraitUtils.createCollation(List.of(0, 1, 2)));
     }
 
 
@@ -495,17 +459,35 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
     /** Validate that we choose single phase AVG aggregate for AVG by default. */
     @Test
     public void avgAgg() throws Exception {
-        Predicate<AggregateCall> countMap = (a) -> Objects.equals(a.getAggregation().getName(), "AVG") && a.getArgList().equals(List.of(1));
+        Predicate<AggregateCall> avgAgg = (a) -> Objects.equals(a.getAggregation().getName(), "AVG") && a.getArgList().equals(List.of(1));
 
-        Predicate<IgniteColocatedHashAggregate> nonColocated = isInstanceOf(IgniteColocatedHashAggregate.class)
-                .and(in -> hasAggregates(countMap).test(in.getAggCallList()))
-                .and(input(isInstanceOf(IgniteExchange.class)
-                        .and(hasDistribution(single()))));
+        Predicate<AggregateCall> sumMap = (a) ->
+                Objects.equals(a.getAggregation().getName(), "SUM") && a.getArgList().equals(List.of(1));
+
+        Predicate<AggregateCall> countMap = (a) ->
+                Objects.equals(a.getAggregation().getName(), "COUNT") && a.getArgList().equals(List.of(1));
+
+        Predicate<AggregateCall> sumReduce = (a) ->
+                Objects.equals(a.getAggregation().getName(), "SUM") && a.getArgList().equals(List.of(1));
+
+        Predicate<AggregateCall> sum0Reduce = (a) ->
+                Objects.equals(a.getAggregation().getName(), "$SUM0") && a.getArgList().equals(List.of(2));
+
+        Predicate<RelNode> nonColocated = nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                .and(in -> hasAggregates(sumReduce, sum0Reduce).test(in.getAggregateCalls()))
+                .and(input(isInstanceOf(IgniteProject.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(hasDistribution(single()))
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                .and(in -> hasAggregates(sumMap, countMap).test(in.getAggCallList()))
+                                        )
+                                ))
+                        ))));
 
         Predicate<IgniteExchange> colocatedGroupBy = isInstanceOf(IgniteExchange.class)
                 .and(hasDistribution(single()))
                 .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                        .and(in -> hasAggregates(countMap).test(in.getAggCallList()))
+                        .and(in -> hasAggregates(avgAgg).test(in.getAggCallList()))
                         .and(input(isTableScan("TEST")))
                 ));
 
@@ -626,14 +608,20 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkDistinctAggHash(TestCase testCase) throws Exception {
         assertPlan(testCase,
-                isInstanceOf(IgniteColocatedHashAggregate.class)
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
                         .and(hasAggregate())
-                        .and(hasDistinctAggregate())
-                        .and(hasGroups())
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(input(isTableScan("TEST")))
+                        .and(not(hasDistinctAggregate()))
+                        .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                .and(not(hasAggregate()))
+                                .and(hasGroups())
+                                .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                .and(not(hasAggregate()))
+                                                .and(input(isTableScan("TEST")))
+                                        ))
+                                ))
                         ))
-        );
+                ));
     }
 
     private void checkColocatedDistinctAggHash(TestCase testCase) throws Exception {
@@ -665,13 +653,20 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
     private void checkDistinctAggWithGroupByHash(TestCase testCase) throws Exception {
         assertPlan(testCase,
                 nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                        .and(hasDistinctAggregate())
-                        .and(hasGroups())
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(input(isTableScan("TEST")))
+                        .and(hasAggregate())
+                        .and(not(hasDistinctAggregate()))
+                        .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                .and(not(hasAggregate()))
+                                .and(hasGroups())
+                                .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                .and(not(hasAggregate()))
+                                                .and(hasGroups())
+                                                .and(input(isTableScan("TEST")))
+                                        ))
+                                ))
                         ))
-                )
-        );
+                ));
     }
 
     private void checkDistinctAggWithColocatedGroupByHash(TestCase testCase) throws Exception {
@@ -729,11 +724,15 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkGroupWithNoAggregateHash(TestCase testCase) throws Exception {
         assertPlan(testCase,
-                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
                         .and(not(hasAggregate()))
                         .and(hasGroups())
                         .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(input(isTableScan("TEST")))
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                        .and(not(hasAggregate()))
+                                        .and(hasGroups())
+                                        .and(input(isTableScan("TEST")))
+                                ))
                         ))
                 ));
     }
@@ -786,9 +785,9 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkGroupsWithOrderByGroupColumnsSingle(TestCase testCase, RelCollation collation) throws Exception {
         assertPlan(testCase,
-                isInstanceOf(IgniteColocatedSortAggregate.class)
-                        .and(input(isInstanceOf(IgniteSort.class)
-                                .and(s -> s.collation().equals(collation))
+                isInstanceOf(IgniteSort.class)
+                        .and(s -> s.collation().equals(collation))
+                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
                                 .and(input(isTableScan("TEST")))
                         ))
         );
@@ -796,12 +795,13 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkGroupsWithOrderByGroupColumnsHash(TestCase testCase, RelCollation collation) throws Exception {
         assertPlan(testCase,
-                isInstanceOf(IgniteColocatedSortAggregate.class)
-                        .and(input(isInstanceOf(IgniteExchange.class)
-                                .and(hasDistribution(single()))
-                                .and(input(isInstanceOf(IgniteSort.class)
-                                        .and(s -> s.collation().equals(collation))
-                                        .and(input(isTableScan("TEST")))
+                isInstanceOf(IgniteSort.class)
+                        .and(s -> s.collation().equals(collation))
+                        .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                .and(input(isTableScan("TEST")))
+                                        ))
                                 ))
                         ))
         );
@@ -809,11 +809,15 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
     private void checkCountDistinctHash(TestCase testCase) throws Exception {
         assertPlan(testCase, nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
-                .and(hasNoGroupSets(IgniteColocatedHashAggregate::getGroupSets))
-                .and(hasAggregate())
-                .and(hasDistinctAggregate())
-                .and(input(isInstanceOf(IgniteExchange.class)
-                        .and(hasDistribution(single()))
+                .and(nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(hasGroupSets(IgniteReduceHashAggregate::getGroupSets, 0))
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(hasDistribution(single())
+                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                .and(hasGroupSets(IgniteMapHashAggregate::getGroupSets, 1))
+                                        ))
+                                )
+                        ))
                 ))
         ));
     }
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceHashAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceHashAggregatePlannerTest.java
index 5d1813b1b0..e6c26585e8 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceHashAggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceHashAggregatePlannerTest.java
@@ -139,22 +139,23 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
         checkDistinctAggWithGroupBySingle(TestCase.CASE_7_2);
         checkDistinctAggWithGroupBySingle(TestCase.CASE_7_3);
 
+        // TODO REMOVE TODO and close ticket
         // TODO replace with calls to test methods after https://issues.apache.org/jira/browse/IGNITE-20083 is fixed
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_1A);
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_2A);
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_3A);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_1A);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_2A);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_3A);
 
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_1B);
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_2B);
-        assumeRun("checkDistinctAggWithGroupByHash", TestCase.CASE_7_3B);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_1B);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_2B);
+        checkDistinctAggWithGroupByHash(TestCase.CASE_7_3B);
 
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_1C);
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_2C);
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_3C);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_1C);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_2C);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_3C);
 
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_1D);
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_2D);
-        assumeRun("checkDistinctAggWithColocatedGroupByHash", TestCase.CASE_7_3D);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_1D);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_2D);
+        checkDistinctAggWithColocatedGroupByHash(TestCase.CASE_7_3D);
     }
 
     /**
@@ -212,11 +213,11 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
     @Test
     public void distinctWithoutAggregate() throws Exception {
         checkGroupWithNoAggregateSingle(TestCase.CASE_12);
-        // TODO replace with calls to test methods after https://issues.apache.org/jira/browse/IGNITE-20083 is resolved
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_12A);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_12B);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_12C);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_12D);
+
+        checkGroupWithNoAggregateHash(TestCase.CASE_12A);
+        checkGroupWithNoAggregateHash(TestCase.CASE_12B);
+        checkGroupWithNoAggregateHash(TestCase.CASE_12C);
+        checkGroupWithNoAggregateHash(TestCase.CASE_12D);
     }
 
     /**
@@ -225,11 +226,11 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
     @Test
     public void distinctWithoutAggregateUseIndex() throws Exception {
         checkGroupWithNoAggregateSingle(TestCase.CASE_13);
-        // TODO replace with calls to test methods after https://issues.apache.org/jira/browse/IGNITE-20083 is resolved
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_13A);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_13B);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_13C);
-        assumeRun("checkGroupWithNoAggregateHash", TestCase.CASE_13D);
+
+        checkGroupWithNoAggregateHash(TestCase.CASE_13A);
+        checkGroupWithNoAggregateHash(TestCase.CASE_13B);
+        checkGroupWithNoAggregateHash(TestCase.CASE_13C);
+        checkGroupWithNoAggregateHash(TestCase.CASE_13D);
     }
 
     /**
@@ -434,15 +435,14 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
                 ))
         );
 
-        // TODO Replace with uncommented code after https://issues.apache.org/jira/browse/IGNITE-20083 is resolved
-        assumeRun("", TestCase.CASE_21A);
-        assumeRun("", TestCase.CASE_21B);
-        /*
         assertPlan(TestCase.CASE_21A, nodeOrAnyChild(isInstanceOf(IgniteMergeJoin.class)
                 .and(input(0, subtreePredicate))
                 .and(input(1, subtreePredicate))
         ), disableRules);
-         */
+        assertPlan(TestCase.CASE_21B, nodeOrAnyChild(isInstanceOf(IgniteMergeJoin.class)
+                .and(input(0, subtreePredicate))
+                .and(input(1, subtreePredicate))
+        ), disableRules);
     }
 
     /**
@@ -460,7 +460,7 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
             return Objects.equals(aggName, "$SUM0") && a.getArgList().equals(List.of(1));
         };
 
-        Predicate<RelNode> nonColocated = hasChildThat(isInstanceOf(IgniteReduceHashAggregate.class)
+        Predicate<RelNode> nonColocated = nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
                 .and(in -> hasAggregates(countReduce).test(in.getAggregateCalls()))
                 .and(input(isInstanceOf(IgniteExchange.class)
                         .and(input(isInstanceOf(IgniteMapHashAggregate.class)
@@ -525,8 +525,7 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
                         .and(hasNoGroupSets(IgniteReduceHashAggregate::getGroupSets))
                         .and(input(isInstanceOf(IgniteMapHashAggregate.class)
                                 .and(hasNoGroupSets(IgniteMapHashAggregate::getGroupSets))
-                                .and(input(isInstanceOf(IgniteProject.class).and(input(inputAgg)))
-                                ))
+                                .and(input(inputAgg)))
                         )),
                 disableRules);
     }
@@ -686,6 +685,29 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
         );
     }
 
+    private void checkDistinctAggWithColocatedGroupByHash(TestCase testCase) throws Exception {
+        assertPlan(testCase,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(hasAggregate())
+                        .and(not(hasDistinctAggregate()))
+                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                        .and(not(hasAggregate()))
+                                        .and(hasGroups())
+                                        .and(input(isInstanceOf(IgniteExchange.class)
+                                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                                        .and(not(hasAggregate()))
+                                                        .and(hasGroups())
+                                                        .and(input(isTableScan("TEST")))
+                                                ))
+                                        ))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
     private void checkAggWithGroupByIndexColumnsSingle(TestCase testCase) throws Exception {
         assertPlan(testCase,
                 nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
@@ -748,11 +770,9 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteSort.class)
                         .and(s -> s.collation().equals(collation))
-                        .and(input(isInstanceOf(IgniteProject.class)
-                                .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
-                                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
-                                                .and(input(isTableScan("TEST")))
-                                        ))
+                        .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                        .and(input(isTableScan("TEST")))
                                 ))
                         )),
                 disableRules
@@ -763,14 +783,10 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteSort.class)
                         .and(s -> s.collation().equals(collation))
-                        .and(input(isInstanceOf(IgniteProject.class)
-                                .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteReduceHashAggregate.class)
+                                .and(input(isInstanceOf(IgniteExchange.class)
                                         .and(input(isInstanceOf(IgniteMapHashAggregate.class)
-                                                // TODO: https://issues.apache.org/jira/browse/IGNITE-20095
-                                                // Why can't Map be pushed down to under 'exchange'.
-                                                .and(input(isInstanceOf(IgniteExchange.class)
-                                                        .and(input(isTableScan("TEST")))
-                                                ))
+                                                .and(input(isTableScan("TEST")))
                                         ))
                                 ))
                         )),
@@ -793,8 +809,7 @@ public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerT
                         .and(hasNoGroupSets(IgniteReduceHashAggregate::getGroupSets))
                         .and(input(isInstanceOf(IgniteMapHashAggregate.class)
                                 .and(hasNoGroupSets(IgniteMapHashAggregate::getGroupSets))
-                                .and(input(isInstanceOf(IgniteProject.class).and(input(inputAgg)))
-                                ))
+                                .and(input(inputAgg)))
                         )),
                 disableRules);
     }
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
index 578e8be72f..56cab9b27a 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
@@ -461,7 +461,7 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
         Predicate<AggregateCall> countReduce = (a) ->
                 Objects.equals(a.getAggregation().getName(), "$SUM0") && a.getArgList().equals(List.of(1));
 
-        Predicate<RelNode> nonColocated = hasChildThat(isInstanceOf(IgniteReduceSortAggregate.class)
+        Predicate<RelNode> nonColocated = nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
                 .and(in -> hasAggregates(countReduce).test(in.getAggregateCalls()))
                 .and(input(isInstanceOf(IgniteExchange.class)
                         .and(hasDistribution(single()))
@@ -499,12 +499,12 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
                 .and(in -> hasAggregates(sumReduce, sum0Reduce).test(in.getAggregateCalls()))
                 .and(input(isInstanceOf(IgniteProject.class)
                         .and(input(isInstanceOf(IgniteExchange.class)
-                        .and(hasDistribution(single()))
-                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
-                                        .and(in -> hasAggregates(sumMap, countMap).test(in.getAggCallList()))
-                                )
-                        ))
-                ))));
+                                .and(hasDistribution(single()))
+                                .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                                .and(in -> hasAggregates(sumMap, countMap).test(in.getAggCallList()))
+                                        )
+                                ))
+                        ))));
 
         assertPlan(TestCase.CASE_23, nonColocated, disableRules);
         assertPlan(TestCase.CASE_23A, nonColocated, disableRules);
@@ -520,9 +520,9 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
         Predicate<IgniteReduceSortAggregate> inputAgg = isInstanceOf(IgniteReduceSortAggregate.class)
                 .and(hasGroupSets(IgniteReduceSortAggregate::getGroupSets, 0))
                 .and(hasCollation(RelCollations.of(0)))
-                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
-                                .and(hasCollation(RelCollations.of(1)))
-                                .and(hasGroupSets(Aggregate::getGroupSets, 1))
+                .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                        .and(hasCollation(RelCollations.of(1)))
+                        .and(hasGroupSets(Aggregate::getGroupSets, 1))
                 ));
 
         assertPlan(TestCase.CASE_24_1, nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
@@ -531,8 +531,7 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
                         .and(input(isInstanceOf(IgniteMapSortAggregate.class)
                                 .and(hasNoGroupSets(IgniteMapSortAggregate::getGroupSets))
                                 .and(hasCollation(RelCollations.EMPTY))
-                                .and(input(isInstanceOf(IgniteProject.class).and(input(inputAgg)))
-                                ))
+                                .and(input(inputAgg)))
                         )),
                 disableRules);
     }
@@ -826,11 +825,9 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
     private void checkGroupsWithOrderBySubsetOfGroupColumnsHash(TestCase testCase, RelCollation collation) throws Exception {
         assertPlan(testCase,
                 nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
-                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
-                                // TODO: https://issues.apache.org/jira/browse/IGNITE-20095
-                                // Why can't Map be pushed down to under 'exchange'.
-                                .and(input(isInstanceOf(IgniteExchange.class)
-                                        .and(hasDistribution(single()))
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(hasDistribution(single()))
+                                .and(input(isInstanceOf(IgniteMapSortAggregate.class)
                                         .and(input(isInstanceOf(IgniteSort.class)
                                                 .and(s -> s.collation().equals(collation))
                                                 .and(input(isTableScan("TEST")))
@@ -845,15 +842,11 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteSort.class)
                         .and(s -> s.collation().equals(TraitUtils.createCollation(List.of(0, 1, 2))))
-                        .and(input(isInstanceOf(IgniteProject.class)
-                                .and(input(isInstanceOf(IgniteReduceSortAggregate.class)
-                                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
-                                                // TODO: https://issues.apache.org/jira/browse/IGNITE-20095
-                                                // Why can't Map be pushed down to under 'exchange'.
-                                                .and(input(isInstanceOf(IgniteSort.class)
-                                                        .and(s -> s.collation().equals(collation))
-                                                        .and(input(isTableScan("TEST")
-                                                        ))
+                        .and(input(isInstanceOf(IgniteReduceSortAggregate.class)
+                                .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                        .and(input(isInstanceOf(IgniteSort.class)
+                                                .and(s -> s.collation().equals(collation))
+                                                .and(input(isTableScan("TEST")
                                                 ))
                                         ))
                                 ))
@@ -866,17 +859,13 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteSort.class)
                         .and(s -> s.collation().equals(TraitUtils.createCollation(List.of(0, 1, 2))))
-                        .and(input(isInstanceOf(IgniteProject.class)
-                                .and(input(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteReduceSortAggregate.class)
+                                .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(hasDistribution(single()))
                                         .and(input(isInstanceOf(IgniteMapSortAggregate.class)
-                                                // TODO: https://issues.apache.org/jira/browse/IGNITE-20095
-                                                // Why can't Map be pushed down to under 'exchange'.
-                                                .and(input(isInstanceOf(IgniteExchange.class)
-                                                        .and(hasDistribution(single()))
-                                                        .and(input(isInstanceOf(IgniteSort.class)
-                                                                .and(s -> s.collation().equals(collation))
-                                                                .and(input(isTableScan("TEST")
-                                                                ))
+                                                .and(input(isInstanceOf(IgniteSort.class)
+                                                        .and(s -> s.collation().equals(collation))
+                                                        .and(input(isTableScan("TEST")
                                                         ))
                                                 ))
                                         ))
@@ -904,8 +893,7 @@ public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerT
                         .and(input(isInstanceOf(IgniteMapSortAggregate.class)
                                 .and(hasNoGroupSets(IgniteMapSortAggregate::getGroupSets))
                                 .and(hasCollation(RelCollations.EMPTY))
-                                .and(input(isInstanceOf(IgniteProject.class).and(input(inputAgg)))
-                                ))
+                                .and(input(inputAgg)))
                         )),
                 disableRules);
     }


(ignite-3) 02/10: fix tests

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit c0f8daa13c99084eff950782e2b4255cd4595586
Author: amashenkov <an...@gmail.com>
AuthorDate: Wed Mar 27 17:13:55 2024 +0300

    fix tests
---
 .../sql/engine/planner/AggregatePlannerTest.java       | 18 +++++++-----------
 .../planner/ColocatedHashAggregatePlannerTest.java     | 18 +++++++-----------
 2 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
index 32363f8cb2..ae8bec9b37 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AggregatePlannerTest.java
@@ -618,11 +618,9 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
         assertPlan(testCase,
                 isInstanceOf(IgniteColocatedHashAggregate.class)
                         .and(hasAggregate())
-                        .and(not(hasDistinctAggregate()))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(hasGroups())
-                                .and(input(isTableScan("TEST")))
-                        ))
+                        .and(hasDistinctAggregate())
+                        .and(hasGroups())
+                        .and(input(isTableScan("TEST")))
         );
     }
 
@@ -630,12 +628,10 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
         assertPlan(testCase,
                 isInstanceOf(IgniteColocatedHashAggregate.class)
                         .and(hasAggregate())
-                        .and(not(hasDistinctAggregate()))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(hasGroups())
-                                .and(input(isInstanceOf(IgniteExchange.class)
-                                        .and(input(isTableScan("TEST")))
-                                ))
+                        .and(hasDistinctAggregate())
+                        .and(hasGroups())
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
                         ))
         );
     }
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedHashAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedHashAggregatePlannerTest.java
index eba053ffab..c00abb7397 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedHashAggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedHashAggregatePlannerTest.java
@@ -568,11 +568,9 @@ public class ColocatedHashAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteColocatedHashAggregate.class)
                         .and(hasAggregate())
-                        .and(not(hasDistinctAggregate()))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(hasGroups())
-                                .and(input(isTableScan("TEST")))
-                        )),
+                        .and(hasDistinctAggregate())
+                        .and(hasGroups())
+                        .and(input(isTableScan("TEST"))),
                 disableRules
         );
     }
@@ -581,12 +579,10 @@ public class ColocatedHashAggregatePlannerTest extends AbstractAggregatePlannerT
         assertPlan(testCase,
                 isInstanceOf(IgniteColocatedHashAggregate.class)
                         .and(hasAggregate())
-                        .and(not(hasDistinctAggregate()))
-                        .and(input(isInstanceOf(IgniteColocatedHashAggregate.class)
-                                .and(hasGroups())
-                                .and(input(isInstanceOf(IgniteExchange.class)
-                                        .and(input(isTableScan("TEST")))
-                                ))
+                        .and(hasDistinctAggregate())
+                        .and(hasGroups())
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
                         )),
                 disableRules
         );


(ignite-3) 04/10: Fix Collation pass-through for sorted map aggregate

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 80e48e1a153d4b4609d32e5e98cf31d8fc9ca906
Author: amashenkov <an...@gmail.com>
AuthorDate: Wed Mar 27 21:09:35 2024 +0300

    Fix Collation pass-through for sorted map aggregate
---
 .../ignite/internal/sql/engine/rel/agg/IgniteSortAggregateBase.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/IgniteSortAggregateBase.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/IgniteSortAggregateBase.java
index d763c49b95..70570999eb 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/IgniteSortAggregateBase.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/IgniteSortAggregateBase.java
@@ -80,7 +80,7 @@ interface IgniteSortAggregateBase extends TraitsAwareIgniteRel {
         ImmutableBitSet requiredKeys = ImmutableBitSet.of(required.getKeys());
         RelCollation collation;
 
-        if (getGroupSet().contains(requiredKeys)) {
+        if (ImmutableBitSet.range(getGroupSet().cardinality()).contains(requiredKeys)) {
             List<RelFieldCollation> newCollationFields = new ArrayList<>(getGroupSet().cardinality());
             newCollationFields.addAll(required.getFieldCollations());