当前位置: 首页>>代码示例>>Java>>正文


Java Join.copy方法代码示例

本文整理汇总了Java中org.apache.calcite.rel.core.Join.copy方法的典型用法代码示例。如果您正苦于以下问题:Java Join.copy方法的具体用法?Java Join.copy怎么用?Java Join.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.rel.core.Join的用法示例。


在下文中一共展示了Join.copy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: swap

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
/**
 * Returns a relational expression with the inputs switched round. Does not
 * modify <code>join</code>. Returns null if the join cannot be swapped (for
 * example, because it is an outer join).
 *
 * @param join           join to be swapped
 * @param swapOuterJoins whether outer joins should be swapped
 * @return swapped join if swapping possible; else null
 */
public static RelNode swap(Join join, boolean swapOuterJoins) {
  final JoinRelType joinType = join.getJoinType();
  if (!swapOuterJoins && joinType != JoinRelType.INNER) {
    return null;
  }
  final RexBuilder rexBuilder = join.getCluster().getRexBuilder();
  final RelDataType leftRowType = join.getLeft().getRowType();
  final RelDataType rightRowType = join.getRight().getRowType();
  final VariableReplacer variableReplacer =
      new VariableReplacer(rexBuilder, leftRowType, rightRowType);
  final RexNode oldCondition = join.getCondition();
  RexNode condition = variableReplacer.go(oldCondition);

  // NOTE jvs 14-Mar-2006: We preserve attribute semiJoinDone after the
  // swap.  This way, we will generate one semijoin for the original
  // join, and one for the swapped join, and no more.  This
  // doesn't prevent us from seeing any new combinations assuming
  // that the planner tries the desired order (semijoins after swaps).
  Join newJoin =
      join.copy(join.getTraitSet(), condition, join.getRight(),
          join.getLeft(), joinType.swap(), join.isSemiJoinDone());
  final List<RexNode> exps =
      RelOptUtil.createSwappedJoinExprs(newJoin, join, true);
  return RelOptUtil.createProject(
      newJoin,
      exps,
      join.getRowType().getFieldNames(),
      true);
}
 
开发者ID:apache,项目名称:calcite,代码行数:39,代码来源:JoinCommuteRule.java

示例2: onMatch

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Join join = call.rel(0);

  if (join.getJoinType() != JoinRelType.INNER) {
    return;
  }

  if (join.getCondition().isAlwaysTrue()) {
    return;
  }

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

  // NOTE jvs 14-Mar-2006:  See JoinCommuteRule for why we
  // preserve attribute semiJoinDone here.

  RelNode cartesianJoinRel =
      join.copy(
          join.getTraitSet(),
          join.getCluster().getRexBuilder().makeLiteral(true),
          join.getLeft(),
          join.getRight(),
          join.getJoinType(),
          join.isSemiJoinDone());

  final RelFactories.FilterFactory factory =
      RelFactories.DEFAULT_FILTER_FACTORY;
  RelNode filterRel =
      factory.createFilter(cartesianJoinRel, join.getCondition());

  call.transformTo(filterRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:JoinExtractFilterRule.java

示例3: onMatch

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  Join origJoinRel = call.rel(0);
  if (origJoinRel.isSemiJoinDone()) {
    return;
  }

  // can't process outer joins using semijoins
  if (origJoinRel.getJoinType() != JoinRelType.INNER) {
    return;
  }

  // determine if we have a valid join condition
  final JoinInfo joinInfo = origJoinRel.analyzeCondition();
  if (joinInfo.leftKeys.size() == 0) {
    return;
  }

  RelNode semiJoin =
      SemiJoin.create(origJoinRel.getLeft(),
          origJoinRel.getRight(),
          origJoinRel.getCondition(),
          joinInfo.leftKeys,
          joinInfo.rightKeys);

  RelNode newJoinRel =
      origJoinRel.copy(
          origJoinRel.getTraitSet(),
          origJoinRel.getCondition(),
          semiJoin,
          origJoinRel.getRight(),
          JoinRelType.INNER,
          true);

  call.transformTo(newJoinRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:JoinAddRedundantSemiJoinRule.java

示例4: onMatch

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Join joinRel = call.rel(0);
  final RelNode otherNode;
  final Calc calc;

  final RelNode leftJoinChild;
  final RelNode rightJoinChild;

  if (call.rel(1) instanceof Calc) {
    otherNode = call.rel(2);
    calc = call.rel(1);
    rightJoinChild = otherNode;
    leftJoinChild = calc.getInput();
  } else {
    otherNode = call.rel(1);
    calc = call.rel(2);
    rightJoinChild = calc.getInput();
    leftJoinChild = otherNode;
  }
  /**
   * Currently not supporting calc which doesnot
   * project star (all the columns of input)
   * or has aggregates.
   */
  if (!isStar(calc.getProgram())
      || calc.getProgram().containsAggs()) {
    return;
  }

  final List<RelDataTypeField> origFields =
      calc.getRowType().getFieldList();
  final int[] adjustments = new int[calc.getProgram().getExprCount()];
  if (rightJoinChild == calc.getInput()) {
    int offset = leftJoinChild.getRowType().getFieldList().size();
    for (int i = 0; i < origFields.size(); i++) {
      adjustments[i] = offset;
    }
  }
  Join newJoinRel =
      joinRel.copy(joinRel.getTraitSet(), joinRel.getCondition(),
          leftJoinChild, rightJoinChild, joinRel.getJoinType(),
          joinRel.isSemiJoinDone());

  RexProgramBuilder topProgramBuilder =
      new RexProgramBuilder(
          joinRel.getRowType(),
          joinRel.getCluster().getRexBuilder());
  topProgramBuilder.addIdentity();
  final RelOptUtil.RexInputConverter rexInputConverter =
      new RelOptUtil.RexInputConverter(calc.getCluster().getRexBuilder(),
          origFields,
          joinRel.getRowType().getFieldList(),
          adjustments);
  if (calc.getProgram().getCondition() != null) {
    RexNode cond =
        calc.getProgram().expandLocalRef(calc.getProgram().getCondition());
    final RexLocalRef rexLocalRef =
        topProgramBuilder.addExpr(cond.accept(rexInputConverter));
    topProgramBuilder.addCondition(rexLocalRef);
  }
  Calc newCalcRel =
      calc.copy(calc.getTraitSet(), newJoinRel, topProgramBuilder.getProgram());

  call.transformTo(newCalcRel);
}
 
开发者ID:qubole,项目名称:quark,代码行数:66,代码来源:JoinCalcTransposeRule.java

示例5: onMatch

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  Project origProj = call.rel(0);
  final Join join = call.rel(1);

  if (join instanceof SemiJoin) {
    return; // TODO: support SemiJoin
  }
  // locate all fields referenced in the projection and join condition;
  // determine which inputs are referenced in the projection and
  // join condition; if all fields are being referenced and there are no
  // special expressions, no point in proceeding any further
  PushProjector pushProject =
      new PushProjector(
          origProj,
          join.getCondition(),
          join,
          preserveExprCondition,
          call.builder());
  if (pushProject.locateAllRefs()) {
    return;
  }

  // create left and right projections, projecting only those
  // fields referenced on each side
  RelNode leftProjRel =
      pushProject.createProjectRefsAndExprs(
          join.getLeft(),
          true,
          false);
  RelNode rightProjRel =
      pushProject.createProjectRefsAndExprs(
          join.getRight(),
          true,
          true);

  // convert the join condition to reference the projected columns
  RexNode newJoinFilter = null;
  int[] adjustments = pushProject.getAdjustments();
  if (join.getCondition() != null) {
    List<RelDataTypeField> projJoinFieldList = new ArrayList<>();
    projJoinFieldList.addAll(
        join.getSystemFieldList());
    projJoinFieldList.addAll(
        leftProjRel.getRowType().getFieldList());
    projJoinFieldList.addAll(
        rightProjRel.getRowType().getFieldList());
    newJoinFilter =
        pushProject.convertRefsAndExprs(
            join.getCondition(),
            projJoinFieldList,
            adjustments);
  }

  // create a new join with the projected children
  Join newJoinRel =
      join.copy(
          join.getTraitSet(),
          newJoinFilter,
          leftProjRel,
          rightProjRel,
          join.getJoinType(),
          join.isSemiJoinDone());

  // put the original project on top of the join, converting it to
  // reference the modified projection list
  RelNode topProject =
      pushProject.createNewProject(newJoinRel, adjustments);

  call.transformTo(topProject);
}
 
开发者ID:apache,项目名称:calcite,代码行数:71,代码来源:ProjectJoinTransposeRule.java

示例6: onMatch

import org.apache.calcite.rel.core.Join; //导入方法依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
  final Sort sort = call.rel(0);
  final Join join = call.rel(1);

  // We create a new sort operator on the corresponding input
  final RelNode newLeftInput;
  final RelNode newRightInput;
  final RelMetadataQuery mq = call.getMetadataQuery();
  if (join.getJoinType() == JoinRelType.LEFT) {
    // If the input is already sorted and we are not reducing the number of tuples,
    // we bail out
    if (RelMdUtil.checkInputForCollationAndLimit(mq, join.getLeft(),
        sort.getCollation(), sort.offset, sort.fetch)) {
      return;
    }
    newLeftInput = sort.copy(sort.getTraitSet(), join.getLeft(), sort.getCollation(),
        sort.offset, sort.fetch);
    newRightInput = join.getRight();
  } else {
    final RelCollation rightCollation =
        RelCollationTraitDef.INSTANCE.canonize(
            RelCollations.shift(sort.getCollation(),
                -join.getLeft().getRowType().getFieldCount()));
    // If the input is already sorted and we are not reducing the number of tuples,
    // we bail out
    if (RelMdUtil.checkInputForCollationAndLimit(mq, join.getRight(),
        rightCollation, sort.offset, sort.fetch)) {
      return;
    }
    newLeftInput = join.getLeft();
    newRightInput = sort.copy(sort.getTraitSet().replace(rightCollation),
        join.getRight(), rightCollation, sort.offset, sort.fetch);
  }
  // We copy the join and the top sort operator
  final RelNode joinCopy = join.copy(join.getTraitSet(), join.getCondition(), newLeftInput,
      newRightInput, join.getJoinType(), join.isSemiJoinDone());
  final RelNode sortCopy = sort.copy(sort.getTraitSet(), joinCopy, sort.getCollation(),
      sort.offset, sort.fetch);

  call.transformTo(sortCopy);
}
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:SortJoinTransposeRule.java


注:本文中的org.apache.calcite.rel.core.Join.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。