Package org.eigenbase.rel

Examples of org.eigenbase.rel.JoinRel


        "DrillJoinRule");
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final JoinRel join = (JoinRel) call.rel(0);
    final RelNode left = call.rel(1);
    final RelNode right = call.rel(2);
    final RelTraitSet traits = join.getTraitSet().plus(DrillRel.CONVENTION);

    final RelNode convertedLeft = convert(left, traits);
    final RelNode convertedRight = convert(right, traits);
    try {
      call.transformTo(new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, join.getCondition(),
          join.getJoinType()));
    } catch (InvalidRelException e) {
      tracer.warning(e.toString());
    }
  }
View Full Code Here


        "DrillJoinRule");
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final JoinRel join = (JoinRel) call.rel(0);
    final RelNode left = join.getLeft();
    final RelNode right = join.getRight();
    final RelTraitSet traits = join.getTraitSet().plus(DrillRel.DRILL_LOGICAL);

    final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL));
    final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL));

    List<Integer> leftKeys = Lists.newArrayList();
    List<Integer> rightKeys = Lists.newArrayList();
    int numLeftFields = convertedLeft.getRowType().getFieldCount();

    boolean addFilter = false;
    RexNode origJoinCondition = join.getCondition();
    RexNode newJoinCondition = origJoinCondition;

    RexNode remaining = RelOptUtil.splitJoinCondition(convertedLeft, convertedRight, origJoinCondition, leftKeys, rightKeys);
    boolean hasEquijoins = (leftKeys.size() == rightKeys.size() && leftKeys.size() > 0) ? true : false;

    // If the join involves equijoins and non-equijoins, then we can process the non-equijoins through
    // a filter right after the join
    if (! remaining.isAlwaysTrue()) {
      if (hasEquijoins) {
        addFilter = true;
        List<RexNode> equijoinList = Lists.newArrayList();
        List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
        List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();
        RexBuilder builder = join.getCluster().getRexBuilder();

        for (int i=0; i < leftKeys.size(); i++) {
          int leftKeyOrdinal = leftKeys.get(i).intValue();
          int rightKeyOrdinal = rightKeys.get(i).intValue();

          equijoinList.add(builder.makeCall(
              SqlStdOperatorTable.EQUALS,
              builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
              builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
             ) );
        }
        newJoinCondition = RexUtil.composeConjunction(builder, equijoinList, false);
      } else {
//        tracer.warning("Non-equijoins are only supported in the presence of an equijoin.");
        return;
      }
    }
    //else {
    //
    //  return;
    // }

    try {
      if (!addFilter) {
       RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, origJoinCondition,
                                         join.getJoinType(), leftKeys, rightKeys, false);
       call.transformTo(joinRel);
      } else {
        RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, newJoinCondition,
                                           join.getJoinType(), leftKeys, rightKeys, false);
        call.transformTo(new DrillFilterRel(join.getCluster(), traits, joinRel, remaining));
      }
    } catch (InvalidRelException e) {
      tracer.warning(e.toString());
    }
  }
View Full Code Here

        "DrillJoinRule");
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final JoinRel join = (JoinRel) call.rel(0);
    final RelNode left = join.getLeft();
    final RelNode right = join.getRight();
    final RelTraitSet traits = join.getTraitSet().plus(DrillRel.DRILL_LOGICAL);

    final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL));
    final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL));

    List<Integer> leftKeys = Lists.newArrayList();
    List<Integer> rightKeys = Lists.newArrayList();
    int numLeftFields = convertedLeft.getRowType().getFieldCount();

    boolean addFilter = false;
    RexNode origJoinCondition = join.getCondition();
    RexNode newJoinCondition = origJoinCondition;

    RexNode remaining = RelOptUtil.splitJoinCondition(convertedLeft, convertedRight, origJoinCondition, leftKeys, rightKeys);
    boolean hasEquijoins = (leftKeys.size() == rightKeys.size() && leftKeys.size() > 0) ? true : false;

    // If the join involves equijoins and non-equijoins, then we can process the non-equijoins through
    // a filter right after the join
    // DRILL-1337: We can only pull up a non-equivjoin filter for INNER join.
    // For OUTER join, pulling up a non-eqivjoin filter will lead to incorrectly discarding qualified rows.
    if (! remaining.isAlwaysTrue()) {
      if (hasEquijoins && join.getJoinType()== JoinRelType.INNER) {
        addFilter = true;
        List<RexNode> equijoinList = Lists.newArrayList();
        List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
        List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();
        RexBuilder builder = join.getCluster().getRexBuilder();

        for (int i=0; i < leftKeys.size(); i++) {
          int leftKeyOrdinal = leftKeys.get(i).intValue();
          int rightKeyOrdinal = rightKeys.get(i).intValue();

          equijoinList.add(builder.makeCall(
              SqlStdOperatorTable.EQUALS,
              builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
              builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
             ) );
        }
        newJoinCondition = RexUtil.composeConjunction(builder, equijoinList, false);
      } else {
//        tracer.warning("Non-equijoins are only supported in the presence of an equijoin.");
        return;
      }
    }
    //else {
    //
    //  return;
    // }

    try {
      if (!addFilter) {
       RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, origJoinCondition,
                                         join.getJoinType(), leftKeys, rightKeys, false);
       call.transformTo(joinRel);
      } else {
        RelNode joinRel = new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, newJoinCondition,
                                           join.getJoinType(), leftKeys, rightKeys, false);
        call.transformTo(new DrillFilterRel(join.getCluster(), traits, joinRel, remaining));
      }
    } catch (InvalidRelException e) {
      tracer.warning(e.toString());
    }
  }
View Full Code Here

    }

  @Override
  public void onMatch( RelOptRuleCall call )
    {
    final JoinRel join = call.rel( 0 );
    final RelNode left = call.rel( 1 );
    final RelNode right = call.rel( 2 );

    if( !join.getVariablesStopped().isEmpty() )
      {
      LOG.debug( "variables stopped not supported by this rule" );
      return;
      }

    // split into equi join
    final List<RexNode> leftExprs = new ArrayList<RexNode>();
    final List<RexNode> rightExprs = new ArrayList<RexNode>();

    RexNode remainder =
      RelOptUtil.splitJoinCondition(
        Collections.<RelDataTypeField>emptyList(),
        left,
        right,
        join.getCondition(),
        leftExprs,
        rightExprs,
        new ArrayList<Integer>(),
        null );

    if( remainder != null )
      {
      LOG.debug( "cannot handle non-equi join" );
      return;
      }

    final List<Integer> leftKeys = new ArrayList<Integer>();
    final List<Integer> rightKeys = new ArrayList<Integer>();
    final List<Integer> outputProj = new ArrayList<Integer>();
    final RelNode[] inputRels = {left, right};

    RelOptUtil.projectJoinInputs(
      inputRels,
      leftExprs,
      rightExprs,
      0,
      leftKeys,
      rightKeys,
      outputProj );

    final RelNode newLeft = inputRels[ 0 ];
    final RelNode newRight = inputRels[ 1 ];
    final RelTraitSet traits = join.getCluster().traitSetOf( Cascading.CONVENTION );
    final RexNode newCondition = createCondition( join.getCluster().getRexBuilder(), newLeft, leftKeys, newRight, rightKeys );

    final CascadingJoinRel newJoin = new CascadingJoinRel( join.getCluster(), traits, convert( newLeft, traits ),
      convert( newRight, traits ), newCondition, join.getJoinType(), join.getVariablesStopped(), 0 );

    final RelNode newRel = convert( RelOptUtil.createProjectJoinRel( outputProj, newJoin ), traits );

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

TOP

Related Classes of org.eigenbase.rel.JoinRel

Copyright © 2018 www.massapicom. 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.