Search in sources :

Example 1 with DingoAggregate

use of io.dingodb.calcite.rel.DingoAggregate in project dingo by dingodb.

the class DingoAggregateRule method onMatch.

@Override
public void onMatch(@Nonnull RelOptRuleCall call) {
    Aggregate rel = call.rel(0);
    // AVG must be transformed to SUM/COUNT before.
    if (rel.getAggCallList().stream().anyMatch(agg -> agg.getAggregation().getKind() == SqlKind.AVG)) {
        return;
    }
    RelOptCluster cluster = rel.getCluster();
    TupleMapping keyMapping = getAggKeys(rel);
    List<Agg> aggList = getAggList(rel);
    call.transformTo(new DingoReduce(cluster, rel.getTraitSet().replace(DingoConventions.ROOT), new DingoExchange(cluster, rel.getTraitSet().replace(DingoConventions.PARTITIONED), new DingoAggregate(cluster, rel.getTraitSet().replace(DingoConventions.DISTRIBUTED), convert(rel.getInput(), DingoConventions.DISTRIBUTED), keyMapping, aggList, rel.getRowType())), keyMapping, aggList));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Agg(io.dingodb.exec.aggregate.Agg) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) DingoReduce(io.dingodb.calcite.rel.DingoReduce) Aggregate(org.apache.calcite.rel.core.Aggregate) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) TupleMapping(io.dingodb.common.table.TupleMapping) DingoExchange(io.dingodb.calcite.rel.DingoExchange)

Example 2 with DingoAggregate

use of io.dingodb.calcite.rel.DingoAggregate in project dingo by dingodb.

the class TestPhysicalPlan method testAvg2.

@Test
public void testAvg2() throws SqlParseException {
    String sql = "select name, avg(id), avg(amount) from test group by name";
    RelNode relNode = parse(sql);
    AssertRelNode assertAgg = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput().isA(DingoProject.class).convention(DingoConventions.ROOT).singleInput().isA(DingoReduce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoAggregate.class).convention(DingoConventions.DISTRIBUTED);
    DingoAggregate agg = (DingoAggregate) assertAgg.getInstance();
    assertThat(agg.getAggList()).map(Object::getClass).map(Class::getSimpleName).contains("SumAgg", "CountAgg");
    assertAgg.singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) EnumerableRoot(io.dingodb.calcite.rel.EnumerableRoot) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) DingoReduce(io.dingodb.calcite.rel.DingoReduce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Example 3 with DingoAggregate

use of io.dingodb.calcite.rel.DingoAggregate in project dingo by dingodb.

the class TestPhysicalPlan method testAvg1.

@Test
public void testAvg1() throws SqlParseException {
    String sql = "select name, avg(amount) from test group by name";
    RelNode relNode = parse(sql);
    AssertRelNode assertAgg = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput().isA(DingoProject.class).convention(DingoConventions.ROOT).singleInput().isA(DingoReduce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoAggregate.class).convention(DingoConventions.DISTRIBUTED);
    DingoAggregate agg = (DingoAggregate) assertAgg.getInstance();
    assertThat(agg.getAggList()).map(Object::getClass).map(Class::getSimpleName).contains("SumAgg", "CountAgg");
    assertAgg.singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) EnumerableRoot(io.dingodb.calcite.rel.EnumerableRoot) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) DingoReduce(io.dingodb.calcite.rel.DingoReduce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Example 4 with DingoAggregate

use of io.dingodb.calcite.rel.DingoAggregate in project dingo by dingodb.

the class TestPhysicalPlan method testAvg.

@Test
public void testAvg() throws SqlParseException {
    String sql = "select avg(amount) from test";
    RelNode relNode = parse(sql);
    AssertRelNode assertAgg = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput().isA(DingoProject.class).convention(DingoConventions.ROOT).singleInput().isA(DingoReduce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoAggregate.class).convention(DingoConventions.DISTRIBUTED);
    DingoAggregate agg = (DingoAggregate) assertAgg.getInstance();
    assertThat(agg.getAggList()).map(Object::getClass).map(Class::getSimpleName).contains("SumAgg", "CountAgg");
    assertAgg.singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) EnumerableRoot(io.dingodb.calcite.rel.EnumerableRoot) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) DingoReduce(io.dingodb.calcite.rel.DingoReduce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Aggregations

DingoAggregate (io.dingodb.calcite.rel.DingoAggregate)4 DingoReduce (io.dingodb.calcite.rel.DingoReduce)4 AssertRelNode (io.dingodb.calcite.assertion.AssertRelNode)3 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)3 EnumerableRoot (io.dingodb.calcite.rel.EnumerableRoot)3 RelNode (org.apache.calcite.rel.RelNode)3 Test (org.junit.jupiter.api.Test)3 DingoExchange (io.dingodb.calcite.rel.DingoExchange)1 TupleMapping (io.dingodb.common.table.TupleMapping)1 Agg (io.dingodb.exec.aggregate.Agg)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 Aggregate (org.apache.calcite.rel.core.Aggregate)1