Search in sources :

Example 1 with DrillStoreRel

use of org.apache.drill.exec.planner.logical.DrillStoreRel 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)

Aggregations

ArrayList (java.util.ArrayList)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1 DrillRel (org.apache.drill.exec.planner.logical.DrillRel)1 DrillStoreRel (org.apache.drill.exec.planner.logical.DrillStoreRel)1 UnsupportedRelOperatorException (org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException)1