Search in sources :

Example 1 with DrillRel

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

the class DefaultSqlHandler method convertToDrel.

/**
   *  Given a relNode tree for SELECT statement, convert to Drill Logical RelNode tree.
   * @param relNode
   * @return
   * @throws SqlUnsupportedException
   * @throws RelConversionException
   */
protected DrillRel convertToDrel(final RelNode relNode) throws SqlUnsupportedException, RelConversionException {
    if (context.getOptions().getOption(ExecConstants.EARLY_LIMIT0_OPT) && context.getPlannerSettings().isTypeInferenceEnabled() && FindLimit0Visitor.containsLimit0(relNode)) {
        // if the schema is known, return the schema directly
        final DrillRel shorterPlan;
        if ((shorterPlan = FindLimit0Visitor.getDirectScanRelIfFullySchemaed(relNode)) != null) {
            return shorterPlan;
        }
        if (FindHardDistributionScans.canForceSingleMode(relNode)) {
            // disable distributed mode
            context.getPlannerSettings().forceSingleMode();
        }
    }
    try {
        final RelNode convertedRelNode;
        // HEP Directory pruning .
        final RelNode pruned = transform(PlannerType.HEP_BOTTOM_UP, PlannerPhase.DIRECTORY_PRUNING, relNode);
        final RelTraitSet logicalTraits = pruned.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
        if (!context.getPlannerSettings().isHepOptEnabled()) {
            // hep is disabled, use volcano
            convertedRelNode = transform(PlannerType.VOLCANO, PlannerPhase.LOGICAL_PRUNE_AND_JOIN, pruned, logicalTraits);
        } else {
            final RelNode intermediateNode2;
            if (context.getPlannerSettings().isHepPartitionPruningEnabled()) {
                // hep is enabled and hep pruning is enabled.
                final RelNode intermediateNode = transform(PlannerType.VOLCANO, PlannerPhase.LOGICAL, pruned, logicalTraits);
                intermediateNode2 = transform(PlannerType.HEP_BOTTOM_UP, PlannerPhase.PARTITION_PRUNING, intermediateNode);
            } else {
                // Only hep is enabled
                intermediateNode2 = transform(PlannerType.VOLCANO, PlannerPhase.LOGICAL_PRUNE, pruned, logicalTraits);
            }
            // Do Join Planning.
            convertedRelNode = transform(PlannerType.HEP_BOTTOM_UP, PlannerPhase.JOIN_PLANNING, intermediateNode2);
        }
        // Convert SUM to $SUM0
        final RelNode convertedRelNodeWithSum0 = transform(PlannerType.HEP_BOTTOM_UP, PlannerPhase.SUM_CONVERSION, convertedRelNode);
        final DrillRel drillRel = (DrillRel) convertedRelNodeWithSum0;
        if (drillRel instanceof DrillStoreRel) {
            throw new UnsupportedOperationException();
        } else {
            // If the query contains a limit 0 clause, disable distributed mode since it is overkill for determining schema.
            if (FindLimit0Visitor.containsLimit0(convertedRelNodeWithSum0) && FindHardDistributionScans.canForceSingleMode(convertedRelNodeWithSum0)) {
                context.getPlannerSettings().forceSingleMode();
            }
            return drillRel;
        }
    } catch (RelOptPlanner.CannotPlanException ex) {
        logger.error(ex.getMessage());
        if (JoinUtils.checkCartesianJoin(relNode, new ArrayList<Integer>(), new ArrayList<Integer>(), new ArrayList<Boolean>())) {
            throw new UnsupportedRelOperatorException("This query cannot be planned possibly due to either a cartesian join or an inequality join");
        } else {
            throw ex;
        }
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) UnsupportedRelOperatorException(org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException) DrillStoreRel(org.apache.drill.exec.planner.logical.DrillStoreRel) ArrayList(java.util.ArrayList) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner)

Example 2 with DrillRel

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

the class DefaultSqlHandler method convertToDrel.

/**
   * Return Drill Logical RelNode tree for a SELECT statement, when it is executed / explained directly.
   *
   * @param relNode : root RelNode corresponds to Calcite Logical RelNode.
   * @param validatedRowType : the rowType for the final field names. A rename project may be placed on top of the root.
   * @return
   * @throws RelConversionException
   * @throws SqlUnsupportedException
   */
protected DrillRel convertToDrel(RelNode relNode, RelDataType validatedRowType) throws RelConversionException, SqlUnsupportedException {
    final DrillRel convertedRelNode = convertToDrel(relNode);
    // Put a non-trivial topProject to ensure the final output field name is preserved, when necessary.
    DrillRel topPreservedNameProj = addRenamedProject(convertedRelNode, validatedRowType);
    return new DrillScreenRel(topPreservedNameProj.getCluster(), topPreservedNameProj.getTraitSet(), topPreservedNameProj);
}
Also used : DrillRel(org.apache.drill.exec.planner.logical.DrillRel) DrillScreenRel(org.apache.drill.exec.planner.logical.DrillScreenRel)

Example 3 with DrillRel

use of org.apache.drill.exec.planner.logical.DrillRel 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 4 with DrillRel

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

the class DefaultSqlHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
    final ConvertedRelNode convertedRelNode = validateAndConvert(sqlNode);
    final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
    final RelNode queryRelNode = convertedRelNode.getConvertedNode();
    final DrillRel drel = convertToDrel(queryRelNode, validatedRowType);
    final Prel prel = convertToPrel(drel);
    logAndSetTextPlan("Drill Physical", prel, logger);
    final PhysicalOperator pop = convertToPop(prel);
    final PhysicalPlan plan = convertToPlan(pop);
    log("Drill Plan", plan, logger);
    return plan;
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) RelNode(org.apache.calcite.rel.RelNode) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) RelDataType(org.apache.calcite.rel.type.RelDataType) Prel(org.apache.drill.exec.planner.physical.Prel)

Example 5 with DrillRel

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

the class ExplainHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
    final ConvertedRelNode convertedRelNode = validateAndConvert(sqlNode);
    final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
    final RelNode queryRelNode = convertedRelNode.getConvertedNode();
    log("Calcite", queryRelNode, logger, null);
    DrillRel drel = convertToDrel(queryRelNode, validatedRowType);
    if (mode == ResultMode.LOGICAL) {
        LogicalExplain logicalResult = new LogicalExplain(drel, level, context);
        return DirectPlan.createDirectPlan(context, logicalResult);
    }
    Prel prel = convertToPrel(drel);
    logAndSetTextPlan("Drill Physical", prel, logger);
    PhysicalOperator pop = convertToPop(prel);
    PhysicalPlan plan = convertToPlan(pop);
    log("Drill Plan", plan, logger);
    PhysicalExplain physicalResult = new PhysicalExplain(prel, plan, level, context);
    return DirectPlan.createDirectPlan(context, physicalResult);
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) RelNode(org.apache.calcite.rel.RelNode) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) RelDataType(org.apache.calcite.rel.type.RelDataType) Prel(org.apache.drill.exec.planner.physical.Prel)

Aggregations

DrillRel (org.apache.drill.exec.planner.logical.DrillRel)6 RelNode (org.apache.calcite.rel.RelNode)4 RelDataType (org.apache.calcite.rel.type.RelDataType)3 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)3 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)3 Prel (org.apache.drill.exec.planner.physical.Prel)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 DrillScreenRel (org.apache.drill.exec.planner.logical.DrillScreenRel)2 ArrayList (java.util.ArrayList)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 DrillStoreRel (org.apache.drill.exec.planner.logical.DrillStoreRel)1 DrillWriterRel (org.apache.drill.exec.planner.logical.DrillWriterRel)1 ProjectAllowDupPrel (org.apache.drill.exec.planner.physical.ProjectAllowDupPrel)1 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)1 WriterPrel (org.apache.drill.exec.planner.physical.WriterPrel)1 SqlCreateTable (org.apache.drill.exec.planner.sql.parser.SqlCreateTable)1 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)1 StorageStrategy (org.apache.drill.exec.store.StorageStrategy)1 UnsupportedRelOperatorException (org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException)1