/** * Adds an expression to the list of common expressions, and returns a * reference to the expression. <b>DOES NOT CHECK WHETHER THE EXPRESSION * ALREADY EXISTS</b>. * * @param expr Expression * @return Reference to expression */ public RexLocalRef addExpr(RexNode expr) { RexLocalRef ref; final int index = exprList.size(); exprList.add(expr); ref = new RexLocalRef( index, expr.getType()); localRefList.add(ref); return ref; }
/** * Adds an expression to the list of common expressions, and returns a * reference to the expression. <b>DOES NOT CHECK WHETHER THE EXPRESSION * ALREADY EXISTS</b>. * * @param expr Expression * @return Reference to expression */ public RexLocalRef addExpr(RexNode expr) { RexLocalRef ref; final int index = exprList.size(); exprList.add(expr); ref = new RexLocalRef( index, expr.getType()); localRefList.add(ref); return ref; }
public RexNode visitLocalRef(RexLocalRef localRef) { final int index = localRef.getIndex(); if (index < inputFieldCount) { // Reference to input field. return localRef; } return new RexLocalRef( flattenedAggCallList.size() + index, localRef.getType()); } };
/** * Creates a reference to a given input field. * * @param index Ordinal of input field, must be less than the number of * fields in the input type * @return Reference to input field */ public RexLocalRef makeInputRef(int index) { final List<RelDataTypeField> fields = inputRowType.getFieldList(); assert index < fields.size(); final RelDataTypeField field = fields.get(index); return new RexLocalRef( index, field.getType()); }
/** * Creates a reference to a given input field. * * @param index Ordinal of input field, must be less than the number of * fields in the input type * @return Reference to input field */ public RexLocalRef makeInputRef(int index) { final List<RelDataTypeField> fields = inputRowType.getFieldList(); assert index < fields.size(); final RelDataTypeField field = fields.get(index); return new RexLocalRef( index, field.getType()); }
public RexNode visitLocalRef(RexLocalRef localRef) { final int index = localRef.getIndex(); if (index < inputFieldCount) { // Reference to input field. return localRef; } return new RexLocalRef( flattenedAggCallList.size() + index, localRef.getType()); } };
public RexNode visitInputRef(RexInputRef input) { final int index = exprInverseOrdinals[input.getIndex()]; assert index >= 0; return new RexLocalRef( index, input.getType()); }
public RexNode visitInputRef(RexInputRef input) { final int index = exprInverseOrdinals[input.getIndex()]; assert index >= 0; return new RexLocalRef( index, input.getType()); }
public RexNode visitLocalRef(RexLocalRef local) { // A reference to a local variable becomes a reference to an input // if the local was computed at a previous level. final int localIndex = local.getIndex(); final int exprLevel = exprLevels[localIndex]; if (exprLevel < level) { if (allExprs[localIndex] instanceof RexLiteral) { // Expression is to be inlined. Use the original expression. return allExprs[localIndex]; } int inputIndex = indexOf(localIndex, inputExprOrdinals); assert inputIndex >= 0; return new RexLocalRef( inputIndex, local.getType()); } else { // It's a reference to what was a local expression at the // previous level, and was then projected. final int exprIndex = exprInverseOrdinals[localIndex]; return new RexLocalRef( exprIndex, local.getType()); } } }
public RexNode visitLocalRef(RexLocalRef local) { // A reference to a local variable becomes a reference to an input // if the local was computed at a previous level. final int localIndex = local.getIndex(); final int exprLevel = exprLevels[localIndex]; if (exprLevel < level) { if (allExprs[localIndex] instanceof RexLiteral) { // Expression is to be inlined. Use the original expression. return allExprs[localIndex]; } int inputIndex = indexOf(localIndex, inputExprOrdinals); assert inputIndex >= 0; return new RexLocalRef( inputIndex, local.getType()); } else { // It's a reference to what was a local expression at the // previous level, and was then projected. final int exprIndex = exprInverseOrdinals[localIndex]; return new RexLocalRef( exprIndex, local.getType()); } } }
public RexNode visitLocalRef(RexLocalRef local) { final int index = local.getIndex(); int target = permutation.getTarget(index); return new RexLocalRef( target, local.getType()); } }
public RexNode visitLocalRef(RexLocalRef local) { final int index = local.getIndex(); int target = permutation.getTarget(index); return new RexLocalRef( target, local.getType()); } }
/** * 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<>(); final List<RexInputRef> refs = new ArrayList<>(); 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); }
/** * 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<>(); final List<RexInputRef> refs = new ArrayList<>(); 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); }
assert index >= 0; RexNode expr = allExprs[projectExprOrdinal]; projectRefs.add(new RexLocalRef(index, expr.getType())); final int index = exprInverseOrdinals[conditionExprOrdinal]; conditionRef = new RexLocalRef( index, allExprs[conditionExprOrdinal].getType());
assert index >= 0; RexNode expr = allExprs[projectExprOrdinal]; projectRefs.add(new RexLocalRef(index, expr.getType())); final int index = exprInverseOrdinals[conditionExprOrdinal]; conditionRef = new RexLocalRef( index, allExprs[conditionExprOrdinal].getType());
final int source = permutation.getSource(i); projectRefList.add( new RexLocalRef( source, fields.get(source).getType()));
final int source = permutation.getSource(i); projectRefList.add( new RexLocalRef( source, fields.get(source).getType()));
final Ord<RelDataType> newField = getNewFieldForOldInput(conditionRef.getIndex()); programBuilder.addCondition(new RexLocalRef(newField.i, newField.e));
final Ord<RelDataType> newField = getNewFieldForOldInput(conditionRef.getIndex()); programBuilder.addCondition(new RexLocalRef(newField.i, newField.e));