org.apache.calcite.rel.core.Project类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(15.5k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.apache.calcite.rel.core.Project类的一些代码示例,展示了Project类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project类的具体详情如下:
包路径:org.apache.calcite.rel.core.Project
类名称:Project

Project介绍

[英]Relational expression that computes a set of 'select expressions' from its input relational expression.
[中]从输入关系表达式计算一组“选择表达式”的关系表达式。

代码示例

代码示例来源:origin: apache/drill

public void onMatch(RelOptRuleCall call) {
    final Project project = call.rel(0);
    //TODO: replace HiveSubQRemoveRelBuilder with calcite's once calcite 1.11.0 is released
    final HiveSubQRemoveRelBuilder builder = new HiveSubQRemoveRelBuilder(null, call.rel(0).getCluster(), null);
    final RexSubQuery e =
        RexUtil.SubQueryFinder.find(project.getProjects());
    assert e != null;
    final RelOptUtil.Logic logic =
        LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN,
            project.getProjects(), e);
    builder.push(project.getInput());
    final int fieldCount = builder.peek().getRowType().getFieldCount();
    final RexNode target = apply(e, HiveFilter.getVariablesSet(e),
        logic, builder, 1, fieldCount, false);
    final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target);
    builder.project(shuttle.apply(project.getProjects()),
        project.getRowType().getFieldNames());
    call.transformTo(builder.build());
  }
};

代码示例来源:origin: apache/hive

@Override public void onMatch(RelOptRuleCall call) {
 final Project project = call.rel(0);
 final Join join = call.rel(1);
 final RelNode right = call.rel(3);
 final Aggregate aggregate = call.rel(2);
  return;
 if (!joinInfo.leftSet().equals(
   ImmutableBitSet.range(aggregate.getGroupCount()))) {
   RelOptUtil.InputFinder.bits(project.getChildExps(), null);
   ImmutableBitSet.range(0, join.getLeft().getRowType().getFieldCount());
 if (topRefs.intersects(leftBits)) {
 final Project swappedProject = swapInputs(join, project, call.builder());
 final RelNode swappedJoin = swappedProject.getInput();
 assert(swappedJoin instanceof  Join);
   RelOptUtil.InputFinder.bits(swappedProject.getChildExps(), null);

代码示例来源:origin: apache/hive

public void onMatch(final RelOptRuleCall call) {
 Project topProject = call.rel(0);
 Join join = call.rel(1);
 final Permutation topPermutation = topProject.getPermutation();
 if (topPermutation == null) {
  return;
 final Permutation bottomPermutation = bottomProject.getPermutation();
 if (bottomPermutation == null) {
  return;
 final Join swappedJoin = (Join) bottomProject.getInput(0);
 call.transformTo(swappedJoin);

代码示例来源:origin: apache/storm

@Override
  public RelNode convert(RelNode rel) {
    final Project project = (Project) rel;
    final RelNode input = project.getInput();

    return new StreamsProjectRel(project.getCluster(),
                   project.getTraitSet().replace(StreamsLogicalConvention.INSTANCE),
                   convert(input, input.getTraitSet().replace(StreamsLogicalConvention.INSTANCE)), project.getProjects(),
                   project.getRowType());
  }
}

代码示例来源:origin: apache/hive

@Override
public void onMatch(RelOptRuleCall call) {
 final Project project = call.rel(0);
 boolean changed = false;
 final RexBuilder rexBuilder = project.getCluster().getRexBuilder();
 List<RexNode> newProjects = new ArrayList<>();
 for (RexNode oldNode : project.getProjects()) {
  RexNode newNode = analyzeRexNode(rexBuilder, oldNode);
  if (!newNode.toString().equals(oldNode.toString())) {
   changed = true;
   newProjects.add(newNode);
  } else {
   newProjects.add(oldNode);
  }
 }
 if (!changed) {
  return;
 }
 Project newProject = project.copy(project.getTraitSet(), project.getInput(), newProjects,
   project.getRowType(), project.getFlags());
 call.transformTo(newProject);
}

代码示例来源:origin: apache/hive

public RelNode align(Project rel, List<RelFieldCollation> collations) {
 // 1) We extract the collations indices
 boolean containsWindowing = false;
 for (RexNode childExp : rel.getChildExps()) {
  if (childExp instanceof RexOver) {
   // TODO: support propagation for partitioning/ordering in windowing
   containsWindowing = true;
   break;
  }
 }
 ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
 if (!containsWindowing) {
  for (RelFieldCollation c : collations) {
   RexNode rexNode = rel.getChildExps().get(c.getFieldIndex());
   if (rexNode instanceof RexInputRef) {
    int newIdx = ((RexInputRef) rexNode).getIndex();
    propagateCollations.add(c.copy((newIdx)));
   }
  }
 }
 // 2) We propagate
 final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
 // 3) Return new Project
 return rel.copy(rel.getTraitSet(), ImmutableList.of(child));
}

代码示例来源:origin: org.apache.calcite/calcite-core

final Permutation topPermutation = topProject.getPermutation();
if (topPermutation != null) {
 if (topPermutation.isIdentity()) {
 final Permutation bottomPermutation = bottomProject.getPermutation();
 if (bottomPermutation != null) {
  if (bottomPermutation.isIdentity()) {
  relBuilder.push(bottomProject.getInput());
  relBuilder.project(relBuilder.fields(product),
    topProject.getRowType().getFieldNames());
  call.transformTo(relBuilder.build());
  return;
 if (RexUtil.isIdentity(topProject.getProjects(),
   topProject.getInput().getRowType())) {
  return;
  RelOptUtil.pushPastProject(topProject.getProjects(), bottomProject);
final RelNode input = bottomProject.getInput();
if (RexUtil.isIdentity(newProjects, input.getRowType())) {
 if (force
   || input.getRowType().getFieldNames()
     .equals(topProject.getRowType().getFieldNames())) {
  call.transformTo(input);
  return;
relBuilder.push(bottomProject.getInput());
relBuilder.project(newProjects, topProject.getRowType().getFieldNames());

代码示例来源:origin: apache/hive

@Override
public void onMatch(RelOptRuleCall call) {
 final Project project = call.rel(0);
 final RexBuilder rexBuilder = project.getCluster().getRexBuilder();
 List<RexNode> topProjExprs = project.getChildExps();
 Join join = call.rel(1);
 final JoinRelType joinType = join.getJoinType();
 final RelNode leftInput = join.getLeft();
 boolean leftInputPotentialFK = topRefs.intersects(leftBits);
     .map(projExpr -> projExpr.accept(new RexPermuteInputsShuttle(mappingRL, call.rel(1))))
      .map(projExpr -> projExpr.accept(new RexPermuteInputsShuttle(mappingLR, call.rel(1))))
      .push(fkInput)
      .project(topProjExprs)
      .convert(project.getRowType(), false)
      .build());
   } else {
      .filter(newFilterCond)
      .project(topProjExprs)
      .convert(project.getRowType(), false)
      .build());
     .project(project.getChildExps())
     .build());

代码示例来源:origin: apache/hive

public void onMatch(RelOptRuleCall call) {
 final LogicalCorrelate correlate = call.rel(0);
 final RelNode left = call.rel(1);
 final Project aggOutputProject = call.rel(2);
 final List<RexNode> aggOutputProjects = aggOutputProject.getProjects();
 if (aggOutputProjects.size() != 1) {
  return;
 if (!aggregate.getGroupSet().isEmpty()) {
  return;
 final List<RexNode> aggInputProjects = aggInputProject.getProjects();
  int nFields = left.getRowType().getFieldCount();
  ImmutableBitSet allCols = ImmutableBitSet.range(nFields);
 RelDataType leftInputFieldType = left.getRowType();
 int leftInputFieldCount = leftInputFieldType.getFieldCount();
 int joinOutputProjExprCount =
     leftInputFieldCount + aggInputProjects.size() + 1;
 int nullIndicatorPos = join.getRowType().getFieldCount() - 1;
         cluster.getTypeFactory().createTypeWithNullability(
     ImmutableBitSet.range(groupCount);
 Aggregate newAggregate =
   (Aggregate) relBuilder.push(joinOutputProject)

代码示例来源:origin: apache/drill

@Override public void onMatch(RelOptRuleCall call) {
 LOG.debug("Matched HiveSemiJoinRule");
 final Project project = call.rel(0);
 final Join join = call.rel(1);
 final RelNode left = call.rel(2);
 final Aggregate aggregate = call.rel(3);
 final RelOptCluster cluster = join.getCluster();
 final RexBuilder rexBuilder = cluster.getRexBuilder();
 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;
 if (!joinInfo.rightSet().equals(
   ImmutableBitSet.range(aggregate.getGroupCount()))) {
  call.transformTo(call.builder().push(left).project(project.getProjects(), project.getRowType().getFieldNames()).build());
  return;
  semi = call.builder().push(left).push(aggregate.getInput()).semiJoin(newCondition).build();
 call.transformTo(call.builder().push(semi).project(project.getProjects(), project.getRowType().getFieldNames()).build());

代码示例来源:origin: apache/incubator-druid

@Override
public void onMatch(RelOptRuleCall call)
 final Aggregate aggregate = call.rel(0);
 final Project project = call.rel(1);
 final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
 final List<AggregateCall> newCalls = new ArrayList<>(aggregate.getAggCallList().size());
 final List<RexNode> newProjects = new ArrayList<>(project.getChildExps());
 final List<RexNode> newCasts = new ArrayList<>(aggregate.getGroupCount() + aggregate.getAggCallList().size());
 final RelDataTypeFactory typeFactory = aggregate.getCluster().getTypeFactory();
  newCasts.add(rexBuilder.makeInputRef(project.getChildExps().get(fieldNumber).getType(), fieldNumber));
   final RexNode rexNode = project.getChildExps().get(Iterables.getOnlyElement(aggregateCall.getArgList()));
       booleanType,
       SqlStdOperatorTable.AND,
       ImmutableList.of(project.getProjects().get(aggregateCall.filterArg), filterFromCase)
     );
    } else {
       && arg1.isA(SqlKind.LITERAL)
       && !RexLiteral.isNullLiteral(arg1)
       && RexLiteral.isNullLiteral(arg2)) {
    .builder()
    .push(project.getInput())
    .project(newProjects);

代码示例来源:origin: apache/drill

public void onMatch(RelOptRuleCall call) {
  final Filter filter = call.rel(0);
  final Project project = call.rel(1);
  final List<RexNode> newProjects = new ArrayList<>(project.getProjects());
  newProjects.add(filter.getCondition());
  final RelOptCluster cluster = filter.getCluster();
  RelDataType newRowType =
    cluster.getTypeFactory().builder()
      .addAll(project.getRowType().getFieldList())
      .add("condition", Util.last(newProjects).getType())
      .build();
  final RelNode newProject =
    project.copy(project.getTraitSet(),
      project.getInput(),
      newProjects,
      newRowType);
  final RexInputRef newCondition =
    cluster.getRexBuilder().makeInputRef(newProject,
      newProjects.size() - 1);
  call.transformTo(filter.copy(filter.getTraitSet(), newProject, newCondition));
 }
}

代码示例来源:origin: apache/incubator-druid

@Override
public void onMatch(final RelOptRuleCall call)
 final Project project = call.rel(0);
 final Aggregate aggregate = call.rel(1);
 final ImmutableBitSet projectBits = RelOptUtil.InputFinder.bits(project.getChildExps(), null);
 final ImmutableBitSet callsToKeep = projectBits.intersect(
   ImmutableBitSet.range(aggregate.getGroupCount(), fieldCount)
 );
 if (callsToKeep.cardinality() < aggregate.getAggCallList().size()) {
  final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
    fixUpProjects.add(rexBuilder.makeInputRef(newAggregate, j++));
   } else {
    fixUpProjects.add(rexBuilder.makeNullLiteral(aggregate.getRowType().getFieldList().get(i).getType()));
  call.transformTo(
    call.builder()
      .push(newAggregate)
      .project(fixUpProjects)
      .project(project.getChildExps())
      .build()
  );

代码示例来源:origin: apache/hive

RelNode child = project.getInput();
final RexBuilder rexBuilder = project.getCluster().getRexBuilder();
RelOptPredicateList childInfo = mq.getPulledUpPredicates(child);
HashMultimap<Integer, Integer> inpIndxToOutIndxMap = HashMultimap.create();
ImmutableBitSet.Builder columnsMappedBuilder = ImmutableBitSet.builder();
Mapping m = Mappings.create(MappingType.PARTIAL_FUNCTION, child.getRowType().getFieldCount(),
  project.getRowType().getFieldCount());
for (Ord<RexNode> o : Ord.zip(project.getProjects())) {
 if (o.e instanceof RexInputRef) {
  int sIdx = ((RexInputRef) o.e).getIndex();
for (RexNode r : childInfo.pulledUpPredicates) {
 ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(r);
 if (columnsMapped.contains(rCols)) {
  r = r.accept(new RexPermuteInputsShuttle(m, child));
  projectPullUpPredicates.add(r);
for (Ord<RexNode> expr : Ord.zip(project.getProjects())) {
 if (RexLiteral.isNullLiteral(expr.e)) {
  projectPullUpPredicates.add(rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL,

代码示例来源:origin: apache/hive

public void onMatch(RelOptRuleCall call) {
 final Filter filter = call.rel(0);
 final Project project = call.rel(1);
 if (RexOver.containsOver(project.getProjects(), null)) {
 final RelDataTypeFactory typeFactory = filter.getCluster().getTypeFactory();
 if (RexUtil.isNullabilityCast(typeFactory, newCondition)) {
  newCondition = ((RexCall) newCondition).getOperands().get(0);
   project.getInput(), newCondition) : filterFactory.createFilter(project.getInput(),
   newCondition);
 RelNode newProjRel = projectFactory == null ? project.copy(project.getTraitSet(), newFilterRel,
   project.getProjects(), project.getRowType()) : projectFactory.createProject(newFilterRel,
   project.getProjects(), project.getRowType().getFieldNames());
 call.transformTo(newProjRel);

代码示例来源:origin: apache/incubator-druid

@Override
public void onMatch(RelOptRuleCall call)
   RelOptUtil.InputFinder.bits(project.getProjects(), null);
 final ImmutableBitSet rightBits =
   ImmutableBitSet.range(
     left.getRowType().getFieldCount(),
     join.getRowType().getFieldCount()
   );
 if (bits.intersects(rightBits)) {
  return;
   joinInfo.rightSet().cardinality() != right.getPartialDruidQuery().getAggregate().getGroupCount()) {
  return;
   aggregateRef = joinRef;
  } else {
   final RexNode projectExp = rightProject.getChildExps().get(joinRef);
   if (projectExp.isA(SqlKind.INPUT_REF)) {
    aggregateRef = ((RexInputRef) projectExp).getIndex();
   } else {
 call.transformTo(
   relBuilder
     .project(project.getProjects(), project.getRowType().getFieldNames())
     .build()
 );

代码示例来源:origin: apache/hive

ASTNode cond = where.getCondition().accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder()));
hiveAST.where = ASTBuilder.where(cond);
 RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos),
   groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY));
 b.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder())));
  RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos),
    groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY));
  b.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder())));
if (!groupBy.getGroupSet().isEmpty()) {
 hiveAST.groupBy = b.node();
ASTNode cond = having.getCondition().accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder()));
hiveAST.having = ASTBuilder.having(cond);
List<RexNode> childExps = ((Project) select).getChildExps();
if (childExps.isEmpty()) {
 RexLiteral r = select.getCluster().getRexBuilder().makeExactLiteral(new BigDecimal(1));
ASTNode function = buildUDTFAST(call.getOperator().getName(), children);
sel.add(function);
for (String alias : udtf.getRowType().getFieldNames()) {
 sel.add(HiveParser.Identifier, alias);

代码示例来源:origin: dremio/dremio-oss

@Override
 public void onMatch(RelOptRuleCall call) {
  final Project toTransform = call.rel(0);
  final RelNode input = toTransform.getInput();
  final RelTraitSet traits = toTransform.getTraitSet().plus(Rel.LOGICAL);
  final RelNode convertedInput = convert(input, input.getTraitSet().plus(Rel.LOGICAL).simplify());
  call.transformTo(new ProjectRel(toTransform.getCluster(), traits, convertedInput, toTransform.getProjects(), toTransform.getRowType()));
 }
}

代码示例来源:origin: apache/hive

private Project swapInputs(Join join, Project topProject, RelBuilder builder) {
 RexBuilder rexBuilder = join.getCluster().getRexBuilder();
 int rightInputSize = join.getRight().getRowType().getFieldCount();
 int leftInputSize = join.getLeft().getRowType().getFieldCount();
 List<RelDataTypeField> joinFields = join.getRowType().getFieldList();
 RexNode newJoinCond = join.getCondition().accept(new RelOptUtil.RexInputConverter(rexBuilder, joinFields,
                                          joinFields, condAdjustments));
 Join swappedJoin = (Join)builder.push(join.getRight()).push(join.getLeft()).join(join.getJoinType(),
 List<RelDataTypeField> swappedJoinFeilds = swappedJoin.getRowType().getFieldList();
 for(RexNode project:topProject.getProjects()) {
  RexNode newProject = project.accept(new RelOptUtil.RexInputConverter(rexBuilder, swappedJoinFeilds,
                                     swappedJoinFeilds, condAdjustments));
  newProjects.add(newProject);

代码示例来源:origin: apache/hive

@Override
public void onMatch(RelOptRuleCall call) {
 final HiveJoin join = call.rel(0);
 final RelNode left = call.rel(1);
 final RelNode right = call.rel(2);
 } else {
  topProject = (Project) swapped;
  newJoin = (HiveJoin) swapped.getInput(0);
  if (topProject != null) {
   multiJoin = projectFactory.createProject(multiJoin,
       topProject.getChildExps(),
       topProject.getRowType().getFieldNames());
  call.transformTo(multiJoin);

相关文章