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));
}
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)));
}
}
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)));
}
}
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));
}
Aggregations