private SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType) { return currentType.equals(desiredType) || (currentType.isNullable() != desiredType.isNullable() && typeFactory.createTypeWithNullability(currentType, desiredType.isNullable()).equals(desiredType)) ? node : SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, SqlTypeUtil.convertTypeToSpec(desiredType)); }
private SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex) { SqlNode arg; if (argRex != null && !argRex.getType().equals(varType)) { arg = SqlStdOperatorTable.CAST.createCall( pos, argInput, SqlTypeUtil.convertTypeToSpec(varType)); } else { arg = argInput; } return arg; } }
private SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex) { SqlNode arg; if (argRex != null && !argRex.getType().equals(varType)) { arg = SqlStdOperatorTable.CAST.createCall( pos, argInput, SqlTypeUtil.convertTypeToSpec(varType)); } else { arg = argInput; } return arg; } }
private SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex) { SqlNode arg; if (argRex != null && !argRex.getType().equals(varType)) { arg = SqlStdOperatorTable.CAST.createCall( pos, argInput, SqlTypeUtil.convertTypeToSpec(varType)); } else { arg = argInput; } return arg; } }
private SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex) { SqlNode arg; if (argRex != null && !argRex.getType().equals(varType)) { arg = SqlStdOperatorTable.CAST.createCall( pos, argInput, SqlTypeUtil.convertTypeToSpec(varType)); } else { arg = argInput; } return arg; } }
/** * Creates and registers a convertlet for an operator in which * the SQL representation needs the result type appended * as an extra argument (e.g. CAST). * * @param op operator instance */ private void registerTypeAppendOp(final SqlOperator op) { registerOp( op, (converter, call) -> { SqlNode[] operands = convertExpressionList(converter, call.operands); if (operands == null) { return null; } List<SqlNode> operandList = new ArrayList<>(Arrays.asList(operands)); SqlDataTypeSpec typeSpec = SqlTypeUtil.convertTypeToSpec(call.getType()); operandList.add(typeSpec); return new SqlBasicCall( op, operandList.toArray(new SqlNode[0]), SqlParserPos.ZERO); }); }
private SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType) { return currentType.equals(desiredType) || (currentType.isNullable() != desiredType.isNullable() && typeFactory.createTypeWithNullability(currentType, desiredType.isNullable()).equals(desiredType)) ? node : SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, SqlTypeUtil.convertTypeToSpec(desiredType)); }
private SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType) { return currentType.equals(desiredType) || (currentType.isNullable() != desiredType.isNullable() && typeFactory.createTypeWithNullability(currentType, desiredType.isNullable()).equals(desiredType)) ? node : SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, SqlTypeUtil.convertTypeToSpec(desiredType)); }
/** * Creates and registers a convertlet for an operator in which * the SQL representation needs the result type appended * as an extra argument (e.g. CAST). * * @param op operator instance */ private void registerTypeAppendOp(final SqlOperator op) { registerOp( op, (converter, call) -> { SqlNode[] operands = convertExpressionList(converter, call.operands); if (operands == null) { return null; } List<SqlNode> operandList = new ArrayList<>(Arrays.asList(operands)); SqlDataTypeSpec typeSpec = SqlTypeUtil.convertTypeToSpec(call.getType()); operandList.add(typeSpec); return new SqlBasicCall( op, operandList.toArray(new SqlNode[0]), SqlParserPos.ZERO); }); }
public SqlNode getCastSpec(RelDataType type) { if (type instanceof BasicSqlType) { return new SqlDataTypeSpec( new SqlIdentifier(type.getSqlTypeName().name(), SqlParserPos.ZERO), type.getPrecision(), type.getScale(), type.getCharset() != null && supportsCharSet() ? type.getCharset().name() : null, null, SqlParserPos.ZERO); } return SqlTypeUtil.convertTypeToSpec(type); }
@Before public void setUp() { JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT); integerDataType = typeFactory.createSqlType(SqlTypeName.INTEGER); integerType = SqlTypeUtil.convertTypeToSpec(integerDataType); rexBuilder = new RexBuilder(typeFactory); }
@Before public void setUp() { JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT); integerDataType = typeFactory.createSqlType(SqlTypeName.INTEGER); integerType = SqlTypeUtil.convertTypeToSpec(integerDataType); rexBuilder = new RexBuilder(typeFactory); }
public SqlNode getCastSpec(RelDataType type) { if (type instanceof BasicSqlType) { int precision = type.getPrecision(); switch (type.getSqlTypeName()) { case VARCHAR: // if needed, adjust varchar length to max length supported by the system int maxPrecision = getTypeSystem().getMaxPrecision(type.getSqlTypeName()); if (type.getPrecision() > maxPrecision) { precision = maxPrecision; } } return new SqlDataTypeSpec( new SqlIdentifier(type.getSqlTypeName().name(), SqlParserPos.ZERO), precision, type.getScale(), type.getCharset() != null && supportsCharSet() ? type.getCharset().name() : null, null, SqlParserPos.ZERO); } return SqlTypeUtil.convertTypeToSpec(type); }
private SqlNode toSql(RelDataType type) { switch (dialect.getDatabaseProduct()) { case MYSQL: switch (type.getSqlTypeName()) { case VARCHAR: // MySQL doesn't have a VARCHAR type, only CHAR. return new SqlDataTypeSpec(new SqlIdentifier("CHAR", POS), type.getPrecision(), -1, null, null, POS); case INTEGER: return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", POS), type.getPrecision(), -1, null, null, POS); } break; } if (type instanceof BasicSqlType) { return new SqlDataTypeSpec( new SqlIdentifier(type.getSqlTypeName().name(), POS), type.getPrecision(), type.getScale(), type.getCharset() != null && dialect.supportsCharSet() ? type.getCharset().name() : null, null, POS); } return SqlTypeUtil.convertTypeToSpec(type); //throw new AssertionError(type); // TODO: implement }