Search in sources :

Example 1 with RelTraitSet

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project storm by apache.

the class QueryPlanner method convertToStormRel.

private RelNode convertToStormRel(RelNode relNode) throws RelConversionException {
    RelTraitSet traitSet = relNode.getTraitSet();
    traitSet = traitSet.simplify();
    // PlannerImpl.transform() optimizes RelNode with ruleset
    return planner.transform(STORM_REL_CONVERSION_RULES, traitSet.plus(TridentLogicalConvention.INSTANCE), relNode);
}
Also used : RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 2 with RelTraitSet

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.

the class JoinPruleBase method createDistBothPlan.

// Create join plan with both left and right children hash distributed. If the physical join type
// is MergeJoin, a collation must be provided for both left and right child and the plan will contain
// sort converter if necessary to provide the collation.
private void createDistBothPlan(RelOptRuleCall call, DrillJoinRel join, PhysicalJoinType physicalJoinType, RelNode left, RelNode right, RelCollation collationLeft, RelCollation collationRight, DrillDistributionTrait hashLeftPartition, DrillDistributionTrait hashRightPartition) throws InvalidRelException {
    //DrillDistributionTrait hashLeftPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getLeftKeys())));
    //DrillDistributionTrait hashRightPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getRightKeys())));
    RelTraitSet traitsLeft = null;
    RelTraitSet traitsRight = null;
    if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
        assert collationLeft != null && collationRight != null;
        traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collationLeft).plus(hashLeftPartition);
        traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collationRight).plus(hashRightPartition);
    } else if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
        traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashLeftPartition);
        traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashRightPartition);
    }
    final RelNode convertedLeft = convert(left, traitsLeft);
    final RelNode convertedRight = convert(right, traitsRight);
    DrillJoinRelBase newJoin = null;
    if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
        newJoin = new HashJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType());
    } else if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
        newJoin = new MergeJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType());
    }
    call.transformTo(newJoin);
}
Also used : DrillJoinRelBase(org.apache.drill.exec.planner.common.DrillJoinRelBase) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with RelTraitSet

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet 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 4 with RelTraitSet

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.

the class LogicalAggregate method create_.

private static LogicalAggregate create_(final RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
    final RelOptCluster cluster = input.getCluster();
    final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE);
    return new LogicalAggregate(cluster, traitSet, input, indicator, groupSet, groupSets, aggCalls);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 5 with RelTraitSet

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.

the class LogicalCorrelate method create.

/**
 * Creates a LogicalCorrelate.
 */
public static LogicalCorrelate create(RelNode left, RelNode right, CorrelationId correlationId, ImmutableBitSet requiredColumns, SemiJoinType joinType) {
    final RelOptCluster cluster = left.getCluster();
    final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE);
    return new LogicalCorrelate(cluster, traitSet, left, right, correlationId, requiredColumns, joinType);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

RelTraitSet (org.apache.calcite.plan.RelTraitSet)190 RelNode (org.apache.calcite.rel.RelNode)111 RelOptCluster (org.apache.calcite.plan.RelOptCluster)38 RelCollation (org.apache.calcite.rel.RelCollation)35 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)26 RexNode (org.apache.calcite.rex.RexNode)24 ArrayList (java.util.ArrayList)20 InvalidRelException (org.apache.calcite.rel.InvalidRelException)19 RelDataType (org.apache.calcite.rel.type.RelDataType)14 SqlNode (org.apache.calcite.sql.SqlNode)14 List (java.util.List)13 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)13 RelOptTable (org.apache.calcite.plan.RelOptTable)11 Sort (org.apache.calcite.rel.core.Sort)11 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)11 ImmutableList (com.google.common.collect.ImmutableList)10 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)10 Test (org.junit.Test)9 Table (org.apache.calcite.schema.Table)8 RexInputRef (org.apache.calcite.rex.RexInputRef)7