use of io.dingodb.exec.base.Output in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoExchange rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
List<Output> outputs = new LinkedList<>();
TupleSchema schema = TupleSchema.fromRelDataType(rel.getRowType());
for (Output input : inputs) {
Task task = input.getTask();
Location target = input.getTargetLocation();
if (target == null) {
target = Services.META.currentLocation();
}
if (!target.equals(task.getLocation())) {
Id id = idGenerator.get();
Id receiveId = idGenerator.get();
SendOperator send = new SendOperator(target.getHost(), target.getPort(), receiveId, schema);
send.setId(id);
task.putOperator(send);
input.setLink(send.getInput(0));
ReceiveOperator receive = new ReceiveOperator(task.getHost(), task.getLocation().getPort(), schema);
receive.setId(receiveId);
receive.getSoleOutput().copyHint(input);
Task rcvTask = job.getOrCreate(target);
rcvTask.putOperator(receive);
outputs.addAll(receive.getOutputs());
} else {
outputs.add(input);
}
}
return outputs;
}
use of io.dingodb.exec.base.Output in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoCoalesce rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
int size = inputs.size();
if (size <= 1) {
return inputs;
}
Output one = inputs.iterator().next();
boolean isToSumUp = one.isToSumUp();
Operator operator = isToSumUp ? new SumUpOperator(size) : new CoalesceOperator(size);
operator.setId(idGenerator.get());
Task task = one.getTask();
task.putOperator(operator);
int i = 0;
for (Output input : inputs) {
assert input.getTask().equals(task) : "Operator linked must be in the same task.";
assert input.isToSumUp() == isToSumUp : "All inputs must have the same \"toSumUp\" hint.";
input.setLink(operator.getInput(i));
++i;
}
return operator.getOutputs();
}
use of io.dingodb.exec.base.Output in project dingo by dingodb.
the class DingoJobVisitor method visit.
@Override
public Collection<Output> visit(@Nonnull DingoReduce rel) {
Collection<Output> inputs = dingo(rel.getInput()).accept(this);
int size = inputs.size();
if (size <= 1) {
return inputs;
}
Operator operator;
operator = new ReduceOperator(inputs.size(), rel.getKeyMapping(), rel.getAggList());
operator.setId(idGenerator.get());
Output one = inputs.iterator().next();
Task task = one.getTask();
task.putOperator(operator);
int i = 0;
for (Output input : inputs) {
assert input.getTask().equals(task) : "Operator linked must be in the same task.";
input.setLink(operator.getInput(i));
++i;
}
return operator.getOutputs();
}
use of io.dingodb.exec.base.Output 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.Output 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;
}
Aggregations