Search in sources :

Example 1 with DingoExchange

use of io.dingodb.calcite.rel.DingoExchange 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 DingoExchange

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

the class DingoExchangeRule method onMatch.

@Override
public void onMatch(@Nonnull RelOptRuleCall call) {
    RelNode rel = call.rel(0);
    RelOptCluster cluster = rel.getCluster();
    call.transformTo(new DingoExchange(cluster, cluster.traitSetOf(DingoConventions.PARTITIONED), rel));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelNode(org.apache.calcite.rel.RelNode) DingoExchange(io.dingodb.calcite.rel.DingoExchange)

Example 3 with DingoExchange

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

the class DingoPartModifyRule method onMatch.

@Override
public void onMatch(@Nonnull RelOptRuleCall call) {
    DingoTableModify rel = call.rel(0);
    RelNode input = rel.getInput();
    RelNode convertedInput = null;
    RelOptCluster cluster = rel.getCluster();
    switch(rel.getOperation()) {
        case INSERT:
            convertedInput = new DingoExchange(cluster, rel.getTraitSet().replace(DingoConventions.DISTRIBUTED), new DingoPartition(cluster, rel.getTraitSet().replace(DingoConventions.DISTRIBUTED), convert(input, DingoConventions.DISTRIBUTED), rel.getTable()));
            break;
        case UPDATE:
            // Only support update in part.
            checkUpdateInPart(rel);
            convertedInput = convert(input, DingoConventions.DISTRIBUTED);
            break;
        case DELETE:
            convertedInput = convert(input, DingoConventions.DISTRIBUTED);
            break;
        default:
            throw new IllegalStateException("Operation \"" + rel.getOperation() + "\" is not supported.");
    }
    call.transformTo(new DingoPartModify(cluster, rel.getTraitSet().replace(DingoConventions.DISTRIBUTED), convertedInput, rel.getTable(), rel.getOperation(), rel.getUpdateColumnList(), rel.getSourceExpressionList()));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelNode(org.apache.calcite.rel.RelNode) DingoPartModify(io.dingodb.calcite.rel.DingoPartModify) DingoTableModify(io.dingodb.calcite.rel.DingoTableModify) DingoPartition(io.dingodb.calcite.rel.DingoPartition) DingoExchange(io.dingodb.calcite.rel.DingoExchange)

Example 4 with DingoExchange

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

the class TestDingoJobVisitor method testVisitExchange.

@Test
public void testVisitExchange() {
    RelOptCluster cluster = parser.getCluster();
    DingoExchange exchange = new DingoExchange(cluster, cluster.traitSetOf(DingoConventions.PARTITIONED), new DingoPartScan(cluster, cluster.traitSetOf(DingoConventions.DISTRIBUTED), table));
    Job job = DingoJobVisitor.createJob(exchange);
    Assert.job(job).taskNum(2).task(0, t -> t.operatorNum(2).location(MockMetaServiceProvider.LOC_0).sourceNum(2).source(0, s -> s.isPartScan(TABLE_ID, "0").soleOutput().isNull()).source(1, s -> s.isA(ReceiveOperator.class).soleOutput().isNull())).task(1, t -> t.operatorNum(2).location(MockMetaServiceProvider.LOC_1).soleSource().isPartScan(TABLE_ID, "1").soleOutput().isA(SendOperator.class));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) DingoExchange(io.dingodb.calcite.rel.DingoExchange) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) DingoParserContext(io.dingodb.calcite.DingoParserContext) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert(io.dingodb.calcite.assertion.Assert) DingoDistributedValues(io.dingodb.calcite.rel.DingoDistributedValues) RelOptTable(org.apache.calcite.plan.RelOptTable) Job(io.dingodb.exec.base.Job) BigDecimal(java.math.BigDecimal) DingoConventions(io.dingodb.calcite.DingoConventions) DingoPartModify(io.dingodb.calcite.rel.DingoPartModify) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) DingoCoalesce(io.dingodb.calcite.rel.DingoCoalesce) MockMetaServiceProvider(io.dingodb.calcite.mock.MockMetaServiceProvider) TableModify(org.apache.calcite.rel.core.TableModify) PartModifyOperator(io.dingodb.exec.operator.PartModifyOperator) RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) TableId(io.dingodb.common.table.TableId) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) DingoParser(io.dingodb.calcite.DingoParser) SendOperator(io.dingodb.exec.operator.SendOperator) List(java.util.List) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) DingoValues(io.dingodb.calcite.rel.DingoValues) CoalesceOperator(io.dingodb.exec.operator.CoalesceOperator) ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) Job(io.dingodb.exec.base.Job) SendOperator(io.dingodb.exec.operator.SendOperator) DingoExchange(io.dingodb.calcite.rel.DingoExchange) Test(org.junit.jupiter.api.Test)

Example 5 with DingoExchange

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

the class TestDingoJobVisitor method testVisitCoalesce.

@Test
public void testVisitCoalesce() {
    RelOptCluster cluster = parser.getCluster();
    DingoCoalesce coalesce = new DingoCoalesce(cluster, cluster.traitSetOf(DingoConventions.ROOT), new DingoExchange(cluster, cluster.traitSetOf(DingoConventions.PARTITIONED), new DingoPartScan(cluster, cluster.traitSetOf(DingoConventions.DISTRIBUTED), table)));
    Job job = DingoJobVisitor.createJob(coalesce);
    Assert.job(job).taskNum(2).task(0, t -> t.operatorNum(3).location(MockMetaServiceProvider.LOC_0).sourceNum(2).source(0, s -> s.isPartScan(TABLE_ID, "0").soleOutput().isA(CoalesceOperator.class)).source(1, s -> s.isA(ReceiveOperator.class).soleOutput().isA(CoalesceOperator.class))).task(1, t -> t.operatorNum(2).location(MockMetaServiceProvider.LOC_1).soleSource().isPartScan(TABLE_ID, "1").soleOutput().isA(SendOperator.class));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) DingoExchange(io.dingodb.calcite.rel.DingoExchange) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) DingoParserContext(io.dingodb.calcite.DingoParserContext) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert(io.dingodb.calcite.assertion.Assert) DingoDistributedValues(io.dingodb.calcite.rel.DingoDistributedValues) RelOptTable(org.apache.calcite.plan.RelOptTable) Job(io.dingodb.exec.base.Job) BigDecimal(java.math.BigDecimal) DingoConventions(io.dingodb.calcite.DingoConventions) DingoPartModify(io.dingodb.calcite.rel.DingoPartModify) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) DingoCoalesce(io.dingodb.calcite.rel.DingoCoalesce) MockMetaServiceProvider(io.dingodb.calcite.mock.MockMetaServiceProvider) TableModify(org.apache.calcite.rel.core.TableModify) PartModifyOperator(io.dingodb.exec.operator.PartModifyOperator) RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) TableId(io.dingodb.common.table.TableId) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) DingoParser(io.dingodb.calcite.DingoParser) SendOperator(io.dingodb.exec.operator.SendOperator) List(java.util.List) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) DingoValues(io.dingodb.calcite.rel.DingoValues) CoalesceOperator(io.dingodb.exec.operator.CoalesceOperator) ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) CoalesceOperator(io.dingodb.exec.operator.CoalesceOperator) DingoCoalesce(io.dingodb.calcite.rel.DingoCoalesce) Job(io.dingodb.exec.base.Job) SendOperator(io.dingodb.exec.operator.SendOperator) DingoExchange(io.dingodb.calcite.rel.DingoExchange) Test(org.junit.jupiter.api.Test)

Aggregations

DingoExchange (io.dingodb.calcite.rel.DingoExchange)5 RelOptCluster (org.apache.calcite.plan.RelOptCluster)5 DingoPartModify (io.dingodb.calcite.rel.DingoPartModify)3 ImmutableList (com.google.common.collect.ImmutableList)2 DingoConventions (io.dingodb.calcite.DingoConventions)2 DingoParser (io.dingodb.calcite.DingoParser)2 DingoParserContext (io.dingodb.calcite.DingoParserContext)2 Assert (io.dingodb.calcite.assertion.Assert)2 MockMetaServiceProvider (io.dingodb.calcite.mock.MockMetaServiceProvider)2 DingoCoalesce (io.dingodb.calcite.rel.DingoCoalesce)2 DingoDistributedValues (io.dingodb.calcite.rel.DingoDistributedValues)2 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)2 DingoValues (io.dingodb.calcite.rel.DingoValues)2 TableId (io.dingodb.common.table.TableId)2 Job (io.dingodb.exec.base.Job)2 CoalesceOperator (io.dingodb.exec.operator.CoalesceOperator)2 PartModifyOperator (io.dingodb.exec.operator.PartModifyOperator)2 ReceiveOperator (io.dingodb.exec.operator.ReceiveOperator)2 SendOperator (io.dingodb.exec.operator.SendOperator)2 ValuesOperator (io.dingodb.exec.operator.ValuesOperator)2