Search in sources :

Example 1 with Job

use of io.dingodb.exec.base.Job in project dingo by dingodb.

the class DingoResultSet method getIterator.

Iterator<Object[]> getIterator() {
    if (iterator == null) {
        DingoSignature dingoSignature = (DingoSignature) signature;
        Job job = dingoSignature.getJob();
        Enumerator<Object[]> enumerator = new JobRunner(job).createEnumerator();
        iterator = Linq4j.enumeratorIterator(enumerator);
        try {
            setFetchSize(1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return iterator;
}
Also used : JobRunner(io.dingodb.calcite.JobRunner) SQLException(java.sql.SQLException) Job(io.dingodb.exec.base.Job)

Example 2 with Job

use of io.dingodb.exec.base.Job in project dingo by dingodb.

the class DingoJobVisitor method createJob.

@Nonnull
public static Job createJob(RelNode input, boolean addRoot) {
    IdGenerator idGenerator = new IdGenerator();
    DingoJobVisitor visitor = new DingoJobVisitor(idGenerator);
    Collection<Output> outputs = dingo(input).accept(visitor);
    if (addRoot) {
        if (outputs.size() == 1) {
            Output output = sole(outputs);
            Task task = output.getTask();
            RootOperator root = new RootOperator(TupleSchema.fromRelDataType(input.getRowType()));
            root.setId(idGenerator.get());
            task.putOperator(root);
            output.setLink(root.getInput(0));
        } else if (!outputs.isEmpty()) {
            throw new IllegalStateException("There must be zero or one output to job root.");
        }
    }
    Job job = visitor.getJob();
    log.info("job = {}", job);
    return job;
}
Also used : Task(io.dingodb.exec.base.Task) Output(io.dingodb.exec.base.Output) RootOperator(io.dingodb.exec.operator.RootOperator) IdGenerator(io.dingodb.exec.base.IdGenerator) Job(io.dingodb.exec.base.Job) Nonnull(javax.annotation.Nonnull)

Example 3 with Job

use of io.dingodb.exec.base.Job in project dingo by dingodb.

the class TestDingoJobVisitor method testVisitPartModify.

@Test
public void testVisitPartModify() {
    RelOptCluster cluster = parser.getCluster();
    DingoPartModify partModify = new DingoPartModify(cluster, cluster.traitSetOf(DingoConventions.DISTRIBUTED), distributedValues, table, TableModify.Operation.INSERT, null, null);
    Job job = DingoJobVisitor.createJob(partModify);
    Assert.job(job).taskNum(2).task(0, t -> t.location(MockMetaServiceProvider.LOC_0).operatorNum(2).soleSource().isA(ValuesOperator.class).soleOutput().isA(PartModifyOperator.class)).task(1, t -> t.location(MockMetaServiceProvider.LOC_1).operatorNum(2).soleSource().isA(ValuesOperator.class).soleOutput().isA(PartModifyOperator.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) DingoPartModify(io.dingodb.calcite.rel.DingoPartModify) Job(io.dingodb.exec.base.Job) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) PartModifyOperator(io.dingodb.exec.operator.PartModifyOperator) Test(org.junit.jupiter.api.Test)

Example 4 with Job

use of io.dingodb.exec.base.Job in project dingo by dingodb.

the class TestDingoJobVisitor method testVisitValues.

@Test
public void testVisitValues() {
    Job job = DingoJobVisitor.createJob(values);
    ValuesOperator operator = (ValuesOperator) Assert.job(job).soleTask().location(MockMetaServiceProvider.LOC_0).operatorNum(1).soleSource().isA(ValuesOperator.class).getInstance();
    List<Object[]> tuples = operator.getTuples();
    assertThat(tuples).element(0).satisfies(obj -> {
        assertThat(obj[0]).isEqualTo(BigDecimal.valueOf(1));
        assertThat(obj[1]).isEqualTo("Alice");
        assertThat(obj[2]).isEqualTo(BigDecimal.valueOf(1));
    });
}
Also used : Job(io.dingodb.exec.base.Job) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) Test(org.junit.jupiter.api.Test)

Example 5 with Job

use of io.dingodb.exec.base.Job in project dingo by dingodb.

the class JobRunner method run.

@SuppressWarnings("unused")
@Nonnull
public static Enumerable<Object[]> run(String serializedJob) {
    try {
        final Job job = JobImpl.fromString(serializedJob);
        final JobRunner runner = new JobRunner(job);
        return new AbstractEnumerable<Object[]>() {

            @Override
            public Enumerator<Object[]> enumerator() {
                return runner.createEnumerator();
            }
        };
    } catch (JsonProcessingException e) {
        throw new RuntimeException("Cannot deserialize job.", e);
    }
}
Also used : AbstractEnumerable(org.apache.calcite.linq4j.AbstractEnumerable) Job(io.dingodb.exec.base.Job) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Nonnull(javax.annotation.Nonnull)

Aggregations

Job (io.dingodb.exec.base.Job)11 ImmutableList (com.google.common.collect.ImmutableList)5 ValuesOperator (io.dingodb.exec.operator.ValuesOperator)5 List (java.util.List)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 Test (org.junit.jupiter.api.Test)5 DingoConventions (io.dingodb.calcite.DingoConventions)4 DingoParser (io.dingodb.calcite.DingoParser)4 DingoParserContext (io.dingodb.calcite.DingoParserContext)4 Assert (io.dingodb.calcite.assertion.Assert)4 MockMetaServiceProvider (io.dingodb.calcite.mock.MockMetaServiceProvider)4 DingoCoalesce (io.dingodb.calcite.rel.DingoCoalesce)4 DingoDistributedValues (io.dingodb.calcite.rel.DingoDistributedValues)4 DingoExchange (io.dingodb.calcite.rel.DingoExchange)4 DingoPartModify (io.dingodb.calcite.rel.DingoPartModify)4 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)4 DingoValues (io.dingodb.calcite.rel.DingoValues)4 TableId (io.dingodb.common.table.TableId)4 CoalesceOperator (io.dingodb.exec.operator.CoalesceOperator)4 PartModifyOperator (io.dingodb.exec.operator.PartModifyOperator)4