Search in sources :

Example 1 with IgniteReduceAggregateBase

use of org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase in project ignite-3 by apache.

the class AggregatePlannerTest method distribution.

/**
 * Test that aggregate has single distribution output even if parent node accept random distibution inputs.
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void distribution(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(3)), "grp0");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", 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, "SortMapReduceAggregateConverterRule", "HashMapReduceAggregateConverterRule"));
    IgniteSingleAggregateBase singleAgg = findFirstNode(phys, byClass(algo.single));
    assertEquals(IgniteDistributions.single(), TraitUtils.distribution(singleAgg));
    phys = physicalPlan(sql, publicSchema, concat(algo.rulesToDisable, "SortSingleAggregateConverterRule", "HashSingleAggregateConverterRule"));
    IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
    assertEquals(IgniteDistributions.single(), TraitUtils.distribution(rdcAgg));
}
Also used : IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with IgniteReduceAggregateBase

use of org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase in project ignite-3 by apache.

the class AggregatePlannerTest method mapReduceGroupBy.

/**
 * MapReduceGroupBy.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void mapReduceGroupBy(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable();
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT AVG(val0) FILTER (WHERE val1 > 10) FROM test GROUP BY grp1, grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    IgniteMapAggregateBase mapAgg = findFirstNode(phys, byClass(algo.map));
    IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
    assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(rdcAgg.getAggregateCalls()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
    assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(mapAgg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
    if (algo == AggregateAlgorithm.SORT) {
        assertNotNull(findFirstNode(phys, byClass(IgniteSort.class)));
    }
}
Also used : SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteMapAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapAggregateBase) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with IgniteReduceAggregateBase

use of org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase in project ignite-3 by apache.

the class AggregateDistinctPlannerTest method mapReduceDistinctWithIndex.

/**
 * MapReduceDistinctWithIndex.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void mapReduceDistinctWithIndex(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "val0_val1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT DISTINCT val0, val1 FROM test";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    IgniteAggregate mapAgg = findFirstNode(phys, byClass(algo.map));
    IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
    assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertTrue(nullOrEmpty(rdcAgg.getAggregateCalls()), "Invalid plan\n" + RelOptUtil.toString(phys));
    assertTrue(nullOrEmpty(mapAgg.getAggCallList()), "Invalid plan\n" + RelOptUtil.toString(phys));
    if (algo == AggregateAlgorithm.SORT) {
        assertNotNull(findFirstNode(phys, byClass(IgniteIndexScan.class)));
    }
}
Also used : IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with IgniteReduceAggregateBase

use of org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase in project ignite-3 by apache.

the class AggregatePlannerTest method expandDistinctAggregates.

/**
 * ExpandDistinctAggregates.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void expandDistinctAggregates(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(3, 1, 0)), "idx_val0").addIndex(RelCollations.of(ImmutableIntList.of(3, 2, 0)), "idx_val1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT " + "/*+ EXPAND_DISTINCT_AGG */ " + "SUM(DISTINCT val0), AVG(DISTINCT val1) FROM test GROUP BY grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    // Plan must not contain distinct accumulators.
    assertFalse(findNodes(phys, byClass(IgniteAggregate.class)).stream().anyMatch(n -> ((Aggregate) n).getAggCallList().stream().anyMatch(AggregateCall::isDistinct)), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertNotNull(findFirstNode(phys, byClass(Join.class)), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    // Check the first aggrgation step is SELECT DISTINCT (doesn't contains any accumulators)
    assertTrue(findNodes(phys, byClass(algo.reduce)).stream().allMatch(n -> ((IgniteReduceAggregateBase) n).getAggregateCalls().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertTrue(findNodes(phys, byClass(algo.map)).stream().allMatch(n -> ((Aggregate) n).getAggCallList().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    // Check the second aggrgation step contains accumulators.
    assertTrue(findNodes(phys, byClass(algo.single)).stream().noneMatch(n -> ((Aggregate) n).getAggCallList().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) EnumSource(org.junit.jupiter.params.provider.EnumSource) SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Join(org.apache.calcite.rel.core.Join) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IgniteMapAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapAggregateBase) IgniteReduceSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArrayUtils.concat(org.apache.ignite.internal.util.ArrayUtils.concat) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IsInstanceOf(org.hamcrest.core.IsInstanceOf) RelCollations(org.apache.calcite.rel.RelCollations) IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) SqlExplainLevel(org.apache.calcite.sql.SqlExplainLevel) Aggregate(org.apache.calcite.rel.core.Aggregate) IgniteMapSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) TraitUtils(org.apache.ignite.internal.sql.engine.trait.TraitUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) CollectionUtils.first(org.apache.ignite.internal.util.CollectionUtils.first) IgniteSingleHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleHashAggregate) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteReduceSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate) Aggregate(org.apache.calcite.rel.core.Aggregate) IgniteMapSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) IgniteSingleHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleHashAggregate) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)4 IgniteReduceAggregateBase (org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase)4 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 SqlAvgAggFunction (org.apache.calcite.sql.fun.SqlAvgAggFunction)2 IgniteAggregate (org.apache.ignite.internal.sql.engine.rel.IgniteAggregate)2 IgniteMapAggregateBase (org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapAggregateBase)2 IgniteSingleAggregateBase (org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase)2 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelCollations (org.apache.calcite.rel.RelCollations)1 Aggregate (org.apache.calcite.rel.core.Aggregate)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 Join (org.apache.calcite.rel.core.Join)1 SqlExplainLevel (org.apache.calcite.sql.SqlExplainLevel)1 ImmutableIntList (org.apache.calcite.util.ImmutableIntList)1 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)1 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)1 IgniteMapHashAggregate (org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate)1 IgniteMapSortAggregate (org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate)1