Search in sources :

Example 71 with RelTraitSet

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

the class SortConvertPrule method convert.

@Override
public RelNode convert(RelNode r) {
    Sort rel = (Sort) r;
    RelTraitSet traits = rel.getInput().getTraitSet().replace(Prel.DRILL_PHYSICAL);
    return new SortPrel(rel.getCluster(), traits.plus(rel.getCollation()), convert(rel.getInput(), traits.simplify()), rel.getCollation());
}
Also used : Sort(org.apache.calcite.rel.core.Sort) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 72 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, DrillJoin join, PhysicalJoinType physicalJoinType, RelNode left, RelNode right, RelCollation collationLeft, RelCollation collationRight, DrillDistributionTrait hashLeftPartition, DrillDistributionTrait hashRightPartition) throws InvalidRelException {
    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) {
        final RelTraitSet traitSet = PrelUtil.removeCollation(traitsLeft, call);
        newJoin = new HashJoinPrel(join.getCluster(), traitSet, convertedLeft, convertedRight, join.getCondition(), join.getJoinType(), join.isSemiJoin());
    } else if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
        newJoin = new MergeJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType(), join.isSemiJoin());
    }
    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 73 with RelTraitSet

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

the class LateralJoinPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final DrillLateralJoinRel lateralJoinRel = call.rel(0);
    final RelNode left = lateralJoinRel.getLeft();
    final RelNode right = lateralJoinRel.getRight();
    RelTraitSet traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL);
    RelTraitSet traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL);
    RelTraitSet corrTraits = traitsLeft.plus(DrillDistributionTrait.RANDOM_DISTRIBUTED);
    final RelNode convertedLeft = convert(left, traitsLeft);
    final RelNode convertedRight = convert(right, traitsRight);
    final LateralJoinPrel lateralJoinPrel = new LateralJoinPrel(lateralJoinRel.getCluster(), corrTraits, convertedLeft, convertedRight, lateralJoinRel.excludeCorrelateColumn, lateralJoinRel.getCorrelationId(), lateralJoinRel.getRequiredColumns(), lateralJoinRel.getJoinType());
    call.transformTo(lateralJoinPrel);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) DrillLateralJoinRel(org.apache.drill.exec.planner.logical.DrillLateralJoinRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 74 with RelTraitSet

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

the class ProjectPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final DrillProjectRel project = call.rel(0);
    final RelNode input = project.getInput();
    RelTraitSet traits = input.getTraitSet().plus(Prel.DRILL_PHYSICAL);
    RelNode convertedInput = convert(input, traits);
    // Maintain two different map for distribution trait and collation trait.
    // For now, the only difference comes from the way how cast function impacts propagating trait.
    final Map<Integer, Integer> distributionMap = getDistributionMap(project);
    final Map<Integer, Integer> collationMap = getCollationMap(project);
    boolean traitPull = new ProjectTraitPull(call, distributionMap, collationMap).go(project, convertedInput);
    if (!traitPull) {
        call.transformTo(new ProjectPrel(project.getCluster(), convertedInput.getTraitSet(), convertedInput, project.getProjects(), project.getRowType()));
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) DrillProjectRel(org.apache.drill.exec.planner.logical.DrillProjectRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 75 with RelTraitSet

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

the class QueryPlanner method optimize.

private RelRoot optimize(Planner planner, RelRoot relRoot) {
    RelTraitSet relTraitSet = RelTraitSet.createEmpty();
    try {
        RelRoot optimizedRelRoot = RelRoot.of(planner.transform(0, relTraitSet, relRoot.project()), SqlKind.SELECT);
        LOG.info("query plan with optimization:\n" + RelOptUtil.toString(optimizedRelRoot.rel, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
        return optimizedRelRoot;
    } catch (Exception e) {
        String errorMsg = "Error while optimizing query plan:\n" + RelOptUtil.toString(relRoot.rel, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
        LOG.error(errorMsg, e);
        throw new SamzaException(errorMsg, e);
    }
}
Also used : RelRoot(org.apache.calcite.rel.RelRoot) RelTraitSet(org.apache.calcite.plan.RelTraitSet) SamzaException(org.apache.samza.SamzaException) SamzaException(org.apache.samza.SamzaException)

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)36 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