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); }
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 }