org.apache.calcite.rex.RexInputRef类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.9k)|赞(0)|评价(0)|浏览(127)

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

RexInputRef介绍

[英]Variable which references a field of an input relational expression.

Fields of the input are 0-based. If there is more than one input, they are numbered consecutively. For example, if the inputs to a join are

  • Input #0: EMP(EMPNO, ENAME, DEPTNO) and
  • Input #1: DEPT(DEPTNO AS DEPTNO2, DNAME)

then the fields are:

  • Field #0: EMPNO
  • Field #1: ENAME
  • Field #2: DEPTNO (from EMP)
  • Field #3: DEPTNO2 (from DEPT)
  • Field #4: DNAME

So RexInputRef(3, Integer) is the correct reference for the field DEPTNO2.
[中]引用输入关系表达式字段的变量。
输入的字段是基于0的。如果有多个输入,则会连续编号。例如,如果连接的输入是
*输入#0:EMP(EMPNO、ENAME、DEPTNO)和
*输入#1:DEPT(DEPTNO作为DEPTNO2,DNAME)
然后字段是:
*字段#0:EMPNO
*字段#1:ENAME
*字段#2:DEPTNO(来自EMP)
*字段#3:部门2(来自部门)
*字段#4:DNAME
所以RexInputRef(3, Integer)是字段DEPTNO2的正确参考。

代码示例

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

private RexInputRef getNewForOldInputRef(RexInputRef oldInputRef) {
 assert currentRel != null;
 int oldOrdinal = oldInputRef.getIndex();
 int newOrdinal = 0;
 for (RelNode oldInput0 : currentRel.getInputs()) {
  RelDataType oldInputType = oldInput0.getRowType();
  int n = oldInputType.getFieldCount();
  if (oldOrdinal < n) {
   oldInput = oldInput0;
  newOrdinal += newInput.getRowType().getFieldCount();
  oldOrdinal -= n;
 return new RexInputRef(newOrdinal,
     frame.r.getRowType().getFieldList().get(newLocalOrdinal).getType());

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

@Override public RexNode visitInputRef(RexInputRef inputRef) {
  return RexInputRef.of(inputRef.getIndex(), input.getRowType());
 }
}

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

private RexInputRef getNewForOldInputRef(RexInputRef oldInputRef) {
 assert currentRel != null;
 int oldOrdinal = oldInputRef.getIndex();
 int oldOrdinalNo = oldOrdinal;
 int newOrdinal = 0;
 for (RelNode oldInput0 : currentRel.getInputs()) {
  RelDataType oldInputType = oldInput0.getRowType();
  int n = oldInputType.getFieldCount();
  if (oldOrdinal < n) {
   oldInput = oldInput0;
  newOrdinal += newInput.getRowType().getFieldCount();
  oldOrdinal -= n;
   final Frame newFrame = map.get(currentRel.getInput(0));
   if(newFrame.r instanceof HiveSemiJoin) {
    int oldFieldSize = currentRel.getInput(0).getRowType().getFieldCount();
    int newOrd = newFrame.r.getRowType().getFieldCount() + oldOrdinalNo - oldFieldSize;
    return new RexInputRef(newOrd, oldInputRef.getType());
 return new RexInputRef(newOrdinal,
     frame.r.getRowType().getFieldList().get(newLocalOrdinal).getType());

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

@Override public RexNode visitInputRef(RexInputRef inputRef) {
 final RexInputRef ref = getNewForOldInputRef(inputRef);
 if (ref.getIndex() == inputRef.getIndex()
     && ref.getType() == inputRef.getType()) {
  return inputRef; // re-use old object, to prevent needless expr cloning
 }
 return ref;
}
private RexNode decorrFieldAccess(RexFieldAccess fieldAccess) {

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

@Override public RexNode visitInputRef(RexInputRef ref) {
 final Integer integer = map.get(ref.getName());
 if (integer != null) {
  return new RexInputRef(integer, ref.getType());
 }
 throw MatchFailed.INSTANCE;
}

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

final List<RelDataTypeField> relOutput = rel.getRowType().getFieldList();
final List<Pair<RexNode, String>> projects = Lists.newArrayList();
     Pair.of(
         decorrelateExpr(oldProjects.get(newPos)),
         relOutput.get(newPos).getName()));
 mapOldToNewOutputs.put(newPos, newPos);
for (Map.Entry<CorDef, Integer> entry : frame.corDefOutputs.entrySet()) {
 projects.add(
     RexInputRef.of2(entry.getValue(),
         frame.r.getRowType().getFieldList()));
 corDefOutputs.put(entry.getKey(), newPos);
 newPos++;

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

Project project,
   int nullIndicatorPos) {
final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory();
final RelNode left = join.getLeft();
final JoinRelType joinType = join.getJoinType();
    new RexInputRef(
        nullIndicatorPos,
        typeFactory.createTypeWithNullability(
            join.getRowType().getFieldList().get(nullIndicatorPos)
                .getType(),
            true));
List<Pair<RexNode, String>> newProjExprs = Lists.newArrayList();
    left.getRowType().getFieldList();
 newProjExprs.add(RexInputRef.of2(i, leftInputFields));

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

List<RelDataTypeField> newFieldList = Lists.newLinkedList();
List<RexNode> newExpList = Lists.newLinkedList();
Map<Integer, Pair<RelDataTypeField, RexNode>> replaceFieldMap = Maps
    .newHashMapWithExpectedSize(this.context.dynamicFields.size());
int paramIndex = this.rowType.getFieldList().size();
for (Map.Entry<String, RelDataType> rewriteField : this.context.rewriteFields.entrySet()) {
  String rewriteFieldName = rewriteField.getKey();
      newFieldList.add(newField);
      RelDataTypeField inputField = getInput().getRowType().getFieldList().get(inputIndex);
      RexInputRef newFieldRef = new RexInputRef(inputField.getIndex(), inputField.getType());
      newExpList.add(newFieldRef);
      RelDataTypeField newField = new RelDataTypeFieldImpl(replaceFieldName, rowIndex, fieldType);
      RelDataTypeField inputField = getInput().getRowType().getFieldList().get(inputIndex);
      RexInputRef newFieldRef = new RexInputRef(inputField.getIndex(), inputField.getType());
  List<RexNode> newProjects = Lists.newArrayList(this.rewriteProjects);
  List<RelDataTypeField> newFields = Lists.newArrayList(this.rowType.getFieldList());
  for (int rowIndex : replaceFieldMap.keySet()) {
  FieldInfoBuilder fieldInfo = getCluster().getTypeFactory().builder();
  fieldInfo.addAll(newFields);
  fieldInfo.addAll(newFieldList);
  this.rowType = getCluster().getTypeFactory().createStructType(fieldInfo);

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

final List<RelFieldCollation> fieldCollations = Lists.newArrayList();
int fieldIndex = 0;
RexNodeConverter converter = new RexNodeConverter(cluster, srcRel.getRowType(),
  relToHiveColNameCalcitePosMap.get(srcRel), 0, false);
int srcRelRecordSz = srcRel.getRowType().getFieldCount();
   fieldIndex = ((RexInputRef) rnd).getIndex();
  } else {
   fieldIndex = srcRelRecordSz + newVCLst.size();
 List<RexNode> originalInputRefs = Lists.transform(srcRel.getRowType().getFieldList(),
   new Function<RelDataTypeField, RexNode>() {
    @Override
    public RexNode apply(RelDataTypeField input) {
     return new RexInputRef(input.getIndex(), input.getType());
RelTraitSet traitSet = cluster.traitSetOf(HiveRelNode.CONVENTION);
RelCollation canonizedCollation = traitSet.canonize(RelCollationImpl.of(fieldCollations));
sortRel = new HiveSortLimit(cluster, traitSet, obInputRel, canonizedCollation, null, null);
 List<RexNode> originalInputRefs = Lists.transform(srcRel.getRowType().getFieldList(),
   new Function<RelDataTypeField, RexNode>() {
    @Override
    public RexNode apply(RelDataTypeField input) {
     return new RexInputRef(input.getIndex(), input.getType());

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

public void onMatch(RelOptRuleCall call) {
 final LogicalCorrelate correlate = call.rel(0);
 final RelNode left = call.rel(1);
 final Project aggOutputProject;
 final Aggregate aggregate;
 if (flavor) {
  aggOutputProject = call.rel(2);
  aggregate = call.rel(3);
 } else {
  aggregate = call.rel(2);
  // Create identity projection
  final List<Pair<RexNode, String>> projects = Lists.newArrayList();
  final List<RelDataTypeField> fields =
      aggregate.getRowType().getFieldList();
  for (int i = 0; i < fields.size(); i++) {
   projects.add(RexInputRef.of2(projects.size(), fields));
  }
  aggOutputProject = (Project) RelOptUtil.createProject(
    aggregate, Pair.left(projects), Pair.right(projects), false, relBuilder);
 }
 onMatch2(call, correlate, left, aggOutputProject, aggregate);
}

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

List<RexNode> rightJoinKeys = Lists.newArrayList();
 List<RexNode> tmpCorrelatedJoinKeys = Lists.newArrayList();
 HiveRelOptUtil.splitCorrelatedFilterCondition(
     filter,
 List<RexFieldAccess> correlatedJoinKeys = Lists.newArrayList();
 List<RexInputRef> correlatedInputRefJoinKeys = Lists.newArrayList();
 for (RexNode joinKey : tmpCorrelatedJoinKeys) {
 int nFields = left.getRowType().getFieldCount();
 ImmutableBitSet allCols = ImmutableBitSet.range(nFields);
int nullIndicatorPos = join.getRowType().getFieldCount() - 1;
    new RexInputRef(
        nullIndicatorPos,
        cluster.getTypeFactory().createTypeWithNullability(
            join.getRowType().getFieldList()
                .get(nullIndicatorPos).getType(),
            true));
 joinOutputProjects.add(
     rexBuilder.makeInputRef(
         leftInputFieldType.getFieldList().get(i).getType(), i));

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

List<RexNode> tmpRightJoinKeys = Lists.newArrayList();
 List<RexNode> correlatedJoinKeys = Lists.newArrayList();
 HiveRelOptUtil.splitCorrelatedFilterCondition(
     filter,
     left.getRowType().getFieldCount()
         + rightJoinKeys.get(0).getIndex();
} else if (cm.mapRefRelToCorRef.containsKey(project)) {
     left.getRowType().getFieldCount()
         + right.getRowType().getFieldCount() - 1;
} else {
 return;

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

private RelNode genLateralViewPlans(ASTNode lateralView, Map<String, RelNode> aliasToRel)
    throws SemanticException {
 final RexBuilder rexBuilder = this.cluster.getRexBuilder();
 final RelDataTypeFactory dtFactory = this.cluster.getTypeFactory();
 final String inlineFunctionName =
   GenericUDTFInline.class.getAnnotation(Description.class).name();
 List<RexNode> inputRefs = Lists.transform(inputRel.getRowType().getFieldList(),
   input -> new RexInputRef(input.getIndex(), input.getType()));
  inputRefsTypes.add(inputRefs.get(i).getType());
 List<String> outputFieldNames = new ArrayList<>(inputRel.getRowType().getFieldNames());
 RexCall convertedOriginalValuesExpr = (RexCall) new RexNodeConverter(this.cluster, inputRel.getRowType(),
     inputPosMap, 0, false).convert(valuesExpr);
 RelDataType valuesRowType = ((ArraySqlType) convertedOriginalValuesExpr.getType()).getComponentType();
 List<RexNode> newStructExprs = new ArrayList<>();
 for (RexNode structExpr : convertedOriginalValuesExpr.getOperands()) {
  RexCall structCall = (RexCall) structExpr;
  List<RexNode> exprs = new ArrayList<>(inputRefs);
  exprs.addAll(structCall.getOperands());
  newStructExprs.add(rexBuilder.makeCall(structCall.op, exprs));
     columnAliases.size() != valuesRowType.getFieldCount()) {

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

RexNodeConverter rexNodeConv = new RexNodeConverter(cluster, srcRel.getRowType(),
    outerNameToPosMap, buildHiveColNameToInputPosMap(col_list, inputRR), relToHiveRR.get(srcRel),
    outerRR, 0, false, subqueryId);
  List<RexNode> originalInputRefs = Lists.transform(srcRel.getRowType().getFieldList(),
    new Function<RelDataTypeField, RexNode>() {
     @Override
     public RexNode apply(RelDataTypeField input) {
      return new RexInputRef(input.getIndex(), input.getType());
 ImmutableBitSet groupSet = ImmutableBitSet.range(outputRel.getRowType().getFieldList().size());
 outputRel = new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION),
    outputRel, groupSet, null, new ArrayList<AggregateCall>());
 RowResolver groupByOutputRowResolver = new RowResolver();

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

RelNode leftRel = inputRels[0];
RelNode rightRel = inputRels[1];
RexBuilder rexBuilder = leftRel.getCluster().getRexBuilder();
RexNode outJoinCond = null;
int origLeftInputSize = leftRel.getRowType().getFieldCount();
int origRightInputSize = rightRel.getRowType().getFieldCount();
 final RelDataTypeField field = leftRel.getRowType().getFieldList().get(i);
 newLeftFields.add(rexBuilder.makeInputRef(field.getType(), i));
 newLeftFieldNames.add(field.getName());
 final RelDataTypeField field = rightRel.getRowType().getFieldList().get(i);
 newRightFields.add(rexBuilder.makeInputRef(field.getType(), i));
 newRightFieldNames.add(field.getName());
  origColEqConds.add(Pair.of(((RexInputRef) leftKey).getIndex(),
    ((RexInputRef) rightKey).getIndex()));
  origColEqCondsPosBuilder.set(i);
 } else {
 rightKeys.add(origRightInputSize + i);
 RexNode cond = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
   rexBuilder.makeInputRef(newLeftFields.get(origLeftInputSize + i).getType(), newLeftOffset + i),
   rexBuilder.makeInputRef(newRightFields.get(origRightInputSize + i).getType(), newRightOffset + i));
 if (outJoinCond == null) {

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

public static ExprNodeDesc getExprNode(Integer inputRefIndx, RelNode inputRel,
  ExprNodeConverter exprConv) {
 ExprNodeDesc exprNode = null;
 RexNode rexInputRef = new RexInputRef(inputRefIndx, inputRel.getRowType()
   .getFieldList().get(inputRefIndx).getType());
 exprNode = rexInputRef.accept(exprConv);
 return exprNode;
}

代码示例来源: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())));
      HiveParser.TOK_GROUPING_SETS_EXPRESSION, "TOK_GROUPING_SETS_EXPRESSION");
  for (int i : groupSet) {
   RexInputRef iRef = new RexInputRef(i, groupBy.getCluster().getTypeFactory()
     .createSqlType(SqlTypeName.ANY));
   expression.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder())));
ASTNode cond = having.getCondition().accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder()));
hiveAST.having = ASTBuilder.having(cond);
ASTNode function = buildUDTFAST(call.getOperator().getName(), children);
sel.add(function);
for (String alias : udtf.getRowType().getFieldNames()) {
 sel.add(HiveParser.Identifier, alias);

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

gbInfo.outputColNames.addAll(aggRel.getRowType().getFieldNames());
  aggInputRel.getRowType(), new HashSet<Integer>(), aggRel.getCluster().getTypeFactory(),
  true);
 RexInputRef iRef = new RexInputRef(i, aggInputRel.getRowType().getFieldList()
   .get(i).getType());
 tmpExprNodeDesc = iRef.accept(exprConv);
 gbInfo.gbKeys.add(tmpExprNodeDesc);
 gbInfo.gbKeyColNamesInInput.add(aggInputRel.getRowType().getFieldNames().get(i));
 gbInfo.gbKeyTypes.add(tmpExprNodeDesc.getTypeInfo());

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

RexUtil.composeConjunction(rexBuilder, conditions, false);
 RelNode newRel = HiveSemiJoin.getSemiJoin(frame.r.getCluster(), frame.r.getTraitSet(),
   join.getLeft(), join.getRight(), condition, join.getLeftKeys(), join.getRightKeys());
    rightFrame.r.getRowType().getFieldList();
  conditions.add(
    rexBuilder.makeCall(callOp,
      RexInputRef.of(newLeftPos, newLeftOutput),
      new RexInputRef(newLeftFieldCount + newRightPos,
        newRightOutput.get(newRightPos).getType())));
 } else {
  conditions.add(
    rexBuilder.makeCall(callOp,
      new RexInputRef(newLeftFieldCount + newRightPos,
        newRightOutput.get(newRightPos).getType()),
      RexInputRef.of(newLeftPos, newLeftOutput)));
int oldLeftFieldCount = oldLeft.getRowType().getFieldCount();
int oldRightFieldCount = oldRight.getRowType().getFieldCount();
   rel.getCluster().traitSetOf(HiveRelNode.CONVENTION), leftFrame.r, rightFrame.r,
   condition, ImmutableIntList.copyOf(leftKeys), ImmutableIntList.copyOf(rightKeys));

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

/** Infers the alias of an expression.
 *
 * <p>If the expression was created by {@link #alias}, replaces the expression
 * in the project list.
 */
private String inferAlias(List<RexNode> exprList, RexNode expr) {
 switch (expr.getKind()) {
 case INPUT_REF:
  final RexInputRef ref = (RexInputRef) expr;
  return peek(0).getRowType().getFieldNames().get(ref.getIndex());
 case CAST:
  return inferAlias(exprList, ((RexCall) expr).getOperands().get(0));
 case AS:
  final RexCall call = (RexCall) expr;
  for (;;) {
   final int i = exprList.indexOf(expr);
   if (i < 0) {
    break;
   }
   exprList.set(i, call.getOperands().get(0));
  }
  return ((NlsString) ((RexLiteral) call.getOperands().get(1)).getValue())
    .getValue();
 default:
  return null;
 }
}

相关文章