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