use of io.dingodb.exec.base.Task 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;
}
use of io.dingodb.exec.base.Task in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoPartModify rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
String tableName = getSimpleName(rel.getTable());
List<Output> outputs = new LinkedList<>();
TableDefinition td = Services.META.getTableDefinition(tableName);
final TableId tableId = new TableId(Services.META.getTableKey(tableName));
for (Output input : inputs) {
Task task = input.getTask();
Operator operator;
switch(rel.getOperation()) {
case INSERT:
operator = new PartInsertOperator(tableId, input.getHint().getPartId(), td.getTupleSchema(), td.getKeyMapping());
break;
case UPDATE:
operator = new PartUpdateOperator(tableId, input.getHint().getPartId(), td.getTupleSchema(), td.getKeyMapping(), TupleMapping.of(td.getColumnIndices(rel.getUpdateColumnList())), rel.getSourceExpressionList().stream().map(RexConverter::toString).collect(Collectors.toList()));
break;
case DELETE:
operator = new PartDeleteOperator(tableId, input.getHint().getPartId(), td.getTupleSchema(), td.getKeyMapping());
break;
default:
throw new IllegalStateException("Operation \"" + rel.getOperation() + "\" is not supported.");
}
operator.setId(idGenerator.get());
task.putOperator(operator);
input.setLink(operator.getInput(0));
OutputHint hint = new OutputHint();
hint.setToSumUp(true);
operator.getSoleOutput().setHint(hint);
outputs.addAll(operator.getOutputs());
}
return outputs;
}
use of io.dingodb.exec.base.Task in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoSort rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
List<Output> outputs = new LinkedList<>();
for (Output input : inputs) {
Operator operator = new SortOperator(rel.getCollation().getFieldCollations().stream().map(c -> new SortCollation(c.getFieldIndex(), c.direction, c.nullDirection)).collect(Collectors.toList()), rel.fetch == null ? -1 : RexLiteral.intValue(rel.fetch), rel.offset == null ? 0 : RexLiteral.intValue(rel.offset));
Task task = input.getTask();
operator.setId(idGenerator.get());
task.putOperator(operator);
input.setLink(operator.getInput(0));
operator.getSoleOutput().copyHint(input);
outputs.addAll(operator.getOutputs());
}
return outputs;
}
use of io.dingodb.exec.base.Task 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;
}
use of io.dingodb.exec.base.Task in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoPartition rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
String tableName = getSimpleName(rel.getTable());
List<Output> outputs = new LinkedList<>();
final Map<String, Location> partLocations = Services.META.getPartLocations(tableName);
final TableDefinition td = Services.META.getTableDefinition(tableName);
final PartitionStrategy ps = new SimpleHashStrategy(partLocations.size());
for (Output input : inputs) {
Task task = input.getTask();
PartitionOperator operator = new PartitionOperator(ps, td.getKeyMapping());
operator.setId(idGenerator.get());
operator.createOutputs(tableName, partLocations);
task.putOperator(operator);
input.setLink(operator.getInput(0));
outputs.addAll(operator.getOutputs());
}
return outputs;
}
Aggregations