/** * Generates a cast from one row type to another * * @param rexBuilder RexBuilder to use for constructing casts * @param lhsRowType target row type * @param rhsRowType source row type; fields must be 1-to-1 with lhsRowType, in same order * @return cast expressions */ public static RexNode[] generateCastExpressions( RexBuilder rexBuilder, RelDataType lhsRowType, RelDataType rhsRowType) { int n = rhsRowType.getFieldCount(); assert n == lhsRowType.getFieldCount() : "field count: lhs [" + lhsRowType + "] rhs [" + rhsRowType + "]"; RexNode[] rhsExps = new RexNode[n]; for (int i = 0; i < n; ++i) { rhsExps[i] = rexBuilder.makeInputRef(rhsRowType.getFields()[i].getType(), i); } return generateCastExpressions(rexBuilder, lhsRowType, rhsExps); }
public Void visitInputRef(RexInputRef inputRef) { super.visitInputRef(inputRef); if (inputRef.getIndex() >= inputRowType.getFieldCount()) { throw new IllegalForwardRefException(); } return null; }
public RelDataType inferReturnType(SqlOperatorBinding opBinding) { assert opBinding.getOperandCount() == 1; final RelDataType recordType = opBinding.getOperandType(0); boolean isStruct = recordType.isStruct(); int fieldCount = recordType.getFieldCount(); assert isStruct && (fieldCount == 1); RelDataTypeField fieldType = recordType.getFieldList().get(0); assert fieldType != null : "expected a record type with one field: " + recordType; final RelDataType firstColType = fieldType.getType(); return opBinding.getTypeFactory().createTypeWithNullability(firstColType, true); }