@Override public RexNode visitInputRef(RexInputRef input) { final int index = input.getIndex(); if (index < start) { return input; } return new RexInputRef(index + offset, input.getType()); } });
public RexNode get(int index) { final int pos = posList.get(index); return RexInputRef.of(pos, rowType); } });
if (origins.get(i) == i) { squished.put(i, newProjects.size()); newProjects.add(RexInputRef.of2(i, fields)); undoProjects.add( Pair.of( (RexNode) new RexInputRef( squished.get(origin), field.getType()), field.getName()));
@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; }
@Override public Pair<RexNode, String> get(int index) { if (index < leftCount) { RelDataTypeField field = fields.get(index); return Pair.<RexNode, String>of( new RexInputRef(index, field.getType()), field.getName()); } else { return Pair.<RexNode, String>of( extraLeftExprs.get(index - leftCount), null); } } },
final BitSet groupSet = aggregate.getGroupSet(); for (int i : BitSets.toIter(groupSet)) { refs.add(RexInputRef.of(i, aggFields)); new RexInputRef( groupCount + newAggCallList.size(), aggFields.get(groupCount + i).getType()));
/** * Adds an expression, deducing an appropriate name if possible. * * @param expr Expression * @param name Suggested name */ private void addExpr(RexNode expr, String name) { convertedInputExprs.add(expr); if ((name == null) && (expr instanceof RexInputRef)) { final int i = ((RexInputRef) expr).getIndex(); name = bb.root.getRowType().getFieldList().get(i).getName(); } if (convertedInputExprNames.contains(name)) { // In case like 'SELECT ... GROUP BY x, y, x', don't add // name 'x' twice. name = null; } convertedInputExprNames.add(name); }
projects.add(RexInputRef.of2(newChildPos, newChildOutput)); mapNewChildToProjOutputPos.put(newChildPos, newPos); : childMapCorVarToOutputPos.keySet()) { int newChildPos = childMapCorVarToOutputPos.get(corVar); projects.add(RexInputRef.of2(newChildPos, newChildOutput)); for (int i = 0; i < newChildOutput.size(); i++) { if (!mapNewChildToProjOutputPos.containsKey(i)) { projects.add(RexInputRef.of2(i, newChildOutput)); mapNewChildToProjOutputPos.put(i, newPos); newPos++; rexBuilder.makeCall( SqlStdOperatorTable.EQUALS, RexInputRef.of(newLeftPos, newLeftOutput), new RexInputRef( newLeftFieldCount + newRightPos, newRightOutput.get(newRightPos).getType()));
private MutableRel invert(MutableRel model, MutableRel input, MutableProject project) { if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("SubstitutionVisitor: invert:\n" + "model: " + model + "\n" + "input: " + input + "\n" + "project: " + project + "\n"); } final List<RexNode> exprList = new ArrayList<RexNode>(); final RexBuilder rexBuilder = model.cluster.getRexBuilder(); for (RelDataTypeField field : model.getRowType().getFieldList()) { exprList.add(rexBuilder.makeZeroLiteral(field.getType())); } for (Ord<RexNode> expr : Ord.zip(project.getProjects())) { if (expr.e instanceof RexInputRef) { final int target = ((RexInputRef) expr.e).getIndex(); exprList.set(expr.i, rexBuilder.ensureType(expr.e.getType(), RexInputRef.of(target, input.rowType), false)); } else { throw MatchFailed.INSTANCE; } } return MutableProject.of(model.rowType, input, exprList); } }
public Pair<RexNode, String> get(int index) { return RexInputRef.of2(index, fields); } };
/** * Creates a program that projects its input fields but with possibly * different names for the output fields. */ public static RexProgram createIdentity( RelDataType rowType, RelDataType outputRowType) { if (rowType != outputRowType && !Pair.right(rowType.getFieldList()).equals( Pair.right(outputRowType.getFieldList()))) { throw new IllegalArgumentException( "field type mismatch: " + rowType + " vs. " + outputRowType); } final List<RelDataTypeField> fields = rowType.getFieldList(); final List<RexLocalRef> projectRefs = new ArrayList<RexLocalRef>(); final List<RexInputRef> refs = new ArrayList<RexInputRef>(); for (int i = 0; i < fields.size(); i++) { final RexInputRef ref = RexInputRef.of(i, fields); refs.add(ref); projectRefs.add(new RexLocalRef(i, ref.getType())); } return new RexProgram(rowType, refs, projectRefs, null, outputRowType); }
boundInputRef.getType(), setOp);
/** * Creates an input variable. * * @param index Index of the field in the underlying row-type * @param type Type of the column */ public RexInputRef(int index, RelDataType type) { super(createName(index), index, type); }
private RelNode convertCursor(Blackboard bb, SubQuery subQuery) { final SqlCall cursorCall = (SqlCall) subQuery.node; assert cursorCall.operandCount() == 1; SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); int iCursor = bb.cursors.size(); bb.cursors.add(converted); subQuery.expr = new RexInputRef( iCursor, converted.getRowType()); return converted; }
final BitSet groupSet = aggregate.getGroupSet(); for (int i : Util.toIter(groupSet)) { refs.add(RexInputRef.of(i, aggFields)); new RexInputRef( groupCount + newAggCallList.size(), aggFields.get(groupCount + i).getType()));
RelDataTypeField getRootField(RexInputRef inputRef) { int fieldOffset = inputRef.getIndex(); for (RelNode input : inputs) { RelDataType rowType = input.getRowType(); if (rowType == null) { // TODO: remove this once leastRestrictive // is correctly implemented return null; } if (fieldOffset < rowType.getFieldCount()) { return rowType.getFieldList().get(fieldOffset); } fieldOffset -= rowType.getFieldCount(); } throw new AssertionError(); }
projects.add(RexInputRef.of2(newChildPos, newChildOutput)); mapNewChildToProjOutputPos.put(newChildPos, newPos); projects.add(RexInputRef.of2(newChildPos, newChildOutput)); for (int i = 0; i < newChildOutput.size(); i++) { if (!mapNewChildToProjOutputPos.containsKey(i)) { projects.add(RexInputRef.of2(i, newChildOutput)); mapNewChildToProjOutputPos.put(i, newPos); newPos++; rexBuilder.makeCall( SqlStdOperatorTable.equalsOperator, RexInputRef.of(newLeftPos, newLeftOutput), new RexInputRef( newLeftFieldCount + newRightPos, newRightOutput.get(newRightPos).getType()));
@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; } };