Search in sources :

Example 81 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project drill by apache.

the class MergeJoinPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
    final DrillJoinRel join = 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 {
        RelCollation collationLeft = getCollation(join.getLeftKeys());
        RelCollation collationRight = getCollation(join.getRightKeys());
        if (isDist) {
            createDistBothPlan(call, join, PhysicalJoinType.MERGE_JOIN, left, right, collationLeft, collationRight, hashSingleKey);
        } else {
            if (checkBroadcastConditions(call.getPlanner(), join, left, right)) {
                createBroadcastPlan(call, join, join.getCondition(), PhysicalJoinType.MERGE_JOIN, left, right, collationLeft, collationRight);
            }
        }
    } catch (InvalidRelException e) {
        tracer.warn(e.toString());
    }
}
Also used : InvalidRelException(org.apache.calcite.rel.InvalidRelException) DrillJoinRel(org.apache.drill.exec.planner.logical.DrillJoinRel) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode)

Example 82 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project drill by apache.

the class WriterPrule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final DrillWriterRel writer = call.rel(0);
    final RelNode input = call.rel(1);
    final List<Integer> keys = writer.getPartitionKeys();
    final RelCollation collation = getCollation(keys);
    final boolean hashDistribute = PrelUtil.getPlannerSettings(call.getPlanner()).getOptions().getOption(ExecConstants.CTAS_PARTITIONING_HASH_DISTRIBUTE_VALIDATOR);
    final RelTraitSet traits = hashDistribute ? input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(getDistribution(keys)) : input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation);
    final RelNode convertedInput = convert(input, traits);
    if (!new WriteTraitPull(call).go(writer, convertedInput)) {
        DrillWriterRelBase newWriter = new WriterPrel(writer.getCluster(), convertedInput.getTraitSet(), convertedInput, writer.getCreateTableEntry());
        call.transformTo(newWriter);
    }
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) DrillWriterRel(org.apache.drill.exec.planner.logical.DrillWriterRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillWriterRelBase(org.apache.drill.exec.planner.common.DrillWriterRelBase)

Example 83 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project drill by apache.

the class TopNPrel method prepareForLateralUnnestPipeline.

@Override
public Prel prepareForLateralUnnestPipeline(List<RelNode> children) {
    List<RelFieldCollation> relFieldCollations = Lists.newArrayList();
    relFieldCollations.add(new RelFieldCollation(0, RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST));
    for (RelFieldCollation fieldCollation : this.collation.getFieldCollations()) {
        relFieldCollations.add(new RelFieldCollation(fieldCollation.getFieldIndex() + 1, fieldCollation.direction, fieldCollation.nullDirection));
    }
    RelCollation collationTrait = RelCollations.of(relFieldCollations);
    RelTraitSet traits = RelTraitSet.createEmpty().replace(this.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE)).replace(collationTrait).replace(DRILL_PHYSICAL);
    return transformTopNToSortAndLimit(children, traits, collationTrait);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 84 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project drill by apache.

the class SortPrel method prepareForLateralUnnestPipeline.

@Override
public Prel prepareForLateralUnnestPipeline(List<RelNode> children) {
    List<RelFieldCollation> relFieldCollations = Lists.newArrayList();
    relFieldCollations.add(new RelFieldCollation(0, RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST));
    for (RelFieldCollation fieldCollation : this.collation.getFieldCollations()) {
        relFieldCollations.add(new RelFieldCollation(fieldCollation.getFieldIndex() + 1, fieldCollation.direction, fieldCollation.nullDirection));
    }
    @SuppressWarnings("deprecation") RelCollation collationTrait = RelCollationImpl.of(relFieldCollations);
    RelTraitSet traits = RelTraitSet.createEmpty().replace(this.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE)).replace(collationTrait).replace(DRILL_PHYSICAL);
    return this.copy(traits, children.get(0), collationTrait, this.offset, this.fetch);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 85 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project herddb by diennea.

the class CalcitePlanner method planSort.

private PlannerOp planSort(EnumerableSort op, RelDataType rowType) {
    PlannerOp input = convertRelNode(op.getInput(), rowType, false, false);
    RelCollation collation = op.getCollation();
    List<RelFieldCollation> fieldCollations = collation.getFieldCollations();
    boolean[] directions = new boolean[fieldCollations.size()];
    boolean[] nullLastdirections = new boolean[fieldCollations.size()];
    int[] fields = new int[fieldCollations.size()];
    int i = 0;
    for (RelFieldCollation col : fieldCollations) {
        RelFieldCollation.Direction direction = col.getDirection();
        int index = col.getFieldIndex();
        RelFieldCollation.NullDirection nullDirection = col.nullDirection;
        directions[i] = direction == RelFieldCollation.Direction.ASCENDING || direction == RelFieldCollation.Direction.STRICTLY_ASCENDING;
        // default is NULL LAST
        nullLastdirections[i] = nullDirection == RelFieldCollation.NullDirection.LAST || nullDirection == RelFieldCollation.NullDirection.UNSPECIFIED;
        fields[i++] = index;
    }
    return new SortOp(input, directions, fields, nullLastdirections);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) PlannerOp(herddb.model.planner.PlannerOp) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) SortOp(herddb.model.planner.SortOp)

Aggregations

RelCollation (org.apache.calcite.rel.RelCollation)83 RelNode (org.apache.calcite.rel.RelNode)40 RelTraitSet (org.apache.calcite.plan.RelTraitSet)37 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)33 RexNode (org.apache.calcite.rex.RexNode)24 ArrayList (java.util.ArrayList)19 RelDataType (org.apache.calcite.rel.type.RelDataType)17 RelOptCluster (org.apache.calcite.plan.RelOptCluster)15 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)13 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 List (java.util.List)11 Sort (org.apache.calcite.rel.core.Sort)11 ImmutableList (com.google.common.collect.ImmutableList)8 RelDistribution (org.apache.calcite.rel.RelDistribution)8 RexInputRef (org.apache.calcite.rex.RexInputRef)8 Map (java.util.Map)7 Mappings (org.apache.calcite.util.mapping.Mappings)7 Supplier (com.google.common.base.Supplier)6 HashMap (java.util.HashMap)6