Search in sources :

Example 1 with InvalidRelException

use of org.apache.calcite.rel.InvalidRelException in project drill by apache.

the class HashJoinPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
    if (!settings.isHashJoinEnabled()) {
        return;
    }
    final DrillJoinRel join = (DrillJoinRel) call.rel(0);
    final RelNode left = join.getLeft();
    final RelNode right = join.getRight();
    if (!checkPreconditions(join, left, right, settings)) {
        return;
    }
    boolean hashSingleKey = PrelUtil.getPlannerSettings(call.getPlanner()).isHashSingleKey();
    try {
        if (isDist) {
            createDistBothPlan(call, join, PhysicalJoinType.HASH_JOIN, left, right, null, /* left collation */
            null, /* right collation */
            hashSingleKey);
        } else {
            if (checkBroadcastConditions(call.getPlanner(), join, left, right)) {
                createBroadcastPlan(call, join, join.getCondition(), PhysicalJoinType.HASH_JOIN, left, right, null, /* left collation */
                null);
            }
        }
    } catch (InvalidRelException e) {
        tracer.warning(e.toString());
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) DrillJoinRel(org.apache.drill.exec.planner.logical.DrillJoinRel) RelNode(org.apache.calcite.rel.RelNode)

Example 2 with InvalidRelException

use of org.apache.calcite.rel.InvalidRelException in project drill by apache.

the class StreamAggPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final DrillAggregateRel aggregate = (DrillAggregateRel) call.rel(0);
    RelNode input = aggregate.getInput();
    final RelCollation collation = getCollation(aggregate);
    RelTraitSet traits = null;
    if (aggregate.containsDistinctCall()) {
        // currently, don't use StreamingAggregate if any of the logical aggrs contains DISTINCT
        return;
    }
    try {
        if (aggregate.getGroupSet().isEmpty()) {
            DrillDistributionTrait singleDist = DrillDistributionTrait.SINGLETON;
            final RelTraitSet singleDistTrait = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(singleDist);
            if (create2PhasePlan(call, aggregate)) {
                traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL);
                RelNode convertedInput = convert(input, traits);
                new SubsetTransformer<DrillAggregateRel, InvalidRelException>(call) {

                    @Override
                    public RelNode convertChild(final DrillAggregateRel join, final RelNode rel) throws InvalidRelException {
                        DrillDistributionTrait toDist = rel.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE);
                        RelTraitSet traits = newTraitSet(Prel.DRILL_PHYSICAL, toDist);
                        RelNode newInput = convert(rel, traits);
                        StreamAggPrel phase1Agg = new StreamAggPrel(aggregate.getCluster(), traits, newInput, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList(), OperatorPhase.PHASE_1of2);
                        UnionExchangePrel exch = new UnionExchangePrel(phase1Agg.getCluster(), singleDistTrait, phase1Agg);
                        return new StreamAggPrel(aggregate.getCluster(), singleDistTrait, exch, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), phase1Agg.getPhase2AggCalls(), OperatorPhase.PHASE_2of2);
                    }
                }.go(aggregate, convertedInput);
            } else {
                createTransformRequest(call, aggregate, input, singleDistTrait);
            }
        } else {
            // hash distribute on all grouping keys
            final DrillDistributionTrait distOnAllKeys = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(aggregate, true)));
            traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(distOnAllKeys);
            createTransformRequest(call, aggregate, input, traits);
            // hash distribute on one grouping key
            DrillDistributionTrait distOnOneKey = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(aggregate, false)));
            traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(distOnOneKey);
            if (create2PhasePlan(call, aggregate)) {
                traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL);
                RelNode convertedInput = convert(input, traits);
                new SubsetTransformer<DrillAggregateRel, InvalidRelException>(call) {

                    @Override
                    public RelNode convertChild(final DrillAggregateRel aggregate, final RelNode rel) throws InvalidRelException {
                        DrillDistributionTrait toDist = rel.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE);
                        RelTraitSet traits = newTraitSet(Prel.DRILL_PHYSICAL, collation, toDist);
                        RelNode newInput = convert(rel, traits);
                        StreamAggPrel phase1Agg = new StreamAggPrel(aggregate.getCluster(), traits, newInput, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList(), OperatorPhase.PHASE_1of2);
                        int numEndPoints = PrelUtil.getSettings(phase1Agg.getCluster()).numEndPoints();
                        HashToMergeExchangePrel exch = new HashToMergeExchangePrel(phase1Agg.getCluster(), phase1Agg.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(distOnAllKeys), phase1Agg, ImmutableList.copyOf(getDistributionField(aggregate, true)), collation, numEndPoints);
                        return new StreamAggPrel(aggregate.getCluster(), exch.getTraitSet(), exch, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), phase1Agg.getPhase2AggCalls(), OperatorPhase.PHASE_2of2);
                    }
                }.go(aggregate, convertedInput);
            }
        }
    } catch (InvalidRelException e) {
        tracer.warning(e.toString());
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) DrillAggregateRel(org.apache.drill.exec.planner.logical.DrillAggregateRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with InvalidRelException

use of org.apache.calcite.rel.InvalidRelException in project drill by apache.

the class DrillUnionAllRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final LogicalUnion union = (LogicalUnion) call.rel(0);
    // This rule applies to Union-All only
    if (!union.all) {
        return;
    }
    final RelTraitSet traits = union.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
    final List<RelNode> convertedInputs = new ArrayList<>();
    for (RelNode input : union.getInputs()) {
        final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL));
        convertedInputs.add(convertedInput);
    }
    try {
        call.transformTo(new DrillUnionRel(union.getCluster(), traits, convertedInputs, union.all, true));
    } catch (InvalidRelException e) {
        tracer.warning(e.toString());
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) LogicalUnion(org.apache.calcite.rel.logical.LogicalUnion) RelNode(org.apache.calcite.rel.RelNode) ArrayList(java.util.ArrayList) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 4 with InvalidRelException

use of org.apache.calcite.rel.InvalidRelException in project hive by apache.

the class HiveJoin method copy.

@Override
public final HiveJoin copy(RelTraitSet traitSet, RexNode conditionExpr, RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) {
    try {
        Set<String> variablesStopped = Collections.emptySet();
        HiveJoin join = new HiveJoin(getCluster(), traitSet, left, right, conditionExpr, joinType, variablesStopped, joinAlgorithm);
        // If available, copy state to registry for optimization rules
        HiveRulesRegistry registry = join.getCluster().getPlanner().getContext().unwrap(HiveRulesRegistry.class);
        if (registry != null) {
            registry.copyPushedPredicates(this, join);
        }
        return join;
    } catch (InvalidRelException | CalciteSemanticException e) {
        // internal error.
        throw new AssertionError(e);
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) HiveRulesRegistry(org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)

Example 5 with InvalidRelException

use of org.apache.calcite.rel.InvalidRelException in project hive by apache.

the class HiveSemiJoin method copy.

@Override
public SemiJoin copy(RelTraitSet traitSet, RexNode condition, RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) {
    try {
        final JoinInfo joinInfo = JoinInfo.of(left, right, condition);
        HiveSemiJoin semijoin = new HiveSemiJoin(getCluster(), traitSet, left, right, condition, joinInfo.leftKeys, joinInfo.rightKeys);
        // If available, copy state to registry for optimization rules
        HiveRulesRegistry registry = semijoin.getCluster().getPlanner().getContext().unwrap(HiveRulesRegistry.class);
        if (registry != null) {
            registry.copyPushedPredicates(this, semijoin);
        }
        return semijoin;
    } catch (InvalidRelException | CalciteSemanticException e) {
        // internal error.
        throw new AssertionError(e);
    }
}
Also used : JoinInfo(org.apache.calcite.rel.core.JoinInfo) InvalidRelException(org.apache.calcite.rel.InvalidRelException) HiveRulesRegistry(org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)

Aggregations

InvalidRelException (org.apache.calcite.rel.InvalidRelException)13 RelNode (org.apache.calcite.rel.RelNode)11 RelTraitSet (org.apache.calcite.plan.RelTraitSet)8 DrillJoinRel (org.apache.drill.exec.planner.logical.DrillJoinRel)4 RelCollation (org.apache.calcite.rel.RelCollation)2 DrillAggregateRel (org.apache.drill.exec.planner.logical.DrillAggregateRel)2 DrillUnionRel (org.apache.drill.exec.planner.logical.DrillUnionRel)2 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)2 HiveRulesRegistry (org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry)2 ArrayList (java.util.ArrayList)1 JoinInfo (org.apache.calcite.rel.core.JoinInfo)1 LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)1 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)1 LogicalUnion (org.apache.calcite.rel.logical.LogicalUnion)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RexNode (org.apache.calcite.rex.RexNode)1 DistributionField (org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField)1