org.apache.calcite.rel.InvalidRelException Java Examples

The following examples show how to use org.apache.calcite.rel.InvalidRelException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnionDistinctPrule.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  final DrillUnionRel union = call.rel(0);
  final List<RelNode> inputs = union.getInputs();
  List<RelNode> convertedInputList = Lists.newArrayList();
  RelTraitSet traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL);

  try {
    for (RelNode input : inputs) {
      RelNode convertedInput = convert(input, PrelUtil.fixTraits(call, traits));
      convertedInputList.add(convertedInput);
    }

    traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(DrillDistributionTrait.SINGLETON);
    UnionDistinctPrel unionDistinct =
        new UnionDistinctPrel(union.getCluster(), traits, convertedInputList,
            false /* compatibility already checked during logical phase */);

    call.transformTo(unionDistinct);

  } catch (InvalidRelException e) {
    tracer.warn(e.toString());
  }
}
 
Example #2
Source File: DrillJoinRel.java    From Bats with Apache License 2.0 6 votes vote down vote up
protected static RexNode getJoinCondition(Join join, ConversionContext context) throws InvalidRelException {
  Pair<RelNode, RelNode> inputs = getJoinInputs(join, context);
  List<RexNode> joinConditions = new ArrayList<RexNode>();
  // right fields appear after the LHS fields.
  final int rightInputOffset = inputs.left.getRowType().getFieldCount();
  for (JoinCondition condition : join.getConditions()) {
    RelDataTypeField leftField = inputs.left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()),
        true, false);
    RelDataTypeField rightField = inputs.right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()),
        true, false);
    joinConditions.add(
        context.getRexBuilder().makeCall(
            SqlStdOperatorTable.EQUALS,
            context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
            context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
        )
    );
  }
  RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
  return rexCondition;
}
 
Example #3
Source File: HashAggPrule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void createTransformRequest(RelOptRuleCall call, AggregateRel aggregate,
                                    RelNode input, RelTraitSet traits) throws InvalidRelException {

  final RelNode convertedInput = convert(input, PrelUtil.fixTraits(call, traits));

  HashAggPrel newAgg = HashAggPrel.create(
      aggregate.getCluster(),
      traits,
      convertedInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of1);

  call.transformTo(newAgg);
}
 
Example #4
Source File: StreamAggPrule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void createTransformRequest(RelOptRuleCall call, AggregateRel aggregate,
                                    RelNode input, RelTraitSet inputTraits, RelTraitSet outputTraits) throws InvalidRelException {

  final RelNode convertedInput = convert(input, inputTraits);

  StreamAggPrel newAgg = StreamAggPrel.create(
      aggregate.getCluster(),
      outputTraits,
      convertedInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of1);

  call.transformTo(newAgg);
}
 
Example #5
Source File: HashAggPrule.java    From Bats with Apache License 2.0 6 votes vote down vote up
private void createTransformRequest(RelOptRuleCall call, DrillAggregateRel aggregate,
                                    RelNode input, RelTraitSet traits) throws InvalidRelException {

  final RelNode convertedInput = convert(input, PrelUtil.fixTraits(call, traits));

  HashAggPrel newAgg = new HashAggPrel(
      aggregate.getCluster(),
      traits,
      convertedInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of1);

  call.transformTo(newAgg);
}
 
Example #6
Source File: NestedLoopJoinPrule.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
  if (!settings.isNestedLoopJoinEnabled()) {
    return;
  }
  int[] joinFields = new int[2];
  DrillJoinRel join = (DrillJoinRel) call.rel(0);
  final RelNode left = join.getLeft();
  final RelNode right = join.getRight();

  if (!checkPreconditions(join, left, right, settings)) {
    return;
  }

  try {

    if (checkBroadcastConditions(call.getPlanner(), join, left, right)) {
      createBroadcastPlan(call, join, join.getCondition(), PhysicalJoinType.NESTEDLOOP_JOIN,
          left, right, null /* left collation */, null /* right collation */);
    }

  } catch (InvalidRelException e) {
    tracer.warn(e.toString());
  }
}
 
Example #7
Source File: OLAPAggregateRule.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
    LogicalAggregate agg = (LogicalAggregate) rel;

    // AVG() will be transformed into SUM()/COUNT() by AggregateReduceFunctionsRule.
    // Here only let the transformed plan pass.
    if (containsAvg(agg)) {
        return null;
    }

    RelTraitSet traitSet = agg.getTraitSet().replace(OLAPRel.CONVENTION);
    try {
        return new OLAPAggregateRel(agg.getCluster(), traitSet, convert(agg.getInput(), OLAPRel.CONVENTION), agg.indicator, agg.getGroupSet(), agg.getGroupSets(), agg.getAggCallList());
    } catch (InvalidRelException e) {
        throw new IllegalStateException("Can't create OLAPAggregateRel!", e);
    }
}
 
Example #8
Source File: StreamAggPrel.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static StreamAggPrel create(RelOptCluster cluster,
                     RelTraitSet traits,
                     RelNode child,
                     boolean indicator,
                     ImmutableBitSet groupSet,
                     List<ImmutableBitSet> groupSets,
                     List<AggregateCall> aggCalls,
                     OperatorPhase phase) throws InvalidRelException {
  final RelTraitSet adjustedTraits = AggPrelBase.adjustTraits(traits, child, groupSet)
      .replaceIf(RelCollationTraitDef.INSTANCE, () -> {
        // Validate input collation which should match groups
        if (AssertionUtil.isAssertionsEnabled()) {
          validateCollation(cluster, child, groupSet);
        }

        return collation(groupSet);
      });

  return new StreamAggPrel(cluster, adjustedTraits, child, indicator, groupSet, groupSets, aggCalls, phase);
}
 
Example #9
Source File: UnionAllRule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@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(Rel.LOGICAL);
  final List<RelNode> convertedInputs = new ArrayList<>();
  for (RelNode input : union.getInputs()) {
    final RelNode convertedInput = convert(input, input.getTraitSet().plus(Rel.LOGICAL).simplify());
    convertedInputs.add(convertedInput);
  }
  try {
    call.transformTo(new UnionRel(union.getCluster(), traits, convertedInputs, union.all,
        true /* check compatibility */));
  } catch (InvalidRelException e) {
    tracer.warn(e.toString()) ;
  }
}
 
Example #10
Source File: AggregateRule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  final LogicalAggregate aggregate = (LogicalAggregate) call.rel(0);
  final RelNode input = call.rel(1);

  if (aggregate.containsDistinctCall() || ProjectableSqlAggFunctions.isProjectableAggregate(aggregate)) {
    // currently, don't use this rule if any of the aggregates contains DISTINCT or projectable agg calls
    return;
  }

  final RelTraitSet traits = aggregate.getTraitSet().plus(Rel.LOGICAL);
  final RelNode convertedInput = convert(input, input.getTraitSet().plus(Rel.LOGICAL).simplify());
  try {
    call.transformTo(AggregateRel.create(aggregate.getCluster(), traits, convertedInput, aggregate.indicator,
        aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList()));
  } catch (InvalidRelException e) {
    // Do nothing. Planning might not succeed, but that's okay.
    tracer.debug("Cannot create aggregate node", e);
  }
}
 
Example #11
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public OLAPAggregateRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, boolean indicator,
        ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
        throws InvalidRelException {
    super(cluster, traits, child, indicator, groupSet, groupSets, aggCalls);
    Preconditions.checkArgument(getConvention() == OLAPRel.CONVENTION);
    this.afterAggregate = false;
    this.rewriteAggCalls = aggCalls;
    this.rowType = getRowType();
}
 
Example #12
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet,
        List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
    try {
        return new OLAPAggregateRel(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls);
    } catch (InvalidRelException e) {
        throw new IllegalStateException("Can't create OLAPAggregateRel!", e);
    }
}
 
Example #13
Source File: JoinPruleBase.java    From Bats with Apache License 2.0 5 votes vote down vote up
protected void createDistBothPlan(RelOptRuleCall call, DrillJoin join,
    PhysicalJoinType physicalJoinType,
    RelNode left, RelNode right,
    RelCollation collationLeft, RelCollation collationRight,
    boolean hashSingleKey)throws InvalidRelException {

  /* If join keys are  l1 = r1 and l2 = r2 and ... l_k = r_k, then consider the following options of plan:
   *   1) Plan1: distributed by (l1, l2, ..., l_k) for left side and by (r1, r2, ..., r_k) for right side.
   *   2) Plan2: distributed by l1 for left side, by r1 for right side.
   *   3) Plan3: distributed by l2 for left side, by r2 for right side.
   *   ...
   *      Plan_(k+1): distributed by l_k for left side, by r_k by right side.
   *
   *   Whether enumerate plan 2, .., Plan_(k+1) depends on option : hashSingleKey.
   */

  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())));

  createDistBothPlan(call, join, physicalJoinType, left, right, collationLeft, collationRight, hashLeftPartition, hashRightPartition);

  assert (join.getLeftKeys().size() == join.getRightKeys().size());

  if (!hashSingleKey) {
    return;
  }

  int numJoinKeys = join.getLeftKeys().size();
  if (numJoinKeys > 1) {
    for (int i = 0; i< numJoinKeys; i++) {
      hashLeftPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getLeftKeys().subList(i, i+1))));
      hashRightPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getRightKeys().subList(i, i+1))));

      createDistBothPlan(call, join, physicalJoinType, left, right, collationLeft, collationRight, hashLeftPartition, hashRightPartition);
    }
  }
}
 
Example #14
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) {
    try {
        return new EnumerableAggregate(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), //
                sole(inputs), indicator, this.groupSet, this.groupSets, rewriteAggCalls);
    } catch (InvalidRelException e) {
        throw new IllegalStateException("Can't create EnumerableAggregate!", e);
    }
}
 
Example #15
Source File: AggregateRel.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  try {
    return AggregateRel.create(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls);
  } catch (InvalidRelException e) {
    // Semantic error not possible. Must be a bug. Convert to
    // internal error.
    throw new AssertionError(e);
  }
}
 
Example #16
Source File: OLAPJoinRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public OLAPJoinRel(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, //
        RexNode condition, ImmutableIntList leftKeys, ImmutableIntList rightKeys, //
        Set<CorrelationId> variablesSet, JoinRelType joinType) throws InvalidRelException {
    super(cluster, traits, left, right, condition, leftKeys, rightKeys, variablesSet, joinType);
    Preconditions.checkArgument(getConvention() == OLAPRel.CONVENTION);
    this.rowType = getRowType();
    this.isTopJoin = false;
}
 
Example #17
Source File: UnionRelBase.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public UnionRelBase(RelOptCluster cluster, RelTraitSet traits,
    List<RelNode> inputs, boolean all, boolean checkCompatibility) throws InvalidRelException {
  super(cluster, traits, inputs, all);
  if (checkCompatibility &&
      !this.isCompatible(cluster, false /* don't compare names */, true /* allow substrings */)) {
    throw new InvalidRelException("Input row types of the Union are not compatible.");
  }
}
 
Example #18
Source File: NestedLoopJoinPrule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void createBroadcastPlan(
    final RelOptRuleCall call,
    final JoinRel join,
    final RexNode joinCondition,
    final RelNode incomingLeft,
    final RelNode incomingRight,
    final RelCollation collationLeft,
    final RelCollation collationRight) throws InvalidRelException {
  throw new UnsupportedOperationException("Not used.");
}
 
Example #19
Source File: DrillUnionRelBase.java    From Bats with Apache License 2.0 5 votes vote down vote up
public DrillUnionRelBase(RelOptCluster cluster, RelTraitSet traits,
    List<RelNode> inputs, boolean all, boolean checkCompatibility) throws InvalidRelException {
  super(cluster, traits, inputs, all);
  if (checkCompatibility &&
      !this.isCompatible(false /* don't compare names */, true /* allow substrings */)) {
    throw new InvalidRelException("Input row types of the Union are not compatible.");
  }
}
 
Example #20
Source File: DremioRelFactories.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public RelNode createSetOp(SqlKind kind, List<RelNode> inputs, boolean all) {
  final RelOptCluster cluster = inputs.get(0).getCluster();
  final RelTraitSet traitSet = cluster.traitSetOf(Rel.LOGICAL);
  switch(kind) {
    case UNION:
      try {
        return new UnionRel(cluster, traitSet, inputs, all, true);
      } catch (InvalidRelException e) {
        throw new AssertionError(e);
      }
    default:
      throw new AssertionError("Dremio doesn't currently support " + kind + " operations.");
  }
}
 
Example #21
Source File: StreamAggPrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
public StreamAggPrel(RelOptCluster cluster,
                     RelTraitSet traits,
                     RelNode child,
                     boolean indicator,
                     ImmutableBitSet groupSet,
                     List<ImmutableBitSet> groupSets,
                     List<AggregateCall> aggCalls,
                     OperatorPhase phase) throws InvalidRelException {
  super(cluster, traits, child, indicator, groupSet, groupSets, aggCalls, phase);
}
 
Example #22
Source File: HashJoinPrule.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
  if (!settings.isHashJoinEnabled() || isSemi && !settings.isSemiJoinEnabled()) {
    return;
  }

  final DrillJoin 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 {

    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 /* right collation */);
      }
    }


  } catch (InvalidRelException e) {
    tracer.warn(e.toString());
  }
}
 
Example #23
Source File: JoinPruleBase.java    From Bats with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: HashJoinPrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
public HashJoinPrel(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition,
    JoinRelType joinType, boolean swapped, RuntimeFilterDef runtimeFilterDef,
    boolean isRowKeyJoin, int joinControl, boolean semiJoin) throws InvalidRelException {
  super(cluster, traits, left, right, condition, joinType, semiJoin);
  Preconditions.checkArgument(isSemiJoin && !swapped || swapped && !isSemiJoin || (!swapped && !isSemiJoin));
  if (isSemiJoin) {
    Preconditions.checkArgument(!swapped, "swapping of inputs is not allowed for semi-joins");
    Preconditions.checkArgument(validateTraits(traitSet, left, right));
  }
  this.swapped = swapped;
  this.isRowKeyJoin = isRowKeyJoin;
  joincategory = JoinUtils.getJoinCategory(left, right, condition, leftKeys, rightKeys, filterNulls);
  this.runtimeFilterDef = runtimeFilterDef;
  this.joinControl = joinControl;
}
 
Example #25
Source File: MergeJoinPrule.java    From Bats with Apache License 2.0 5 votes vote down vote up
@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());
  }
}
 
Example #26
Source File: HashAggPrule.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convertChild(DrillAggregateRel aggregate, RelNode input) throws InvalidRelException {

  RelTraitSet traits = newTraitSet(Prel.DRILL_PHYSICAL, input.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE));
  RelNode newInput = convert(input, traits);

  HashAggPrel phase1Agg = new HashAggPrel(
      aggregate.getCluster(),
      traits,
      newInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of2);

  HashToRandomExchangePrel exch =
      new HashToRandomExchangePrel(phase1Agg.getCluster(), phase1Agg.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(distOnAllKeys),
          phase1Agg, ImmutableList.copyOf(getDistributionField(aggregate, true)));

  ImmutableBitSet newGroupSet = remapGroupSet(aggregate.getGroupSet());
  List<ImmutableBitSet> newGroupSets = Lists.newArrayList();
  for (ImmutableBitSet groupSet : aggregate.getGroupSets()) {
    newGroupSets.add(remapGroupSet(groupSet));
  }

  return new HashAggPrel(
      aggregate.getCluster(),
      exch.getTraitSet(),
      exch,
      aggregate.indicator,
      newGroupSet,
      newGroupSets,
      phase1Agg.getPhase2AggCalls(),
      OperatorPhase.PHASE_2of2);
}
 
Example #27
Source File: MergeJoinPrule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
  final JoinRel join = (JoinRel) 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, left, right, collationLeft, collationRight, hashSingleKey);
    } else {
      if (checkBroadcastConditions(call.getPlanner(), join, left, right)) {
        createBroadcastPlan(call, join, join.getCondition(), left, right, collationLeft, collationRight);
      }
    }

  } catch (InvalidRelException | UnsupportedRelOperatorException e) {
    tracer.warn(e.toString());
  }
}
 
Example #28
Source File: HashAggPrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  try {
    return new HashAggPrel(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls,
        this.getOperatorPhase());
  } catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
Example #29
Source File: HashAggPrel.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static HashAggPrel create(RelOptCluster cluster,
                   RelTraitSet traits,
                   RelNode child,
                   boolean indicator,
                   ImmutableBitSet groupSet,
                   List<ImmutableBitSet> groupSets,
                   List<AggregateCall> aggCalls,
                   OperatorPhase phase) throws InvalidRelException {
  final RelTraitSet adjustedTraits = AggPrelBase.adjustTraits(traits, child, groupSet);
  return new HashAggPrel(cluster, adjustedTraits, child, indicator, groupSet, groupSets, aggCalls, phase);
}
 
Example #30
Source File: HashJoinPrule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void createDistBothPlan(RelOptRuleCall call, JoinRel join,
                                RelNode left, RelNode right,
                                RelCollation collationLeft, RelCollation collationRight,
                                DistributionTrait hashLeftPartition, DistributionTrait hashRightPartition) throws InvalidRelException {
  RelTraitSet traitsLeft = left.getTraitSet().plus(Prel.PHYSICAL).plus(hashLeftPartition);
  RelTraitSet traitsRight = right.getTraitSet().plus(Prel.PHYSICAL).plus(hashRightPartition);

  final RelNode convertedLeft = convert(left, traitsLeft);
  final RelNode convertedRight = convert(right, traitsRight);

  call.transformTo(PrelUtil.addPartialProjectOnJoin(HashJoinPrel.create(join.getCluster(), traitsLeft,
    convertedLeft, convertedRight, join.getCondition(),
    join.getJoinType(), null), join.getProjectedFields()));
}