Search in sources :

Example 1 with ValuesOperator

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

the class DingoJobVisitor method visit.

@Override
public Collection<Output> visit(@Nonnull DingoDistributedValues rel) {
    List<Output> outputs = new LinkedList<>();
    String tableName = getSimpleName(rel.getTable());
    final Map<String, Location> partLocations = Services.META.getPartLocations(tableName);
    final PartitionStrategy ps = new SimpleHashStrategy(partLocations.size());
    final TableDefinition td = Services.META.getTableDefinition(tableName);
    Map<String, List<Object[]>> partMap = ps.partTuples(rel.getValues(), td.getKeyMapping());
    for (Map.Entry<String, List<Object[]>> entry : partMap.entrySet()) {
        Object partId = entry.getKey();
        ValuesOperator operator = new ValuesOperator(entry.getValue());
        operator.setId(idGenerator.get());
        OutputHint hint = new OutputHint();
        hint.setPartId(partId);
        Location location = partLocations.get(partId);
        hint.setLocation(location);
        operator.getSoleOutput().setHint(hint);
        Task task = job.getOrCreate(location);
        task.putOperator(operator);
        outputs.addAll(operator.getOutputs());
    }
    return outputs;
}
Also used : Task(io.dingodb.exec.base.Task) LinkedList(java.util.LinkedList) OutputHint(io.dingodb.exec.base.OutputHint) Output(io.dingodb.exec.base.Output) TableDefinition(io.dingodb.common.table.TableDefinition) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SimpleHashStrategy(io.dingodb.exec.partition.SimpleHashStrategy) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) Map(java.util.Map) Location(io.dingodb.meta.Location) PartitionStrategy(io.dingodb.exec.partition.PartitionStrategy)

Example 2 with ValuesOperator

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

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

the class DingoJobVisitor method visit.

@Override
public Collection<Output> visit(@Nonnull DingoValues rel) {
    Task task = job.getOrCreate(Services.META.currentLocation());
    ValuesOperator operator = new ValuesOperator(rel.getValues());
    operator.setId(idGenerator.get());
    task.putOperator(operator);
    return operator.getOutputs();
}
Also used : Task(io.dingodb.exec.base.Task) ValuesOperator(io.dingodb.exec.operator.ValuesOperator)

Example 4 with ValuesOperator

use of io.dingodb.exec.operator.ValuesOperator 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

ValuesOperator (io.dingodb.exec.operator.ValuesOperator)4 Task (io.dingodb.exec.base.Task)3 Location (io.dingodb.meta.Location)2 Test (org.junit.jupiter.api.Test)2 TableDefinition (io.dingodb.common.table.TableDefinition)1 Job (io.dingodb.exec.base.Job)1 Output (io.dingodb.exec.base.Output)1 OutputHint (io.dingodb.exec.base.OutputHint)1 RootOperator (io.dingodb.exec.operator.RootOperator)1 PartitionStrategy (io.dingodb.exec.partition.PartitionStrategy)1 SimpleHashStrategy (io.dingodb.exec.partition.SimpleHashStrategy)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1