Search in sources :

Example 6 with TableDefinition

use of io.dingodb.common.table.TableDefinition 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;
}
Also used : Task(io.dingodb.exec.base.Task) PartitionOperator(io.dingodb.exec.operator.PartitionOperator) Output(io.dingodb.exec.base.Output) TableDefinition(io.dingodb.common.table.TableDefinition) SimpleHashStrategy(io.dingodb.exec.partition.SimpleHashStrategy) LinkedList(java.util.LinkedList) Location(io.dingodb.meta.Location) PartitionStrategy(io.dingodb.exec.partition.PartitionStrategy)

Example 7 with TableDefinition

use of io.dingodb.common.table.TableDefinition 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 8 with TableDefinition

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

the class DingoGetByKeysRule method onMatch.

@Override
public void onMatch(@Nonnull RelOptRuleCall call) {
    final DingoTableScan rel = call.rel(0);
    RexNode rexNode = RexUtil.toDnf(rel.getCluster().getRexBuilder(), rel.getFilter());
    TableDefinition td = dingo(rel.getTable()).getTableDefinition();
    KeyTuplesRexVisitor visitor = new KeyTuplesRexVisitor(td);
    Set<Object[]> keyTuples = rexNode.accept(visitor);
    if (checkKeyTuples(keyTuples)) {
        call.transformTo(new DingoGetByKeys(rel.getCluster(), rel.getTraitSet().replace(DingoConventions.DISTRIBUTED), rel.getTable(), keyTuples, rel.getSelection()));
    }
}
Also used : DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) TableDefinition(io.dingodb.common.table.TableDefinition) DingoGetByKeys(io.dingodb.calcite.rel.DingoGetByKeys) RexNode(org.apache.calcite.rex.RexNode)

Example 9 with TableDefinition

use of io.dingodb.common.table.TableDefinition 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 10 with TableDefinition

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

the class DingoPartModifyRule method checkUpdateInPart.

private static void checkUpdateInPart(@Nonnull DingoTableModify rel) {
    DingoTable table = rel.getTable().unwrap(DingoTable.class);
    assert table != null;
    TableDefinition td = table.getTableDefinition();
    List<String> updateList = rel.getUpdateColumnList();
    if (updateList != null && updateList.stream().anyMatch(c -> Objects.requireNonNull(td.getColumn(c)).isPrimary())) {
        throw new IllegalStateException("Update columns " + updateList + " contain primary columns and are not supported.");
    }
}
Also used : DingoTable(io.dingodb.calcite.DingoTable) DingoExchange(io.dingodb.calcite.rel.DingoExchange) RelOptCluster(org.apache.calcite.plan.RelOptCluster) DingoTableModify(io.dingodb.calcite.rel.DingoTableModify) TableDefinition(io.dingodb.common.table.TableDefinition) RelRule(org.apache.calcite.plan.RelRule) RelNode(org.apache.calcite.rel.RelNode) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) Objects(java.util.Objects) DingoConventions(io.dingodb.calcite.DingoConventions) List(java.util.List) DingoPartModify(io.dingodb.calcite.rel.DingoPartModify) DingoPartition(io.dingodb.calcite.rel.DingoPartition) DingoTable(io.dingodb.calcite.DingoTable) Nonnull(javax.annotation.Nonnull) TableDefinition(io.dingodb.common.table.TableDefinition)

Aggregations

TableDefinition (io.dingodb.common.table.TableDefinition)13 Output (io.dingodb.exec.base.Output)5 Task (io.dingodb.exec.base.Task)5 Location (io.dingodb.meta.Location)4 LinkedList (java.util.LinkedList)4 TableId (io.dingodb.common.table.TableId)3 PartitionStrategy (io.dingodb.exec.partition.PartitionStrategy)3 SimpleHashStrategy (io.dingodb.exec.partition.SimpleHashStrategy)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 PrimitiveCodec.encodeString (io.dingodb.common.codec.PrimitiveCodec.encodeString)2 OutputHint (io.dingodb.exec.base.OutputHint)2 GetByKeysOperator (io.dingodb.exec.operator.GetByKeysOperator)2 PartScanOperator (io.dingodb.exec.operator.PartScanOperator)2 PartitionOperator (io.dingodb.exec.operator.PartitionOperator)2 ValuesOperator (io.dingodb.exec.operator.ValuesOperator)2 IOException (java.io.IOException)2 List (java.util.List)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 DingoConventions (io.dingodb.calcite.DingoConventions)1