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 2023/02/15 11:48:12 UTC

[ignite-3] branch ignite-18208 updated: WIP. Rearrange AggregatePlannerTest tests.

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

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


The following commit(s) were added to refs/heads/ignite-18208 by this push:
     new 1e1cfe5b2d WIP. Rearrange AggregatePlannerTest tests.
1e1cfe5b2d is described below

commit 1e1cfe5b2dd3dd99ceafe16eaafb202bc79db4f7
Author: amashenkov <an...@gmail.com>
AuthorDate: Wed Feb 15 14:48:05 2023 +0300

    WIP. Rearrange AggregatePlannerTest tests.
---
 .../sql/engine/framework/TestBuilders.java         |   5 +-
 .../planner/AbstractAggregatePlannerTest.java      | 126 +++++++++++++-
 .../sql/engine/planner/AggregatePlannerTest.java   | 184 +--------------------
 .../planner/ColocatedHashAggregatePlannerTest.java | 113 +++++++++++++
 .../planner/ColocatedSortAggregatePlannerTest.java | 112 +++++++++++++
 .../planner/MapReduceHashAggregatePlannerTest.java | 128 ++++++++++++++
 .../planner/MapReduceSortAggregatePlannerTest.java | 136 +++++++++++++++
 7 files changed, 621 insertions(+), 183 deletions(-)

diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java
index 02cb0772d1..23a41e83f1 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java
@@ -286,7 +286,10 @@ public class TestBuilders {
         @Override
         public TestTable build() {
             return new TestTable(
-                    new TableDescriptorImpl(columns, distribution), name, dataProviders, size
+                    new TableDescriptorImpl(columns, distribution),
+                    Objects.requireNonNull(name),
+                    dataProviders,
+                    size
             );
         }
 
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AbstractAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AbstractAggregatePlannerTest.java
index 53e1bb1574..7337ff615f 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AbstractAggregatePlannerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/AbstractAggregatePlannerTest.java
@@ -17,11 +17,19 @@
 
 package org.apache.ignite.internal.sql.engine.planner;
 
+import static org.apache.ignite.internal.sql.engine.trait.IgniteDistributions.broadcast;
+import static org.apache.ignite.internal.sql.engine.trait.IgniteDistributions.single;
+
 import java.util.UUID;
+import java.util.function.Consumer;
 import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import org.apache.calcite.plan.RelOptUtil;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.ignite.internal.schema.NativeTypes;
+import org.apache.ignite.internal.sql.engine.framework.TestBuilders;
 import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteColocatedAggregateBase;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteColocatedHashAggregate;
@@ -32,21 +40,131 @@ import org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate;
 import org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate;
+import org.apache.ignite.internal.sql.engine.schema.IgniteIndex;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.apache.ignite.internal.sql.engine.trait.IgniteDistribution;
 import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions;
+import org.apache.ignite.internal.sql.engine.trait.TraitUtils;
 import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
 import org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem;
+import org.junit.jupiter.api.Test;
 
 /**
  * Base class for further planner test implementations.
  */
 public abstract class AbstractAggregatePlannerTest extends AbstractPlannerTest {
+    @Test
+    public void simpleAggregateWithSingleDistribution() throws Exception {
+        checkTestCase1("SELECT AVG(val0) FROM test", schema(single()));
+    }
+
+    @Test
+    public void simpleAggregateHashDistribution() throws Exception {
+        checkTestCase2("SELECT AVG(val0) FROM test", schema(hash()));
+    }
+
+    @Test
+    public void groupNoIndexSingleDistribution() throws Exception {
+        checkTestCase3("SELECT AVG(val0) FROM test GROUP BY grp0", schema(single()));
+        checkTestCase3("SELECT AVG(val0) FROM test GROUP BY grp1, grp0", schema(single()));
+    }
+
+    @Test
+    public void groupNoIndexHashDistribution() throws Exception {
+        checkTestCase4("SELECT AVG(val0) FROM test GROUP BY grp0", schema(hash()));
+        checkTestCase4("SELECT AVG(val0) FROM test GROUP BY grp1, grp0", schema(hash()));
+    }
+
+    @Test
+    public void groupWithIndexSingleDistribution() throws Exception {
+        checkTestCase5("SELECT AVG(val0) FROM test GROUP BY grp0", schema(single(), indexedGrp0Grp1()));
+    }
+
+    @Test
+    public void groupWithIndexCollationPermuteSingleDistribution() throws Exception {
+        checkTestCase5("SELECT AVG(val0) FROM test GROUP BY grp1, grp0", schema(single(), indexedGrp0Grp1()));
+    }
+
+    @Test
+    public void groupWithIndexHashDistribution() throws Exception {
+        checkTestCase6("SELECT AVG(val0) FROM test GROUP BY grp0", schema(hash(), indexedGrp0Grp1()));
+    }
+
+    @Test
+    public void groupWithIndexCollationPermuteHashDistribution() throws Exception {
+        checkTestCase6("SELECT AVG(val0) FROM test GROUP BY grp1, grp0", schema(hash(), indexedGrp0Grp1()));
+    }
+
+    protected void checkTestCase1(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    protected void checkTestCase2(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    protected void checkTestCase3(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    protected void checkTestCase4(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    protected void checkTestCase5(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    protected void checkTestCase6(String sql, IgniteSchema schema) throws Exception {
+        assert false;
+    }
+
+    public static IgniteSchema schema(IgniteDistribution distribution,
+            Consumer<org.apache.ignite.internal.sql.engine.framework.TestTable>... indices) {
+        org.apache.ignite.internal.sql.engine.framework.TestTable table = TestBuilders.table()
+                .name("TEST")
+                .addColumn("ID", NativeTypes.INT32)
+                .addColumn("VAL0", NativeTypes.INT32)
+                .addColumn("VAL1", NativeTypes.INT32)
+                .addColumn("GRP0", NativeTypes.INT32)
+                .addColumn("GRP1", NativeTypes.INT32)
+                .size(DEFAULT_TBL_SIZE)
+                .distribution(distribution)
+                .build();
+
+        for (Consumer<org.apache.ignite.internal.sql.engine.framework.TestTable> index : indices) {
+            index.accept(table);
+        }
+
+        IgniteSchema schema = new IgniteSchema("PUBLIC");
+        schema.addTable(table);
+
+        return schema;
+    }
+
+    private static IgniteDistribution hash() {
+        return IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID);
+    }
+
+    private static Consumer<org.apache.ignite.internal.sql.engine.framework.TestTable> indexedGrp0Grp1() {
+        return tbl -> tbl.addIndex(createIndex(tbl, "grp0_grp1", 3, 4));
+    }
+
+    private static IgniteIndex createIndex(org.apache.ignite.internal.sql.engine.framework.TestTable tbl, String grp0_grp1, int... keys) {
+        return new IgniteIndex(TestSortedIndex.create(
+                TraitUtils.createCollation(IntStream.of(keys).boxed().collect(Collectors.toList())),
+                grp0_grp1,
+                tbl
+        ));
+    }
+
     /**
      * Creates table with broadcast distribution.
      *
      * @param tblName Table name.
      * @return Table instance with broadcast distribution and multiple predefined columns.
      */
-    protected TestTable createBroadcastTable(String tblName) {
+    protected static TestTable createBroadcastTable(String tblName) {
         IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
 
         return createTable(tblName,
@@ -58,7 +176,7 @@ public abstract class AbstractAggregatePlannerTest extends AbstractPlannerTest {
                         .add("GRP1", f.createJavaType(Integer.class))
                         .build(),
                 DEFAULT_TBL_SIZE,
-                IgniteDistributions.broadcast()
+                broadcast()
         );
     }
 
@@ -68,7 +186,7 @@ public abstract class AbstractAggregatePlannerTest extends AbstractPlannerTest {
      * @param tblName Table name.
      * @return Table instance with specified affinity distribution and multiple predefined columns.
      */
-    protected AbstractPlannerTest.TestTable createAffinityTable(String tblName) {
+    protected static AbstractPlannerTest.TestTable createAffinityTable(String tblName) {
         IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
 
         return createTable(tblName,
@@ -80,7 +198,7 @@ public abstract class AbstractAggregatePlannerTest extends AbstractPlannerTest {
                         .add("GRP1", f.createJavaType(Integer.class))
                         .build(),
                 DEFAULT_TBL_SIZE,
-                IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID)
+                hash()
         );
     }
 
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 209bf79f5f..57d4195f37 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
@@ -63,6 +63,7 @@ import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
 import org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem;
 import org.apache.ignite.internal.util.ArrayUtils;
 import org.hamcrest.core.IsInstanceOf;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
@@ -73,183 +74,8 @@ import org.junit.jupiter.params.provider.MethodSource;
  * AggregatePlannerTest.
  * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
  */
+@Disabled
 public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
-    /**
-     * SingleWithoutIndex.
-     * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
-     *
-     * @throws Exception If failed.
-     */
-    @ParameterizedTest
-    @EnumSource
-    public void singleWithoutIndex(AggregateAlgorithm algo) throws Exception {
-        TestTable tbl = createBroadcastTable("TEST").addIndex("val0_val1", 1, 2);
-
-        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
-        publicSchema.addTable(tbl);
-
-        String sql = "SELECT AVG(val0) FROM test GROUP BY grp0";
-
-        IgniteRel phys = physicalPlan(
-                sql,
-                publicSchema,
-                algo.rulesToDisable
-        );
-
-        IgniteColocatedAggregateBase agg = findFirstNode(phys, byClass(algo.colocated));
-
-        assertNotNull(agg, invalidPlanErrorMessage(phys));
-
-        assertThat(
-                invalidPlanErrorMessage(phys).get(),
-                first(agg.getAggCallList()).getAggregation(),
-                IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
-
-        if (algo == AggregateAlgorithm.SORT) {
-            assertNotNull(findFirstNode(phys, byClass(IgniteSort.class)));
-        }
-    }
-
-    /**
-     * SingleWithIndex.
-     * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
-     *
-     * @throws Exception If failed.
-     */
-    @ParameterizedTest
-    @EnumSource
-    public void singleWithIndex(AggregateAlgorithm algo) throws Exception {
-        TestTable tbl = createBroadcastTable("TEST").addIndex("grp0_grp1", 3, 4);
-
-        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
-        publicSchema.addTable(tbl);
-
-        String sql = "SELECT AVG(val0) FROM test GROUP BY grp0";
-
-        IgniteRel phys = physicalPlan(
-                sql,
-                publicSchema,
-                algo.rulesToDisable
-        );
-
-        IgniteColocatedAggregateBase agg = findFirstNode(phys, byClass(algo.colocated));
-
-        assertNotNull(agg, invalidPlanErrorMessage(phys));
-
-        assertThat(invalidPlanErrorMessage(phys).get(),
-                first(agg.getAggCallList()).getAggregation(),
-                IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
-
-        if (algo == AggregateAlgorithm.SORT) {
-            assertNotNull(findFirstNode(phys, byClass(IgniteIndexScan.class)));
-        }
-    }
-
-    @ParameterizedTest
-    @EnumSource(AggregateAlgorithm.class)
-    public void colocated(AggregateAlgorithm algo) throws Exception {
-        IgniteSchema schema = createSchema(
-                createTable(
-                        "EMP", IgniteDistributions.affinity(1, UUID.randomUUID(), DEFAULT_ZONE_ID),
-                        "EMPID", Integer.class,
-                        "DEPTID", Integer.class,
-                        "NAME", String.class,
-                        "SALARY", Integer.class
-                ).addIndex("DEPTID", 1),
-                createTable(
-                        "DEPT", IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID),
-                        "DEPTID", Integer.class,
-                        "NAME", String.class
-                ).addIndex("DEPTID", 0)
-        );
-
-        String sql = "SELECT SUM(SALARY) FROM emp GROUP BY deptid";
-
-        assertPlan(sql, schema, hasChildThat(isInstanceOf(algo.colocated)
-                        .and(hasDistribution(IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID)))),
-                algo.rulesToDisable);
-
-        sql = "SELECT dept.deptid, agg.cnt "
-                + "FROM dept "
-                + "JOIN (SELECT deptid, COUNT(*) AS cnt FROM emp GROUP BY deptid) AS agg ON dept.deptid = agg.deptid";
-
-        assertPlan(sql, schema, hasChildThat(isInstanceOf(Join.class)
-                        .and(input(0, hasDistribution(IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID))))
-                        .and(input(1, hasDistribution(IgniteDistributions.affinity(0, UUID.randomUUID(), DEFAULT_ZONE_ID))))),
-                algo.rulesToDisable);
-    }
-
-    /**
-     * Test that aggregate has single distribution output even if parent node accept random distribution inputs.
-     *
-     * @throws Exception If failed.
-     */
-    @ParameterizedTest
-    @EnumSource
-    public void distribution(AggregateAlgorithm algo) throws Exception {
-        TestTable tbl = createAffinityTable("TEST").addIndex("grp0", 3);
-
-        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
-        publicSchema.addTable(tbl);
-
-        String sql = "SELECT AVG(val0), grp0 FROM test GROUP BY grp0 UNION ALL SELECT val0, grp0 FROM test";
-
-        IgniteRel phys = physicalPlan(
-                sql,
-                publicSchema,
-                concat(algo.rulesToDisable, "MapReduceSortAggregateConverterRule",
-                        "MapReduceHashAggregateConverterRule")
-        );
-
-        IgniteColocatedAggregateBase singleAgg = findFirstNode(phys, byClass(algo.colocated));
-
-        assertEquals(IgniteDistributions.single(), TraitUtils.distribution(singleAgg));
-
-        phys = physicalPlan(
-                sql,
-                publicSchema,
-                concat(algo.rulesToDisable)
-        );
-
-        IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
-
-        assertEquals(IgniteDistributions.single(), TraitUtils.distribution(rdcAgg));
-    }
-
-    /**
-     * CollationPermuteSingle.
-     * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
-     *
-     * @throws Exception If failed.
-     */
-    @Test
-    public void collationPermuteSingle() throws Exception {
-        TestTable tbl = createAffinityTable("TEST").addIndex("grp0_1", 3, 4);
-
-        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
-        publicSchema.addTable(tbl);
-
-        String sql = "SELECT MIN(val0) FROM test GROUP BY grp1, grp0";
-
-        IgniteRel phys = physicalPlan(
-                sql,
-                publicSchema,
-                AggregateAlgorithm.SORT.rulesToDisable
-        );
-
-        IgniteColocatedSortAggregate agg = findFirstNode(phys, byClass(IgniteColocatedSortAggregate.class));
-
-        assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
-
-        assertNull(
-                findFirstNode(phys, byClass(IgniteSort.class)),
-                "Invalid plan\n" + RelOptUtil.toString(phys)
-        );
-    }
 
     /**
      * ExpandDistinctAggregates.
@@ -327,7 +153,7 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
 
         publicSchema.addTable(tbl);
 
-        String sql = "SELECT AVG(val0) FILTER (WHERE val1 > 10) FROM test GROUP BY grp1, grp0";
+        String sql = "SELECT AVG(val0) FROM test GROUP BY grp1, grp0";
 
         IgniteRel phys = physicalPlan(
                 sql,
@@ -480,6 +306,7 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
         assertPlan("SELECT (SELECT test.a FROM test t ORDER BY 1 LIMIT 1) FROM test", publicSchema,
                 hasChildThat(isInstanceOf(IgniteCorrelatedNestedLoopJoin.class)
                         .and(input(1, hasChildThat(isInstanceOf(IgniteLimit.class)
+                                //TODO: check aggregate here
                                 .and(input(isInstanceOf(IgniteSort.class)))))))
         );
     }
@@ -593,7 +420,8 @@ public class AggregatePlannerTest extends AbstractAggregatePlannerTest {
      */
     @ParameterizedTest
     @EnumSource
-    public void subqueryWithAggregate(AggregateAlgorithm algo) throws Exception {
+    public void subqueryWithAggregate(AggregateAlgorithm algo, IgniteSchema schema) throws Exception {
+
         IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
 
         IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
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
new file mode 100644
index 0000000000..e9f3e90068
--- /dev/null
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedHashAggregatePlannerTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.planner;
+
+import static org.apache.ignite.internal.util.CollectionUtils.first;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.calcite.sql.fun.SqlAvgAggFunction;
+import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
+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.agg.IgniteColocatedAggregateBase;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteColocatedHashAggregate;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.hamcrest.core.IsInstanceOf;
+
+/**
+ * AggregatePlannerTest.
+ * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ */
+public class ColocatedHashAggregatePlannerTest extends AbstractAggregatePlannerTest {
+
+    private final String[] disableRules = {
+            "MapReduceHashAggregateConverterRule",
+            "MapReduceSortAggregateConverterRule",
+            "ColocatedSortAggregateConverterRule"
+    };
+
+    @Override
+    protected void checkTestCase1(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isTableScan("TEST")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase2(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase3(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isTableScan("TEST")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase4(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
+                        ))),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase5(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isTableScan("TEST")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase6(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedHashAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
+                        ))),
+                disableRules
+        );
+    }
+}
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedSortAggregatePlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedSortAggregatePlannerTest.java
new file mode 100644
index 0000000000..a3f059a5e1
--- /dev/null
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/ColocatedSortAggregatePlannerTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.planner;
+
+import static org.apache.ignite.internal.util.CollectionUtils.first;
+
+import org.apache.calcite.sql.fun.SqlAvgAggFunction;
+import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
+import org.apache.ignite.internal.sql.engine.rel.IgniteSort;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteColocatedSortAggregate;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+
+/**
+ * AggregatePlannerTest.
+ * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ */
+public class ColocatedSortAggregatePlannerTest extends AbstractAggregatePlannerTest {
+    private final String[] disableRules = {
+            "MapReduceHashAggregateConverterRule",
+            "MapReduceSortAggregateConverterRule",
+            "ColocatedHashAggregateConverterRule"
+    };
+
+    @Override
+    protected void checkTestCase1(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(hasChildThat(isTableScan("TEST")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase2(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase3(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(hasChildThat(isTableScan("TEST")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase4(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isInstanceOf(IgniteSort.class)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase5(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(hasChildThat(isIndexScan("TEST", "grp0_grp1")))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase6(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteColocatedSortAggregate.class)
+                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isIndexScan("TEST", "grp0_grp1")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+}
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
new file mode 100644
index 0000000000..d651b66ca6
--- /dev/null
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceHashAggregatePlannerTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.planner;
+
+import static org.apache.ignite.internal.util.CollectionUtils.first;
+
+import org.apache.calcite.sql.fun.SqlAvgAggFunction;
+import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+
+/**
+ * AggregatePlannerTest.
+ * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ */
+public class MapReduceHashAggregatePlannerTest extends AbstractAggregatePlannerTest {
+    private final String[] disableRules = {
+            "MapReduceSortAggregateConverterRule",
+            "ColocatedHashAggregateConverterRule",
+            "ColocatedSortAggregateConverterRule"
+    };
+
+    @Override
+    protected void checkTestCase1(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(
+                sql,
+                schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase2(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(
+                sql,
+                schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase3(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(
+                sql,
+                schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase4(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase5(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase6(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceHashAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isInstanceOf(IgniteMapHashAggregate.class)
+                                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                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
new file mode 100644
index 0000000000..c69f007900
--- /dev/null
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/MapReduceSortAggregatePlannerTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.planner;
+
+import static org.apache.ignite.internal.util.CollectionUtils.first;
+
+import org.apache.calcite.sql.fun.SqlAvgAggFunction;
+import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
+import org.apache.ignite.internal.sql.engine.rel.IgniteSort;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate;
+import org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate;
+import org.apache.ignite.internal.sql.engine.schema.IgniteSchema;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+/**
+ * AggregatePlannerTest.
+ * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ */
+public class MapReduceSortAggregatePlannerTest extends AbstractAggregatePlannerTest {
+    private final String[] disableRules = {
+            "MapReduceHashAggregateConverterRule",
+            "ColocatedHashAggregateConverterRule",
+            "ColocatedSortAggregateConverterRule"
+    };
+
+    @Test
+    @Disabled
+    @Override
+    public void groupWithIndexCollationPermuteHashDistribution() throws Exception {
+        super.groupWithIndexCollationPermuteHashDistribution();
+    }
+
+    @Override
+    protected void checkTestCase1(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isTableScan("TEST")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase2(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                        .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase3(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isInstanceOf(IgniteSort.class)
+                                        .and(input(isTableScan("TEST")))
+                                ))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase4(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                                .and(input(isInstanceOf(IgniteSort.class)
+                                                        .and(input(isTableScan("TEST")))
+                                                ))
+                                        ))
+                                )
+                        )),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase5(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                .and(input(isIndexScan("TEST", "grp0_grp1")))
+                        ))
+                ),
+                disableRules
+        );
+    }
+
+    @Override
+    protected void checkTestCase6(String sql, IgniteSchema schema) throws Exception {
+        assertPlan(sql, schema,
+                nodeOrAnyChild(isInstanceOf(IgniteReduceSortAggregate.class)
+                        .and(input(isInstanceOf(IgniteExchange.class)
+                                        .and(input(isInstanceOf(IgniteMapSortAggregate.class)
+                                                .and(n -> first(n.getAggCallList()).getAggregation() instanceof SqlAvgAggFunction)
+                                                .and(input(isIndexScan("TEST", "grp0_grp1")))
+                                        ))
+                                )
+                        )),
+                disableRules
+        );
+    }
+}