Search in sources :

Example 1 with TableId

use of io.dingodb.common.table.TableId 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;
}
Also used : TableId(io.dingodb.common.table.TableId) SumUpOperator(io.dingodb.exec.operator.SumUpOperator) AggregateOperator(io.dingodb.exec.operator.AggregateOperator) SortOperator(io.dingodb.exec.operator.SortOperator) RootOperator(io.dingodb.exec.operator.RootOperator) PartScanOperator(io.dingodb.exec.operator.PartScanOperator) SendOperator(io.dingodb.exec.operator.SendOperator) ReceiveOperator(io.dingodb.exec.operator.ReceiveOperator) ProjectOperator(io.dingodb.exec.operator.ProjectOperator) ValuesOperator(io.dingodb.exec.operator.ValuesOperator) PartUpdateOperator(io.dingodb.exec.operator.PartUpdateOperator) ReduceOperator(io.dingodb.exec.operator.ReduceOperator) Operator(io.dingodb.exec.base.Operator) GetByKeysOperator(io.dingodb.exec.operator.GetByKeysOperator) PartitionOperator(io.dingodb.exec.operator.PartitionOperator) PartDeleteOperator(io.dingodb.exec.operator.PartDeleteOperator) PartInsertOperator(io.dingodb.exec.operator.PartInsertOperator) CoalesceOperator(io.dingodb.exec.operator.CoalesceOperator) Task(io.dingodb.exec.base.Task) PartUpdateOperator(io.dingodb.exec.operator.PartUpdateOperator) PartDeleteOperator(io.dingodb.exec.operator.PartDeleteOperator) LinkedList(java.util.LinkedList) PartInsertOperator(io.dingodb.exec.operator.PartInsertOperator) OutputHint(io.dingodb.exec.base.OutputHint) Output(io.dingodb.exec.base.Output) TableDefinition(io.dingodb.common.table.TableDefinition)

Example 2 with TableId

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

the class DingoJobVisitor method visit.

@Override
public Collection<Output> visit(@Nonnull DingoPartScan rel) {
    String tableName = getSimpleName(rel.getTable());
    TableDefinition td = Services.META.getTableDefinition(tableName);
    Map<String, Location> parts = Services.META.getPartLocations(tableName);
    List<Output> outputs = new ArrayList<>(parts.size());
    TableId tableId = new TableId(Services.META.getTableKey(tableName));
    String filterStr = null;
    if (rel.getFilter() != null) {
        filterStr = RexConverter.convert(rel.getFilter()).toString();
    }
    for (Map.Entry<String, Location> entry : parts.entrySet()) {
        final Object partId = entry.getKey();
        PartScanOperator operator = new PartScanOperator(tableId, entry.getKey(), td.getTupleSchema(), td.getKeyMapping(), filterStr, rel.getSelection());
        operator.setId(idGenerator.get());
        Task task = job.getOrCreate(entry.getValue());
        task.putOperator(operator);
        operator.getSoleOutput().setHint(OutputHint.of(tableName, partId));
        outputs.addAll(operator.getOutputs());
    }
    return outputs;
}
Also used : TableId(io.dingodb.common.table.TableId) Task(io.dingodb.exec.base.Task) ArrayList(java.util.ArrayList) PartScanOperator(io.dingodb.exec.operator.PartScanOperator) Output(io.dingodb.exec.base.Output) TableDefinition(io.dingodb.common.table.TableDefinition) Map(java.util.Map) Location(io.dingodb.meta.Location)

Example 3 with TableId

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

the class DingoJobVisitor method visit.

@Override
public Collection<Output> visit(@Nonnull DingoGetByKeys rel) {
    String tableName = getSimpleName(rel.getTable());
    final Map<String, Location> partLocations = Services.META.getPartLocations(tableName);
    final TableDefinition td = Services.META.getTableDefinition(tableName);
    final PartitionStrategy ps = new SimpleHashStrategy(partLocations.size());
    final TableId tableId = new TableId(Services.META.getTableKey(tableName));
    Map<String, List<Object[]>> partMap = ps.partKeyTuples(rel.getKeyTuples());
    List<Output> outputs = new LinkedList<>();
    for (Map.Entry<String, List<Object[]>> entry : partMap.entrySet()) {
        final Object partId = entry.getKey();
        GetByKeysOperator operator = new GetByKeysOperator(tableId, partId, td.getTupleSchema(), td.getKeyMapping(), entry.getValue(), rel.getSelection());
        operator.setId(idGenerator.get());
        Task task = job.getOrCreate(partLocations.get(entry.getKey()));
        task.putOperator(operator);
        operator.getSoleOutput().setHint(OutputHint.of(tableName, partId));
        outputs.addAll(operator.getOutputs());
    }
    return outputs;
}
Also used : TableId(io.dingodb.common.table.TableId) Task(io.dingodb.exec.base.Task) LinkedList(java.util.LinkedList) GetByKeysOperator(io.dingodb.exec.operator.GetByKeysOperator) 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) Map(java.util.Map) Location(io.dingodb.meta.Location) PartitionStrategy(io.dingodb.exec.partition.PartitionStrategy)

Example 4 with TableId

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

the class MetaTestService method createTable.

@Override
public void createTable(@Nonnull String tableName, @Nonnull TableDefinition tableDefinition) {
    try {
        OutputStream os = new FileOutputStream(metaFile(tableName));
        tableDefinition.writeJson(os);
        // force reload
        tableDefinitionMap = null;
        Map<String, Location> partLocations = getPartLocations(tableName);
        for (Map.Entry<String, Location> entry : partLocations.entrySet()) {
            StoreInstance store = Services.KV_STORE.getInstance(entry.getValue().getPath());
            new PartInKvStore(store.getKvBlock(new TableId(getTableKey(tableName)), entry.getKey()), tableDefinition.getTupleSchema(), tableDefinition.getKeyMapping());
        }
    } catch (IOException e) {
        log.error("Failed to write table definition: {}", tableDefinition);
        throw new AssertionError("Failed to write table definition.");
    }
}
Also used : TableId(io.dingodb.common.table.TableId) PartInKvStore(io.dingodb.exec.table.PartInKvStore) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StoreInstance(io.dingodb.store.api.StoreInstance) Location(io.dingodb.meta.Location)

Aggregations

TableId (io.dingodb.common.table.TableId)4 TableDefinition (io.dingodb.common.table.TableDefinition)3 Output (io.dingodb.exec.base.Output)3 Task (io.dingodb.exec.base.Task)3 Location (io.dingodb.meta.Location)3 Map (java.util.Map)3 GetByKeysOperator (io.dingodb.exec.operator.GetByKeysOperator)2 PartScanOperator (io.dingodb.exec.operator.PartScanOperator)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Operator (io.dingodb.exec.base.Operator)1 OutputHint (io.dingodb.exec.base.OutputHint)1 AggregateOperator (io.dingodb.exec.operator.AggregateOperator)1 CoalesceOperator (io.dingodb.exec.operator.CoalesceOperator)1 PartDeleteOperator (io.dingodb.exec.operator.PartDeleteOperator)1 PartInsertOperator (io.dingodb.exec.operator.PartInsertOperator)1 PartUpdateOperator (io.dingodb.exec.operator.PartUpdateOperator)1 PartitionOperator (io.dingodb.exec.operator.PartitionOperator)1 ProjectOperator (io.dingodb.exec.operator.ProjectOperator)1