Search in sources :

Example 1 with RootOperator

use of io.dingodb.exec.operator.RootOperator 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 2 with RootOperator

use of io.dingodb.exec.operator.RootOperator in project dingo by dingodb.

the class TestTaskImpl method testValues.

@Test
public void testValues() {
    Task task = new TaskImpl("", Mockito.mock(Location.class));
    ValuesOperator values = new ValuesOperator(ImmutableList.of(new Object[] { 1, "Alice", 1.0 }, new Object[] { 2, "Betty", 2.0 }));
    values.setId(idGenerator.get());
    task.putOperator(values);
    RootOperator root = new RootOperator(TupleSchema.ofTypes("INTEGER", "STRING", "DOUBLE"));
    root.setId(idGenerator.get());
    task.putOperator(root);
    values.getOutputs().get(0).setLink(root.getInput(0));
    task.init();
    task.run();
    assertThat(root.popValue()).containsExactly(1, "Alice", 1.0);
    task.run();
    assertThat(root.popValue()).containsExactly(2, "Betty", 2.0);
}
Also used : Task(io.dingodb.exec.base.Task) RootOperator(io.dingodb.exec.operator.RootOperator) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) Location(io.dingodb.meta.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Task (io.dingodb.exec.base.Task)2 RootOperator (io.dingodb.exec.operator.RootOperator)2 IdGenerator (io.dingodb.exec.base.IdGenerator)1 Job (io.dingodb.exec.base.Job)1 Output (io.dingodb.exec.base.Output)1 ValuesOperator (io.dingodb.exec.operator.ValuesOperator)1 Location (io.dingodb.meta.Location)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.jupiter.api.Test)1