Search in sources :

Example 1 with TupleSchema

use of io.dingodb.common.table.TupleSchema 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;
}
Also used : ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) Task(io.dingodb.exec.base.Task) Output(io.dingodb.exec.base.Output) TableId(io.dingodb.common.table.TableId) Id(io.dingodb.exec.base.Id) SendOperator(io.dingodb.exec.operator.SendOperator) LinkedList(java.util.LinkedList) TupleSchema(io.dingodb.common.table.TupleSchema) Location(io.dingodb.meta.Location)

Example 2 with TupleSchema

use of io.dingodb.common.table.TupleSchema in project dingo by dingodb.

the class CsvUtils method readCsv.

/**
 * Read a csv stream into tuples. The first line is the tuple schema definition.
 *
 * @param is the csv stream
 * @return iterator of tuples
 * @throws IOException when errors occurred in reading the stream
 */
@Nonnull
public static Iterator<Object[]> readCsv(InputStream is) throws IOException {
    final Iterator<String[]> it = PARSER.readValues(is, String[].class);
    if (it.hasNext()) {
        String[] types = it.next();
        TupleSchema schema = TupleSchema.ofTypes(types);
        return Iterators.transform(it, schema::parse);
    }
    return Iterators.transform(it, s -> s);
}
Also used : TupleSchema(io.dingodb.common.table.TupleSchema) Nonnull(javax.annotation.Nonnull)

Aggregations

TupleSchema (io.dingodb.common.table.TupleSchema)2 TableId (io.dingodb.common.table.TableId)1 Id (io.dingodb.exec.base.Id)1 Output (io.dingodb.exec.base.Output)1 Task (io.dingodb.exec.base.Task)1 ReceiveOperator (io.dingodb.exec.operator.ReceiveOperator)1 SendOperator (io.dingodb.exec.operator.SendOperator)1 Location (io.dingodb.meta.Location)1 LinkedList (java.util.LinkedList)1 Nonnull (javax.annotation.Nonnull)1