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


Java RelOptUtil.createProject方法代码示例

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


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

示例1: onMatch

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

  // Don't push Filter past Project if the Filter is referencing an ITEM or a FLATTEN expression
  // from the Project.
  //\TODO: Ideally we should split up the filter conditions into ones that
  // reference the ITEM expression and ones that don't and push the latter past the Project
  if (findItemOrFlatten(filterRel.getCondition(), projRel.getProjects()) != null) {
    return;
  }

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

  Filter newFilterRel = LogicalFilter.create(projRel.getInput(), newCondition);

  Project newProjRel =
      (Project) RelOptUtil.createProject(
          newFilterRel,
          projRel.getNamedProjects(),
          false);

  call.transformTo(newProjRel);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:27,代码来源:DrillPushFilterPastProjectRule.java

示例2: createProjectWithAdditionalExprs

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Projects all {@code input} output fields plus the additional expressions.
 *
 * @param input        Input relational expression
 * @param additionalExprs Additional expressions and names
 * @return the new Project
 */
private RelNode createProjectWithAdditionalExprs(
    RelNode input,
    List<Pair<RexNode, String>> additionalExprs) {
  final List<RelDataTypeField> fieldList =
      input.getRowType().getFieldList();
  List<Pair<RexNode, String>> projects = Lists.newArrayList();
  for (Ord<RelDataTypeField> field : Ord.zip(fieldList)) {
    projects.add(
        Pair.of(
            (RexNode) rexBuilder.makeInputRef(
                field.e.getType(), field.i),
            field.e.getName()));
  }
  projects.addAll(additionalExprs);
  return RelOptUtil.createProject(input, projects, false);
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:RelDecorrelator.java

示例3: createNewProject

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Creates a new projection based on the original projection, adjusting all
 * input refs using an adjustment array passed in. If there was no original
 * projection, create a new one that selects every field from the underlying
 * rel.
 *
 * <p>If the resulting projection would be trivial, return the child.
 *
 * @param projChild   child of the new project
 * @param adjustments array indicating how much each input reference should
 *                    be adjusted by
 * @return the created projection
 */
public RelNode createNewProject(RelNode projChild, int[] adjustments) {
  final List<Pair<RexNode, String>> projects = Lists.newArrayList();

  if (origProj != null) {
    for (Pair<RexNode, String> p : origProj.getNamedProjects()) {
      projects.add(
          Pair.of(
              convertRefsAndExprs(
                  p.left,
                  projChild.getRowType().getFieldList(),
                  adjustments),
              p.right));
    }
  } else {
    for (Ord<RelDataTypeField> field : Ord.zip(childFields)) {
      projects.add(
          Pair.of(
              (RexNode) rexBuilder.makeInputRef(
                  field.e.getType(), field.i), field.e.getName()));
    }
  }
  return RelOptUtil.createProject(
      projChild,
      Pair.left(projects),
      Pair.right(projects),
      true /* optimize to avoid trivial projections, as per javadoc */,
      relBuilder);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:42,代码来源:PushProjector.java

示例4: projectJoinOutputWithNullability

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Pulls project above the join from its RHS input. Enforces nullability
 * for join output.
 *
 * @param join             Join
 * @param project          Original project as the right-hand input of the join
 * @param nullIndicatorPos Position of null indicator
 * @return the subtree with the new LogicalProject at the root
 */
private RelNode projectJoinOutputWithNullability(LogicalJoin join, LogicalProject project, int nullIndicatorPos) {
	final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory();
	final RelNode left = join.getLeft();
	final JoinRelType joinType = join.getJoinType();

	RexInputRef nullIndicator = new RexInputRef(nullIndicatorPos, typeFactory.createTypeWithNullability(join.getRowType().getFieldList().get(nullIndicatorPos).getType(), true));

	// now create the new project
	List<Pair<RexNode, String>> newProjExprs = Lists.newArrayList();

	// project everything from the LHS and then those from the original
	// projRel
	List<RelDataTypeField> leftInputFields = left.getRowType().getFieldList();

	for (int i = 0; i < leftInputFields.size(); i++) {
		newProjExprs.add(RexInputRef.of2(i, leftInputFields));
	}

	// Marked where the projected expr is coming from so that the types will
	// become nullable for the original projections which are now coming out
	// of the nullable side of the OJ.
	boolean projectPulledAboveLeftCorrelator = joinType.generatesNullsOnRight();

	for (Pair<RexNode, String> pair : project.getNamedProjects()) {
		RexNode newProjExpr = removeCorrelationExpr(pair.left, projectPulledAboveLeftCorrelator, nullIndicator);

		newProjExprs.add(Pair.of(newProjExpr, pair.right));
	}

	return RelOptUtil.createProject(join, newProjExprs, false);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:41,代码来源:FlinkRelDecorrelator.java

示例5: aggregateCorrelatorOutput

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Pulls a {@link Project} above a {@link Correlate} from its RHS input.
 * Enforces nullability for join output.
 *
 * @param correlate Correlate
 * @param project   the original project as the RHS input of the join
 * @param isCount   Positions which are calls to the <code>COUNT</code>
 *                  aggregation function
 * @return the subtree with the new LogicalProject at the root
 */
private RelNode aggregateCorrelatorOutput(Correlate correlate, LogicalProject project, Set<Integer> isCount) {
	final RelNode left = correlate.getLeft();
	final JoinRelType joinType = correlate.getJoinType().toJoinType();

	// now create the new project
	final List<Pair<RexNode, String>> newProjects = Lists.newArrayList();

	// Project everything from the LHS and then those from the original
	// project
	final List<RelDataTypeField> leftInputFields = left.getRowType().getFieldList();

	for (int i = 0; i < leftInputFields.size(); i++) {
		newProjects.add(RexInputRef.of2(i, leftInputFields));
	}

	// Marked where the projected expr is coming from so that the types will
	// become nullable for the original projections which are now coming out
	// of the nullable side of the OJ.
	boolean projectPulledAboveLeftCorrelator = joinType.generatesNullsOnRight();

	for (Pair<RexNode, String> pair : project.getNamedProjects()) {
		RexNode newProjExpr = removeCorrelationExpr(pair.left, projectPulledAboveLeftCorrelator, isCount);
		newProjects.add(Pair.of(newProjExpr, pair.right));
	}

	return RelOptUtil.createProject(correlate, newProjects, false);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:38,代码来源:FlinkRelDecorrelator.java

示例6: createProjectWithAdditionalExprs

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Projects all {@code input} output fields plus the additional expressions.
 *
 * @param input           Input relational expression
 * @param additionalExprs Additional expressions and names
 * @return the new LogicalProject
 */
private RelNode createProjectWithAdditionalExprs(RelNode input, List<Pair<RexNode, String>> additionalExprs) {
	final List<RelDataTypeField> fieldList = input.getRowType().getFieldList();
	List<Pair<RexNode, String>> projects = Lists.newArrayList();
	for (Ord<RelDataTypeField> field : Ord.zip(fieldList)) {
		projects.add(Pair.of((RexNode) rexBuilder.makeInputRef(field.e.getType(), field.i), field.e.getName()));
	}
	projects.addAll(additionalExprs);
	return RelOptUtil.createProject(input, projects, false);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:FlinkRelDecorrelator.java

示例7: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
	LogicalAggregate singleAggregate = call.rel(0);
	LogicalProject project = call.rel(1);
	LogicalAggregate aggregate = call.rel(2);

	// check singleAggRel is single_value agg
	if ((!singleAggregate.getGroupSet().isEmpty()) || (singleAggregate.getAggCallList().size() != 1) || !(singleAggregate.getAggCallList().get(0).getAggregation() instanceof SqlSingleValueAggFunction)) {
		return;
	}

	// check projRel only projects one expression
	// check this project only projects one expression, i.e. scalar
	// subqueries.
	List<RexNode> projExprs = project.getProjects();
	if (projExprs.size() != 1) {
		return;
	}

	// check the input to projRel is an aggregate on the entire input
	if (!aggregate.getGroupSet().isEmpty()) {
		return;
	}

	// singleAggRel produces a nullable type, so create the new
	// projection that casts proj expr to a nullable type.
	final RelOptCluster cluster = project.getCluster();
	RelNode newProject = RelOptUtil.createProject(aggregate, ImmutableList.of(rexBuilder.makeCast(cluster.getTypeFactory().createTypeWithNullability(projExprs.get(0).getType(), true), projExprs.get(0))), null);
	call.transformTo(newProject);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:30,代码来源:FlinkRelDecorrelator.java

示例8: toRel

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public RelNode toRel(
    RelOptTable.ToRelContext context,
    RelOptTable relOptTable) {
  // Request all fields.
  RelNode rel = new QuarkTileScan(context.getCluster(),
      this.relOptTable, this.quarkTile, this.backingTable);

  //Create a filter

  RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
  List<RexNode> filterArgs = Lists.newArrayList();
  filterArgs.add(rexBuilder.makeInputRef(rel, this.quarkTile.groupingColumn));
  filterArgs.add(rexBuilder.makeLiteral(bitSetToString(this.quarkTile.groupingValue)));

  rel = LogicalFilter.create(rel, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, filterArgs));

  //Create a project list
  List<Integer> posList = Lists.newArrayList();
  for (QuarkTile.Column quarkColumn : this.quarkTile.cubeColumns) {
    posList.add(quarkColumn.cubeOrdinal);
  }

  for (Lattice.Measure measure : this.quarkTile.measures) {
    posList.add(((QuarkTile.Measure) measure).ordinal);
  }

  return RelOptUtil.createProject(rel, posList);

}
 
开发者ID:qubole,项目名称:quark,代码行数:30,代码来源:QuarkTileTable.java

示例9: swap

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的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

示例10: aggregateCorrelatorOutput

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Pulls a {@link Project} above a {@link Correlate} from its RHS input.
 * Enforces nullability for join output.
 *
 * @param correlate  Correlate
 * @param project the original project as the RHS input of the join
 * @param isCount Positions which are calls to the <code>COUNT</code>
 *                aggregation function
 * @return the subtree with the new Project at the root
 */
private RelNode aggregateCorrelatorOutput(
    Correlate correlate,
    LogicalProject project,
    Set<Integer> isCount) {
  final RelNode left = correlate.getLeft();
  final JoinRelType joinType = correlate.getJoinType().toJoinType();

  // now create the new project
  final List<Pair<RexNode, String>> newProjects = Lists.newArrayList();

  // Project everything from the LHS and then those from the original
  // project
  final List<RelDataTypeField> leftInputFields =
      left.getRowType().getFieldList();

  for (int i = 0; i < leftInputFields.size(); i++) {
    newProjects.add(RexInputRef.of2(i, leftInputFields));
  }

  // Marked where the projected expr is coming from so that the types will
  // become nullable for the original projections which are now coming out
  // of the nullable side of the OJ.
  boolean projectPulledAboveLeftCorrelator =
      joinType.generatesNullsOnRight();

  for (Pair<RexNode, String> pair : project.getNamedProjects()) {
    RexNode newProjExpr =
        removeCorrelationExpr(
            pair.left,
            projectPulledAboveLeftCorrelator,
            isCount);
    newProjects.add(Pair.of(newProjExpr, pair.right));
  }

  return RelOptUtil.createProject(correlate, newProjects, false);
}
 
开发者ID:apache,项目名称:calcite,代码行数:47,代码来源:RelDecorrelator.java

示例11: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  LogicalAggregate singleAggregate = call.rel(0);
  LogicalProject project = call.rel(1);
  LogicalAggregate aggregate = call.rel(2);

  // check singleAggRel is single_value agg
  if ((!singleAggregate.getGroupSet().isEmpty())
      || (singleAggregate.getAggCallList().size() != 1)
      || !(singleAggregate.getAggCallList().get(0).getAggregation()
      instanceof SqlSingleValueAggFunction)) {
    return;
  }

  // check projRel only projects one expression
  // check this project only projects one expression, i.e. scalar
  // sub-queries.
  List<RexNode> projExprs = project.getProjects();
  if (projExprs.size() != 1) {
    return;
  }

  // check the input to project is an aggregate on the entire input
  if (!aggregate.getGroupSet().isEmpty()) {
    return;
  }

  // singleAggRel produces a nullable type, so create the new
  // projection that casts proj expr to a nullable type.
  final RelOptCluster cluster = project.getCluster();
  RelNode newProject =
      RelOptUtil.createProject(aggregate,
          ImmutableList.of(
              rexBuilder.makeCast(
                  cluster.getTypeFactory().createTypeWithNullability(
                      projExprs.get(0).getType(),
                      true),
                  projExprs.get(0))),
          null);
  call.transformTo(newProject);
}
 
开发者ID:apache,项目名称:calcite,代码行数:41,代码来源:RelDecorrelator.java

示例12: rewrite

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public RelNode rewrite(RelNode root) {
  // Perform flattening.
  final RewriteRelVisitor visitor = new RewriteRelVisitor();
  visitor.visit(root, 0, null);
  RelNode flattened = getNewForOldRel(root);
  flattenedRootType = flattened.getRowType();

  // If requested, add an additional projection which puts
  // everything back into structured form for return to the
  // client.
  restructured = false;
  List<RexNode> structuringExps = null;
  if (restructure) {
    iRestructureInput = 0;
    structuringExps = restructureFields(root.getRowType());
  }
  if (restructured) {
    // REVIEW jvs 23-Mar-2005:  How do we make sure that this
    // implementation stays in Java?  Fennel can't handle
    // structured types.
    return RelOptUtil.createProject(
        flattened,
        structuringExps,
        root.getRowType().getFieldNames());
  } else {
    return flattened;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:RelStructuredTypeFlattener.java

示例13: rewriteRel

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public void rewriteRel(LogicalProject rel) {
  final List<Pair<RexNode, String>> flattenedExpList = Lists.newArrayList();
  flattenProjections(new RewriteRexShuttle(),
      rel.getProjects(),
      rel.getRowType().getFieldNames(),
      "",
      flattenedExpList);
  RelNode newRel =
      RelOptUtil.createProject(
          getNewForOldRel(rel.getInput()),
          flattenedExpList,
          false);
  setNewForOldRel(rel, newRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:RelStructuredTypeFlattener.java

示例14: reduceAggs

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的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 nGroups = oldAggRel.getGroupCount();

  List<AggregateCall> newCalls = new ArrayList<AggregateCall>();
  Map<AggregateCall, RexNode> aggCallMapping =
      new HashMap<AggregateCall, RexNode>();

  List<RexNode> projList = new ArrayList<RexNode>();

  // pass through group key
  for (int i = 0; i < nGroups; ++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.
  RelNode input = oldAggRel.getInput();
  List<RexNode> inputExprs = new ArrayList<RexNode>();
  for (RelDataTypeField field : input.getRowType().getFieldList()) {
    inputExprs.add(
        rexBuilder.makeInputRef(
            field.getType(), inputExprs.size()));
  }

  // 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() - input.getRowType().getFieldCount();
  if (extraArgCount > 0) {
    input =
        RelOptUtil.createProject(
            input,
            inputExprs,
            CompositeList.of(
                input.getRowType().getFieldNames(),
                Collections.<String>nCopies(
                    extraArgCount,
                    null)));
  }
  Aggregate newAggRel =
      newAggregateRel(
          oldAggRel, input, newCalls);

  RelNode projectRel =
      RelOptUtil.createProject(
          newAggRel,
          projList,
          oldAggRel.getRowType().getFieldNames());

  ruleCall.transformTo(projectRel);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:73,代码来源:DrillReduceAggregatesRule.java

示例15: decorrelateRel

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Rewrite LogicalProject.
 *
 * @param rel the project rel to rewrite
 */
public Frame decorrelateRel(LogicalProject rel) {
	//
	// Rewrite logic:
	//
	// 1. Pass along any correlated variables coming from the input.
	//

	final RelNode oldInput = rel.getInput();
	Frame frame = getInvoke(oldInput, rel);
	if (frame == null) {
		// If input has not been rewritten, do not rewrite this rel.
		return null;
	}
	final List<RexNode> oldProjects = rel.getProjects();
	final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();

	// LogicalProject projects the original expressions,
	// plus any correlated variables the input wants to pass along.
	final List<Pair<RexNode, String>> projects = Lists.newArrayList();

	// If this LogicalProject has correlated reference, create value generator
	// and produce the correlated variables in the new output.
	if (cm.mapRefRelToCorVar.containsKey(rel)) {
		decorrelateInputWithValueGenerator(rel);

		// The old input should be mapped to the LogicalJoin created by
		// rewriteInputWithValueGenerator().
		frame = map.get(oldInput);
	}

	// LogicalProject projects the original expressions
	final Map<Integer, Integer> mapOldToNewOutputPos = Maps.newHashMap();
	int newPos;
	for (newPos = 0; newPos < oldProjects.size(); newPos++) {
		projects.add(newPos, Pair.of(decorrelateExpr(oldProjects.get(newPos)), relOutput.get(newPos).getName()));
		mapOldToNewOutputPos.put(newPos, newPos);
	}

	// Project any correlated variables the input wants to pass along.
	final SortedMap<Correlation, Integer> mapCorVarToOutputPos = new TreeMap<>();
	for (Map.Entry<Correlation, Integer> entry : frame.corVarOutputPos.entrySet()) {
		projects.add(RexInputRef.of2(entry.getValue(), frame.r.getRowType().getFieldList()));
		mapCorVarToOutputPos.put(entry.getKey(), newPos);
		newPos++;
	}

	RelNode newProject = RelOptUtil.createProject(frame.r, projects, false);

	return register(rel, newProject, mapOldToNewOutputPos, mapCorVarToOutputPos);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:56,代码来源:FlinkRelDecorrelator.java


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