Examples of JoinRelBase


Examples of org.eigenbase.rel.JoinRelBase

  }

  //~ Methods ----------------------------------------------------------------

  public void onMatch(final RelOptRuleCall call) {
    final JoinRelBase topJoin = call.rel(0);
    final JoinRelBase bottomJoin = call.rel(1);
    final RelNode relA = bottomJoin.getLeft();
    final RelNode relB = bottomJoin.getRight();
    final RelSubset relC = call.rel(2);
    final RelOptCluster cluster = topJoin.getCluster();
    final RexBuilder rexBuilder = cluster.getRexBuilder();

    if (relC.getConvention() != relA.getConvention()) {
      // relC could have any trait-set. But if we're matching say
      // EnumerableConvention, we're only interested in enumerable subsets.
      return;
    }

    //        topJoin
    //        /     \
    //   bottomJoin  C
    //    /    \
    //   A      B

    final int aCount = relA.getRowType().getFieldCount();
    final int bCount = relB.getRowType().getFieldCount();
    final int cCount = relC.getRowType().getFieldCount();
    final BitSet aBitSet = BitSets.range(0, aCount);
    final BitSet bBitSet = BitSets.range(aCount, aCount + bCount);

    if (!topJoin.getSystemFieldList().isEmpty()) {
      // FIXME Enable this rule for joins with system fields
      return;
    }

    // If either join is not inner, we cannot proceed.
    // (Is this too strict?)
    if (topJoin.getJoinType() != JoinRelType.INNER
        || bottomJoin.getJoinType() != JoinRelType.INNER) {
      return;
    }

    // Goal is to transform to
    //
    //       newTopJoin
    //        /     \
    //       A   newBottomJoin
    //               /    \
    //              B      C

    // Split the condition of topJoin and bottomJoin into a conjunctions. A
    // condition can be pushed down if it does not use columns from A.
    final List<RexNode> top = Lists.newArrayList();
    final List<RexNode> bottom = Lists.newArrayList();
    PushJoinThroughJoinRule.split(topJoin.getCondition(), aBitSet, top, bottom);
    PushJoinThroughJoinRule.split(bottomJoin.getCondition(), aBitSet, top,
        bottom);

    // Mapping for moving conditions from topJoin or bottomJoin to
    // newBottomJoin.
    // target: | B | C      |
    // source: | A       | B | C      |
    final Mappings.TargetMapping bottomMapping =
        Mappings.createShiftMapping(
            aCount + bCount + cCount,
            0, aCount, bCount,
            bCount, aCount + bCount, cCount);
    final List<RexNode> newBottomList = Lists.newArrayList();
    new RexPermuteInputsShuttle(bottomMapping, relB, relC)
        .visitList(bottom, newBottomList);
    RexNode newBottomCondition =
        RexUtil.composeConjunction(rexBuilder, newBottomList, false);

    final JoinRelBase newBottomJoin =
        bottomJoin.copy(bottomJoin.getTraitSet(), newBottomCondition, relB,
            relC, JoinRelType.INNER, false);

    // Condition for newTopJoin consists of pieces from bottomJoin and topJoin.
    // Field ordinals do not need to be changed.
    RexNode newTopCondition =
        RexUtil.composeConjunction(rexBuilder, top, false);
    final JoinRelBase newTopJoin =
        topJoin.copy(topJoin.getTraitSet(), newTopCondition, relA,
            newBottomJoin, JoinRelType.INNER, false);

    call.transformTo(newTopJoin);
  }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final ProjectRelBase project = call.rel(0);
    final JoinRelBase join = call.rel(1);
    final RelNode left = call.rel(2);
    final AggregateRelBase aggregate = call.rel(3);
    final BitSet bits = RelOptUtil.InputFinder.bits(project.getProjects(),
        null);
    final BitSet rightBits = BitSets.range(left.getRowType().getFieldCount(),
        join.getRowType().getFieldCount());
    if (bits.intersects(rightBits)) {
      return;
    }
    final JoinInfo joinInfo = join.analyzeCondition();
    if (!joinInfo.rightSet().equals(BitSets.range(aggregate.getGroupCount()))) {
      // Rule requires that aggregate key to be the same as the join key.
      // By the way, neither a super-set nor a sub-set would work.
      return;
    }
    final List<Integer> newRightKeys = Lists.newArrayList();
    final IntList aggregateKeys = BitSets.toList(aggregate.getGroupSet());
    for (int key : joinInfo.rightKeys) {
      newRightKeys.add(aggregateKeys.get(key));
    }
    final SemiJoinRel semiJoin =
        new SemiJoinRel(join.getCluster(),
            join.getCluster().traitSetOf(Convention.NONE),
            left, aggregate.getChild(),
            join.getCondition(), joinInfo.leftKeys,
            ImmutableIntList.copyOf(newRightKeys));
    final ProjectRelBase newProject =
        project.copy(project.getTraitSet(), semiJoin, project.getProjects(),
            project.getRowType());
    call.transformTo(RemoveTrivialProjectRule.strip(newProject));
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

    this.filterFactory = filterFactory;
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    JoinRelBase join = call.rel(0);
    RelOptPredicateList preds = RelMetadataQuery.getPulledUpPredicates(join);

    if (preds.leftInferredPredicates.isEmpty()
        && preds.rightInferredPredicates.isEmpty()) {
      return;
    }

    RexBuilder rB = join.getCluster().getRexBuilder();
    RelNode lChild = join.getLeft();
    RelNode rChild = join.getRight();

    if (preds.leftInferredPredicates.size() > 0) {
      RelNode curr = lChild;
      lChild = filterFactory.createFilter(lChild,
          RexUtil.composeConjunction(rB, preds.leftInferredPredicates, false));
      call.getPlanner().onCopy(curr, lChild);
    }

    if (preds.rightInferredPredicates.size() > 0) {
      RelNode curr = rChild;
      rChild = filterFactory.createFilter(rChild,
          RexUtil.composeConjunction(rB, preds.rightInferredPredicates, false));
      call.getPlanner().onCopy(curr, rChild);
    }

    RelNode newRel = join.copy(join.getTraitSet(), join.getCondition(),
        lChild, rChild, join.getJoinType(), join.isSemiJoinDone());
    call.getPlanner().onCopy(join, newRel);

    call.transformTo(newRel);
  }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

    if (r instanceof TableAccessRelBase) {
      TableAccessRelBase f = (TableAccessRelBase) r;
      s = new Schema(f);
      ast = ASTBuilder.table(f);
    } else if (r instanceof JoinRelBase) {
      JoinRelBase join = (JoinRelBase) r;
      QueryBlockInfo left = convertSource(join.getLeft());
      QueryBlockInfo right = convertSource(join.getRight());
      s = new Schema(left.schema, right.schema);
      ASTNode cond = join.getCondition().accept(new RexVisitor(s));
      boolean semiJoin = join instanceof SemiJoinRel;
      ast = ASTBuilder.join(left.ast, right.ast, join.getJoinType(), cond, semiJoin);
      if (semiJoin)
        s = left.schema;
    } else if (r instanceof UnionRelBase) {
      RelNode leftInput = ((UnionRelBase) r).getInput(0);
      RelNode rightInput = ((UnionRelBase) r).getInput(1);
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

    }

    @Override
    public void onMatch(RelOptRuleCall call) {
      FilterRelBase filter = call.rel(0);
      JoinRelBase join = call.rel(1);
      super.perform(call, filter, join);
    }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

          HiveProjectRel.DEFAULT_PROJECT_FACTORY);
    }

    @Override
    public void onMatch(RelOptRuleCall call) {
      JoinRelBase join = call.rel(0);
      super.perform(call, null, join);
    }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

    this.filterFactory = filterFactory;
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    JoinRelBase join = call.rel(0);
    RelOptPredicateList preds = RelMetadataQuery.getPulledUpPredicates(join);

    if (preds.leftInferredPredicates.isEmpty()
        && preds.rightInferredPredicates.isEmpty()) {
      return;
    }

    RexBuilder rB = join.getCluster().getRexBuilder();
    RelNode lChild = join.getLeft();
    RelNode rChild = join.getRight();

    if (preds.leftInferredPredicates.size() > 0) {
      RelNode curr = lChild;
      lChild = filterFactory.createFilter(lChild,
          RexUtil.composeConjunction(rB, preds.leftInferredPredicates, false));
      call.getPlanner().onCopy(curr, lChild);
    }

    if (preds.rightInferredPredicates.size() > 0) {
      RelNode curr = rChild;
      rChild = filterFactory.createFilter(rChild,
          RexUtil.composeConjunction(rB, preds.rightInferredPredicates, false));
      call.getPlanner().onCopy(curr, rChild);
    }

    RelNode newRel = join.copy(join.getTraitSet(), join.getCondition(),
        lChild, rChild, join.getJoinType(), join.isSemiJoinDone());
    call.getPlanner().onCopy(join, newRel);

    call.transformTo(newRel);
  }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

  }

  //~ Methods ----------------------------------------------------------------

  public void onMatch(final RelOptRuleCall call) {
    final JoinRelBase topJoin = call.rel(0);
    final JoinRelBase bottomJoin = call.rel(1);
    final RelNode relA = bottomJoin.getLeft();
    final RelNode relB = bottomJoin.getRight();
    final RelSubset relC = call.rel(2);
    final RelOptCluster cluster = topJoin.getCluster();
    final RexBuilder rexBuilder = cluster.getRexBuilder();

    if (relC.getConvention() != relA.getConvention()) {
      // relC could have any trait-set. But if we're matching say
      // EnumerableConvention, we're only interested in enumerable subsets.
      return;
    }

    //        topJoin
    //        /     \
    //   bottomJoin  C
    //    /    \
    //   A      B

    final int aCount = relA.getRowType().getFieldCount();
    final int bCount = relB.getRowType().getFieldCount();
    final int cCount = relC.getRowType().getFieldCount();
    final BitSet aBitSet = BitSets.range(0, aCount);
    final BitSet bBitSet = BitSets.range(aCount, aCount + bCount);

    if (!topJoin.getSystemFieldList().isEmpty()) {
      // FIXME Enable this rule for joins with system fields
      return;
    }

    // If either join is not inner, we cannot proceed.
    // (Is this too strict?)
    if (topJoin.getJoinType() != JoinRelType.INNER
        || bottomJoin.getJoinType() != JoinRelType.INNER) {
      return;
    }

    // Goal is to transform to
    //
    //       newTopJoin
    //        /     \
    //       A   newBottomJoin
    //               /    \
    //              B      C

    // Split the condition of topJoin and bottomJoin into a conjunctions. A
    // condition can be pushed down if it does not use columns from A.
    final List<RexNode> top = Lists.newArrayList();
    final List<RexNode> bottom = Lists.newArrayList();
    PushJoinThroughJoinRule.split(topJoin.getCondition(), aBitSet, top, bottom);
    PushJoinThroughJoinRule.split(bottomJoin.getCondition(), aBitSet, top,
        bottom);

    // Mapping for moving conditions from topJoin or bottomJoin to
    // newBottomJoin.
    // target: | B | C      |
    // source: | A       | B | C      |
    final Mappings.TargetMapping bottomMapping =
        Mappings.createShiftMapping(
            aCount + bCount + cCount,
            0, aCount, bCount,
            bCount, aCount + bCount, cCount);
    final List<RexNode> newBottomList = Lists.newArrayList();
    new RexPermuteInputsShuttle(bottomMapping, relB, relC)
        .visitList(bottom, newBottomList);
    RexNode newBottomCondition =
        RexUtil.composeConjunction(rexBuilder, newBottomList, false);

    final JoinRelBase newBottomJoin =
        bottomJoin.copy(bottomJoin.getTraitSet(), newBottomCondition, relB,
            relC, JoinRelType.INNER, false);

    // Condition for newTopJoin consists of pieces from bottomJoin and topJoin.
    // Field ordinals do not need to be changed.
    RexNode newTopCondition =
        RexUtil.composeConjunction(rexBuilder, top, false);
    final JoinRelBase newTopJoin =
        topJoin.copy(topJoin.getTraitSet(), newTopCondition, relA,
            newBottomJoin, JoinRelType.INNER, false);

    call.transformTo(newTopJoin);
  }
View Full Code Here

Examples of org.eigenbase.rel.JoinRelBase

  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final ProjectRelBase project = call.rel(0);
    final JoinRelBase join = call.rel(1);
    final RelNode left = call.rel(2);
    final AggregateRelBase aggregate = call.rel(3);
    final BitSet bits = RelOptUtil.InputFinder.bits(project.getProjects(),
        null);
    final BitSet rightBits = BitSets.range(left.getRowType().getFieldCount(),
        join.getRowType().getFieldCount());
    if (bits.intersects(rightBits)) {
      return;
    }
    final JoinInfo joinInfo = join.analyzeCondition();
    if (!joinInfo.rightSet().equals(BitSets.range(aggregate.getGroupCount()))) {
      // Rule requires that aggregate key to be the same as the join key.
      // By the way, neither a super-set nor a sub-set would work.
      return;
    }
    final List<Integer> newRightKeys = Lists.newArrayList();
    final IntList aggregateKeys = BitSets.toList(aggregate.getGroupSet());
    for (int key : joinInfo.rightKeys) {
      newRightKeys.add(aggregateKeys.get(key));
    }
    final SemiJoinRel semiJoin =
        new SemiJoinRel(join.getCluster(),
            join.getCluster().traitSetOf(Convention.NONE),
            left, aggregate.getChild(),
            join.getCondition(), joinInfo.leftKeys,
            ImmutableIntList.copyOf(newRightKeys));
    final ProjectRelBase newProject =
        project.copy(project.getTraitSet(), semiJoin, project.getProjects(),
            project.getRowType());
    call.transformTo(RemoveTrivialProjectRule.strip(newProject));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.