Search in sources :

Example 1 with DrillWriterRel

use of org.apache.drill.exec.planner.logical.DrillWriterRel in project drill by apache.

the class CreateTableHandler method convertToDrel.

private DrillRel convertToDrel(RelNode relNode, AbstractSchema schema, String tableName, List<String> partitionColumns, RelDataType queryRowType, StorageStrategy storageStrategy) throws RelConversionException, SqlUnsupportedException {
    final DrillRel convertedRelNode = convertToDrel(relNode);
    // Put a non-trivial topProject to ensure the final output field name is preserved, when necessary.
    // Only insert project when the field count from the child is same as that of the queryRowType.
    final DrillRel topPreservedNameProj = queryRowType.getFieldCount() == convertedRelNode.getRowType().getFieldCount() ? addRenamedProject(convertedRelNode, queryRowType) : convertedRelNode;
    final RelTraitSet traits = convertedRelNode.getCluster().traitSet().plus(DrillRel.DRILL_LOGICAL);
    final DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(), traits, topPreservedNameProj, schema.createNewTable(tableName, partitionColumns, storageStrategy));
    return new DrillScreenRel(writerRel.getCluster(), writerRel.getTraitSet(), writerRel);
}
Also used : DrillRel(org.apache.drill.exec.planner.logical.DrillRel) DrillWriterRel(org.apache.drill.exec.planner.logical.DrillWriterRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillScreenRel(org.apache.drill.exec.planner.logical.DrillScreenRel)

Example 2 with DrillWriterRel

use of org.apache.drill.exec.planner.logical.DrillWriterRel in project drill by apache.

the class WriterPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final DrillWriterRel writer = call.rel(0);
    final RelNode input = call.rel(1);
    final List<Integer> keys = writer.getPartitionKeys();
    final RelCollation collation = getCollation(keys);
    final boolean hashDistribute = PrelUtil.getPlannerSettings(call.getPlanner()).getOptions().getOption(ExecConstants.CTAS_PARTITIONING_HASH_DISTRIBUTE_VALIDATOR);
    final RelTraitSet traits = hashDistribute ? input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(getDistribution(keys)) : input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation);
    final RelNode convertedInput = convert(input, traits);
    if (!new WriteTraitPull(call).go(writer, convertedInput)) {
        DrillWriterRelBase newWriter = new WriterPrel(writer.getCluster(), convertedInput.getTraitSet(), convertedInput, writer.getCreateTableEntry());
        call.transformTo(newWriter);
    }
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) DrillWriterRel(org.apache.drill.exec.planner.logical.DrillWriterRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillWriterRelBase(org.apache.drill.exec.planner.common.DrillWriterRelBase)

Aggregations

RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 DrillWriterRel (org.apache.drill.exec.planner.logical.DrillWriterRel)2 RelCollation (org.apache.calcite.rel.RelCollation)1 RelNode (org.apache.calcite.rel.RelNode)1 DrillWriterRelBase (org.apache.drill.exec.planner.common.DrillWriterRelBase)1 DrillRel (org.apache.drill.exec.planner.logical.DrillRel)1 DrillScreenRel (org.apache.drill.exec.planner.logical.DrillScreenRel)1