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


Java RelBuilder.project方法代码示例

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


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

示例1: createUnion

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder,
    RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) {
  relBuilder.push(unionInputQuery);
  relBuilder.push(unionInputView);
  relBuilder.union(true);
  List<RexNode> exprList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
  List<String> nameList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
  for (int i = 0; i < relBuilder.peek().getRowType().getFieldCount(); i++) {
    // We can take unionInputQuery as it is query based.
    RelDataTypeField field = unionInputQuery.getRowType().getFieldList().get(i);
    exprList.add(
        rexBuilder.ensureType(
            field.getType(),
            rexBuilder.makeInputRef(relBuilder.peek(), i),
            true));
    nameList.add(field.getName());
  }
  relBuilder.project(exprList, nameList);
  return relBuilder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:AbstractMaterializedViewRule.java

示例2: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Aggregate aggregate = call.rel(0);
  final RelNode input = call.rel(1);
  if (!aggregate.getAggCallList().isEmpty() || aggregate.indicator) {
    return;
  }
  final RelMetadataQuery mq = call.getMetadataQuery();
  if (!SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()))) {
    return;
  }
  // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on
  // which the input is unique, i.e. contain a key) and has no aggregate
  // functions. It can be removed.
  final RelNode newInput = convert(input, aggregate.getTraitSet().simplify());

  // If aggregate was projecting a subset of columns, add a project for the
  // same effect.
  final RelBuilder relBuilder = call.builder();
  relBuilder.push(newInput);
  if (newInput.getRowType().getFieldCount()
      > aggregate.getRowType().getFieldCount()) {
    relBuilder.project(relBuilder.fields(aggregate.getGroupSet().asList()));
  }
  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:AggregateRemoveRule.java

示例3: createProject

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
 * Creates a relational expression which projects an array of expressions,
 * and optionally optimizes.
 *
 * <p>The result may not be a
 * {@link org.apache.calcite.rel.logical.LogicalProject}. If the
 * projection is trivial, <code>child</code> is returned directly; and future
 * versions may return other formulations of expressions, such as
 * {@link org.apache.calcite.rel.logical.LogicalCalc}.
 *
 * @param child          input relational expression
 * @param exprs          list of expressions for the input columns
 * @param fieldNames     aliases of the expressions, or null to generate
 * @param optimize       Whether to return <code>child</code> unchanged if the
 *                       projections are trivial.
 * @param relBuilder     Factory to create project operators
 */
public static RelNode createProject(
    RelNode child,
    List<? extends RexNode> exprs,
    List<String> fieldNames,
    boolean optimize,
    RelBuilder relBuilder) {
  final RelOptCluster cluster = child.getCluster();
  final RelDataType rowType =
      RexUtil.createStructType(cluster.getTypeFactory(), exprs,
          fieldNames, SqlValidatorUtil.F_SUGGESTER);
  if (optimize
      && RexUtil.isIdentity(exprs, child.getRowType())) {
    if (child instanceof Project && fieldNames != null) {
      // Rename columns of child projection if desired field names are given.
      Project childProject = (Project) child;
      child = childProject.copy(childProject.getTraitSet(),
          childProject.getInput(), childProject.getProjects(), rowType);
    }
    return child;
  }
  relBuilder.push(child);
  relBuilder.project(exprs, rowType.getFieldNames(), !optimize);
  return relBuilder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:RelOptUtil.java

示例4: updateScan

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public RelNode updateScan(IncrementallyUpdateable scan) {
  if (UPDATE_COLUMN.equals(refreshColumn)) {
    return scan;
  }

  RelDataTypeField refreshField = scan.getRowType().getField(refreshColumn, false, false);

  if(refreshField == null){
    throw UserException.dataReadError()
      .message("Table does not include column identified for incremental update of name '%s'.", refreshField.getName())
      .build(logger);
  } else if(refreshField.getType().getSqlTypeName() != SqlTypeName.BIGINT){
    throw UserException.dataReadError()
      .message("Dremio only supports incremental column update on BIGINT types. The identified column was of type %s.", refreshField.getType().getSqlTypeName())
      .build(logger);
  }

  final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(scan.getCluster());

  relBuilder.push(scan);

  List<String> newFieldNames = ImmutableList.<String>builder().addAll(scan.getRowType().getFieldNames()).add(UPDATE_COLUMN).build();

  Iterable<RexInputRef> projects = FluentIterable.from(scan.getRowType().getFieldNames())
    .transform(new Function<String, RexInputRef>() {
      @Override
      public RexInputRef apply(String fieldName) {
        return relBuilder.field(fieldName);
      }
    })
    .append(relBuilder.field(refreshColumn));

  relBuilder.project(projects, newFieldNames);

  return relBuilder.build();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:37,代码来源:IncrementalUpdateUtils.java

示例5: visit

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public RelNode visit(LogicalAggregate aggregate) {
  RelNode input = aggregate.getInput().accept(this);


  final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(aggregate.getCluster());
  relBuilder.push(input);

  RelDataType incomingRowType = input.getRowType();
  RelDataTypeField modField = incomingRowType.getField(UPDATE_COLUMN, false, false);
  ImmutableBitSet newGroupSet = aggregate.getGroupSet().rebuild().set(modField.getIndex()).build();
  GroupKey groupKey = relBuilder.groupKey(newGroupSet, aggregate.indicator, null);

  relBuilder.aggregate(groupKey, aggregate.getAggCallList());

  Iterable<RexInputRef> projects = FluentIterable.from(aggregate.getRowType().getFieldNames())
    .transform(new Function<String, RexInputRef>() {
      @Override
      public RexInputRef apply(String fieldName) {
        return relBuilder.field(fieldName);
      }
    })
    .append(relBuilder.field(UPDATE_COLUMN));

  relBuilder.project(projects);

  return relBuilder.build();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:29,代码来源:IncrementalUpdateUtils.java

示例6: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final Project proj = call.rel(0);
  final ScanCrel scan = call.rel(1);

  ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());

  // get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
  if (columnInfo == null || columnInfo.isStarQuery()) {
    return;
  }

  final RelNode newScan = scan.cloneWithProject(columnInfo.columns);

  List<RexNode> newProjects = Lists.newArrayList();
  for (RexNode n : proj.getChildExps()) {
    newProjects.add(n.accept(columnInfo.getInputRewriter()));
  }

  final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
  relBuilder.push(newScan);
  relBuilder.project(newProjects, proj.getRowType().getFieldNames());
  final RelNode newProj = relBuilder.build();

  if (newProj instanceof Project
      && ProjectRemoveRule.isTrivial((Project) newProj)
      && newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
      call.transformTo(newScan);
  } else {
    call.transformTo(newProj);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:33,代码来源:PushProjectIntoScanRule.java

示例7: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final Project proj = call.rel(0);
  final OldScanCrel scan = call.rel(1);

  ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());

  // get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
  if (columnInfo == null || columnInfo.isStarQuery() || !scan.getGroupScan().canPushdownProjects(columnInfo.columns)) {
    return;
  }

  final OldScanCrel newScan = new OldScanCrel(scan.getCluster(),
      scan.getTable(),
      scan.getTraitSet(),
      columnInfo.createNewRowType(proj.getInput().getCluster().getTypeFactory()),
      scan.getGroupScan().clone(columnInfo.columns),
      scan.getLayoutInfo(),
      scan.getRowCountDiscount());

  List<RexNode> newProjects = Lists.newArrayList();
  for (RexNode n : proj.getChildExps()) {
    newProjects.add(n.accept(columnInfo.getInputRewriter()));
  }

  final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
  relBuilder.push(newScan);
  relBuilder.project(newProjects, proj.getRowType().getFieldNames());
  final RelNode newProj = relBuilder.build();

  if (newProj instanceof Project
      && ProjectRemoveRule.isTrivial((Project) newProj)
      && newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
      call.transformTo(newScan);
  } else {
    call.transformTo(newProj);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:OldPushProjectIntoScanRule.java

示例8: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  SemiJoin semiJoin = call.rel(0);
  LogicalProject project = call.rel(1);

  // Convert the LHS semi-join keys to reference the child projection
  // expression; all projection expressions must be RexInputRefs,
  // otherwise, we wouldn't have created this semi-join.
  final List<Integer> newLeftKeys = new ArrayList<>();
  final List<Integer> leftKeys = semiJoin.getLeftKeys();
  final List<RexNode> projExprs = project.getProjects();
  for (int leftKey : leftKeys) {
    RexInputRef inputRef = (RexInputRef) projExprs.get(leftKey);
    newLeftKeys.add(inputRef.getIndex());
  }

  // convert the semijoin condition to reflect the LHS with the project
  // pulled up
  RexNode newCondition = adjustCondition(project, semiJoin);

  SemiJoin newSemiJoin =
      SemiJoin.create(project.getInput(), semiJoin.getRight(), newCondition,
          ImmutableIntList.copyOf(newLeftKeys), semiJoin.getRightKeys());

  // Create the new projection.  Note that the projection expressions
  // are the same as the original because they only reference the LHS
  // of the semijoin and the semijoin only projects out the LHS
  final RelBuilder relBuilder = call.builder();
  relBuilder.push(newSemiJoin);
  relBuilder.project(projExprs, project.getRowType().getFieldNames());

  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:SemiJoinProjectTransposeRule.java

示例9: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
  final Calc calc = call.rel(0);
  final Pair<ImmutableList<RexNode>, ImmutableList<RexNode>> projectFilter =
      calc.getProgram().split();
  final RelBuilder relBuilder = call.builder();
  relBuilder.push(calc.getInput());
  relBuilder.filter(projectFilter.right);
  relBuilder.project(projectFilter.left, calc.getRowType().getFieldNames());
  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:11,代码来源:CalcSplitRule.java

示例10: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Project topProject = call.rel(0);
  final Project bottomProject = call.rel(1);
  final RelBuilder relBuilder = call.builder();

  // merge projects assuming it doesn't alter the unique count of flattens.
  final FlattenCounter counter = new FlattenCounter();
  counter.add(topProject);
  counter.add(bottomProject);
  final int uniqueFlattens = counter.getCount();

  // If one or both projects are permutations, short-circuit the complex logic
  // of building a RexProgram.
  final Permutation topPermutation = topProject.getPermutation();
  if (topPermutation != null) {
    if (topPermutation.isIdentity()) {
      // Let ProjectRemoveRule handle this.
      return;
    }
    final Permutation bottomPermutation = bottomProject.getPermutation();
    if (bottomPermutation != null) {
      if (bottomPermutation.isIdentity()) {
        // Let ProjectRemoveRule handle this.
        return;
      }
      final Permutation product = topPermutation.product(bottomPermutation);
      relBuilder.push(bottomProject.getInput());
      List<RexNode> exprs = relBuilder.fields(product);
      relBuilder.project(exprs, topProject.getRowType().getFieldNames());

      if(FlattenVisitors.count(exprs) == uniqueFlattens){
        call.transformTo(relBuilder.build());
      }
      return;
    }
  }

  final List<RexNode> newProjects =
      RelOptUtil.pushPastProject(topProject.getProjects(), bottomProject);
  final RelNode input = bottomProject.getInput();
  if (RexUtil.isIdentity(newProjects, input.getRowType()) && uniqueFlattens == 0) {
    call.transformTo(input);
  }

  // replace the two projects with a combined projection
  relBuilder.push(bottomProject.getInput());
  relBuilder.project(newProjects, topProject.getRowType().getFieldNames());
  if(FlattenVisitors.count(newProjects) == uniqueFlattens){
    call.transformTo(relBuilder.build());
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:52,代码来源:MergeProjectRule.java

示例11: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  Filter filterRel = call.rel(0);
  Project projRel = call.rel(1);

  // get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
  // then we could not pushed down. Otherwise, it's qualified to be pushed down.
  final List<RexNode> predList = RelOptUtil.conjunctions(filterRel.getCondition());

  final List<RexNode> qualifiedPredList = Lists.newArrayList();
  final List<RexNode> unqualifiedPredList = Lists.newArrayList();


  for (final RexNode pred : predList) {
    if (findItemOrFlatten(pred, projRel.getProjects()) == null) {
      qualifiedPredList.add(pred);
    } else {
      unqualifiedPredList.add(pred);
    }
  }

  final RexNode qualifedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), qualifiedPredList, true);

  if (qualifedPred == null) {
    return;
  }

  // convert the filter to one that references the child of the project
  RexNode newCondition =
      RelOptUtil.pushPastProject(qualifedPred, projRel);

  RelBuilder relBuilder = relBuilderFactory.create(filterRel.getCluster(), null);
  relBuilder.push(projRel.getInput());
  relBuilder.filter(newCondition);
  relBuilder.project(Pair.left(projRel.getNamedProjects()), Pair.right(projRel.getNamedProjects()));

  final RexNode unqualifiedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), unqualifiedPredList, true);

  if (unqualifiedPred == null) {
    call.transformTo(relBuilder.build());
  } else {
    // if there are filters not qualified to be pushed down, then we have to put those filters on top of
    // the new Project operator.
    // Filter -- unqualified filters
    //   \
    //    Project
    //     \
    //      Filter  -- qualified filters
    relBuilder.filter(unqualifiedPred);
    call.transformTo(relBuilder.build());
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:53,代码来源:PushFilterPastProjectRule.java

示例12: onMatch

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
  final Union union = call.rel(0);

  final int count = union.getRowType().getFieldCount();
  if (count == 1) {
    // No room for optimization since we cannot create an empty Project
    // operator. If we created a Project with one column, this rule would
    // cycle.
    return;
  }

  final RexBuilder rexBuilder = union.getCluster().getRexBuilder();
  final RelMetadataQuery mq = call.getMetadataQuery();
  final RelOptPredicateList predicates = mq.getPulledUpPredicates(union);
  if (predicates == null) {
    return;
  }

  final Map<Integer, RexNode> constants = new HashMap<>();
  for (Map.Entry<RexNode, RexNode> e : predicates.constantMap.entrySet()) {
    if (e.getKey() instanceof RexInputRef) {
      constants.put(((RexInputRef) e.getKey()).getIndex(), e.getValue());
    }
  }

  // None of the expressions are constant. Nothing to do.
  if (constants.isEmpty()) {
    return;
  }

  // Create expressions for Project operators before and after the Union
  List<RelDataTypeField> fields = union.getRowType().getFieldList();
  List<RexNode> topChildExprs = new ArrayList<>();
  List<String> topChildExprsFields = new ArrayList<>();
  List<RexNode> refs = new ArrayList<>();
  ImmutableBitSet.Builder refsIndexBuilder = ImmutableBitSet.builder();
  for (RelDataTypeField field : fields) {
    final RexNode constant = constants.get(field.getIndex());
    if (constant != null) {
      topChildExprs.add(constant);
      topChildExprsFields.add(field.getName());
    } else {
      final RexNode expr = rexBuilder.makeInputRef(union, field.getIndex());
      topChildExprs.add(expr);
      topChildExprsFields.add(field.getName());
      refs.add(expr);
      refsIndexBuilder.set(field.getIndex());
    }
  }
  ImmutableBitSet refsIndex = refsIndexBuilder.build();

  // Update top Project positions
  final Mappings.TargetMapping mapping =
      RelOptUtil.permutation(refs, union.getInput(0).getRowType()).inverse();
  topChildExprs = ImmutableList.copyOf(RexUtil.apply(mapping, topChildExprs));

  // Create new Project-Union-Project sequences
  final RelBuilder relBuilder = call.builder();
  for (RelNode input : union.getInputs()) {
    List<Pair<RexNode, String>> newChildExprs = new ArrayList<>();
    for (int j : refsIndex) {
      newChildExprs.add(
          Pair.<RexNode, String>of(rexBuilder.makeInputRef(input, j),
              input.getRowType().getFieldList().get(j).getName()));
    }
    if (newChildExprs.isEmpty()) {
      // At least a single item in project is required.
      newChildExprs.add(
          Pair.of(topChildExprs.get(0), topChildExprsFields.get(0)));
    }
    // Add the input with project on top
    relBuilder.push(input);
    relBuilder.project(Pair.left(newChildExprs), Pair.right(newChildExprs));
  }
  relBuilder.union(union.all, union.getInputs().size());
  // Create top Project fixing nullability of fields
  relBuilder.project(topChildExprs, topChildExprsFields);
  relBuilder.convert(union.getRowType(), false);

  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:82,代码来源:UnionPullUpConstantsRule.java

示例13: createTopProject

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
 * Creates the topmost projection that will sit on top of the selected join
 * ordering. The projection needs to match the original join ordering. Also,
 * places any post-join filters on top of the project.
 *
 * @param multiJoin join factors being optimized
 * @param joinTree selected join ordering
 * @param fieldNames field names corresponding to the projection expressions
 *
 * @return created projection
 */
private RelNode createTopProject(
    RelBuilder relBuilder,
    LoptMultiJoin multiJoin,
    LoptJoinTree joinTree,
    List<String> fieldNames) {
  List<RexNode> newProjExprs = Lists.newArrayList();
  RexBuilder rexBuilder =
      multiJoin.getMultiJoinRel().getCluster().getRexBuilder();

  // create a projection on top of the joins, matching the original
  // join order
  final List<Integer> newJoinOrder = joinTree.getTreeOrder();
  int nJoinFactors = multiJoin.getNumJoinFactors();
  List<RelDataTypeField> fields = multiJoin.getMultiJoinFields();

  // create a mapping from each factor to its field offset in the join
  // ordering
  final Map<Integer, Integer> factorToOffsetMap = new HashMap<>();
  for (int pos = 0, fieldStart = 0; pos < nJoinFactors; pos++) {
    factorToOffsetMap.put(newJoinOrder.get(pos), fieldStart);
    fieldStart +=
        multiJoin.getNumFieldsInJoinFactor(newJoinOrder.get(pos));
  }

  for (int currFactor = 0; currFactor < nJoinFactors; currFactor++) {
    // if the factor is the right factor in a removable self-join,
    // then where possible, remap references to the right factor to
    // the corresponding reference in the left factor
    Integer leftFactor = null;
    if (multiJoin.isRightFactorInRemovableSelfJoin(currFactor)) {
      leftFactor = multiJoin.getOtherSelfJoinFactor(currFactor);
    }
    for (int fieldPos = 0;
        fieldPos < multiJoin.getNumFieldsInJoinFactor(currFactor);
        fieldPos++) {
      int newOffset = factorToOffsetMap.get(currFactor) + fieldPos;
      if (leftFactor != null) {
        Integer leftOffset =
            multiJoin.getRightColumnMapping(currFactor, fieldPos);
        if (leftOffset != null) {
          newOffset =
              factorToOffsetMap.get(leftFactor) + leftOffset;
        }
      }
      newProjExprs.add(
          rexBuilder.makeInputRef(
              fields.get(newProjExprs.size()).getType(),
              newOffset));
    }
  }

  relBuilder.push(joinTree.getJoinTree());
  relBuilder.project(newProjExprs, fieldNames);

  // Place the post-join filter (if it exists) on top of the final
  // projection.
  RexNode postJoinFilter =
      multiJoin.getMultiJoinRel().getPostJoinFilter();
  if (postJoinFilter != null) {
    relBuilder.filter(postJoinFilter);
  }
  return relBuilder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:75,代码来源:LoptOptimizeJoinRule.java

示例14: reduceAggs

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
 * Reduces all calls to AVG, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP in
 * the aggregates list to.
 *
 * <p>It handles newly generated common subexpressions since this was done
 * at the sql2rel stage.
 */
private void reduceAggs(
    RelOptRuleCall ruleCall,
    Aggregate oldAggRel) {
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();

  List<AggregateCall> oldCalls = oldAggRel.getAggCallList();
  final int groupCount = oldAggRel.getGroupCount();
  final int indicatorCount = oldAggRel.getIndicatorCount();

  final List<AggregateCall> newCalls = Lists.newArrayList();
  final Map<AggregateCall, RexNode> aggCallMapping = Maps.newHashMap();

  final List<RexNode> projList = Lists.newArrayList();

  // pass through group key (+ indicators if present)
  for (int i = 0; i < groupCount + indicatorCount; ++i) {
    projList.add(
        rexBuilder.makeInputRef(
            getFieldType(oldAggRel, i),
            i));
  }

  // List of input expressions. If a particular aggregate needs more, it
  // will add an expression to the end, and we will create an extra
  // project.
  final RelBuilder relBuilder = ruleCall.builder();
  relBuilder.push(oldAggRel.getInput());
  final List<RexNode> inputExprs = new ArrayList<>(relBuilder.fields());

  // create new agg function calls and rest of project list together
  for (AggregateCall oldCall : oldCalls) {
    projList.add(
        reduceAgg(
            oldAggRel, oldCall, newCalls, aggCallMapping, inputExprs));
  }

  final int extraArgCount =
      inputExprs.size() - relBuilder.peek().getRowType().getFieldCount();
  if (extraArgCount > 0) {
    relBuilder.project(inputExprs,
        CompositeList.of(
            relBuilder.peek().getRowType().getFieldNames(),
            Collections.<String>nCopies(extraArgCount, null)));
  }
  newAggregateRel(relBuilder, oldAggRel, newCalls);
  relBuilder.project(projList, oldAggRel.getRowType().getFieldNames());
  ruleCall.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:56,代码来源:AggregateReduceFunctionsRule.java

示例15: perform

import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
protected void perform(RelOptRuleCall call, Project project,
    Join join, RelNode left, Aggregate aggregate) {
  final RelOptCluster cluster = join.getCluster();
  final RexBuilder rexBuilder = cluster.getRexBuilder();
  if (project != null) {
    final ImmutableBitSet bits =
        RelOptUtil.InputFinder.bits(project.getProjects(), null);
    final ImmutableBitSet rightBits =
        ImmutableBitSet.range(left.getRowType().getFieldCount(),
            join.getRowType().getFieldCount());
    if (bits.intersects(rightBits)) {
      return;
    }
  }
  final JoinInfo joinInfo = join.analyzeCondition();
  if (!joinInfo.rightSet().equals(
      ImmutableBitSet.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;
  }
  if (!joinInfo.isEqui()) {
    return;
  }
  final RelBuilder relBuilder = call.builder();
  relBuilder.push(left);
  switch (join.getJoinType()) {
  case INNER:
    final List<Integer> newRightKeyBuilder = Lists.newArrayList();
    final List<Integer> aggregateKeys = aggregate.getGroupSet().asList();
    for (int key : joinInfo.rightKeys) {
      newRightKeyBuilder.add(aggregateKeys.get(key));
    }
    final ImmutableIntList newRightKeys = ImmutableIntList.copyOf(newRightKeyBuilder);
    relBuilder.push(aggregate.getInput());
    final RexNode newCondition =
        RelOptUtil.createEquiJoinCondition(relBuilder.peek(2, 0),
            joinInfo.leftKeys, relBuilder.peek(2, 1), newRightKeys,
            rexBuilder);
    relBuilder.semiJoin(newCondition);
    break;

  case LEFT:
    // The right-hand side produces no more than 1 row (because of the
    // Aggregate) and no fewer than 1 row (because of LEFT), and therefore
    // we can eliminate the semi-join.
    break;

  default:
    throw new AssertionError(join.getJoinType());
  }
  if (project != null) {
    relBuilder.project(project.getProjects(), project.getRowType().getFieldNames());
  }
  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:57,代码来源:SemiJoinRule.java


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