/** * Generates code to cast an OJ expression as another type. The target type is limited to being an * AssignableValue. See class description for an explanation of the arguments. * * @return resulting expression. If lhsExp was provided, assigns this expression to lhsExp. */ public Expression convertCastToAssignableValue( FarragoRexToOJTranslator translator, StatementList stmtList, RelDataType lhsType, RelDataType rhsType, Expression lhsExp, Expression rhsExp) { CastHelper helper = new CastHelper(translator, stmtList, null, lhsType, rhsType, lhsExp, rhsExp); return helper.castToAssignableValue(); }
/** * Generates code to cast an OJ expression as another type. See class description for an * explanation of arguments. * * @return resulting expression. If lhsExp was provided, assigns this expression to lhsExp. */ public Expression convertCastOrAssignment( FarragoRexToOJTranslator translator, StatementList stmtList, String targetName, RelDataType lhsType, RelDataType rhsType, Expression lhsExp, Expression rhsExp) { CastHelper helper = new CastHelper(translator, stmtList, targetName, lhsType, rhsType, lhsExp, rhsExp); return helper.implement(); }
// implement FarragoOJRexImplementor public Expression implementFarrago( FarragoRexToOJTranslator translator, RexCall call, Expression[] operands) { RelDataType lhsType = call.getType(); RelDataType rhsType = call.operands[0].getType(); Expression rhsExp = operands[0]; SqlTypeName lhsTypeName = lhsType.getSqlTypeName(); if ((lhsTypeName == SqlTypeName.CURSOR) || (lhsTypeName == SqlTypeName.COLUMN_LIST)) { // Conversion should already have been taken care of outside. return rhsExp; } // NOTE jvs 19-Nov-2008: In some cases (e.g. FRG-273) a cast // may be illegal at the SQL level, but allowable as part of // implementation, so don't try to enforce // SqlTypeUtil.canCastFrom here. Anything which was supposed // to have been prevented should already have been caught // by the validator. CastHelper helper = new CastHelper(translator, null, call.toString(), lhsType, rhsType, null, rhsExp); return helper.implement(); }