@Override public Object[] apply(final RelDataTypeField field) { final RelDataType type = field.getType(); boolean isNumeric = SqlTypeName.NUMERIC_TYPES.contains(type.getSqlTypeName()); boolean isCharacter = SqlTypeName.CHAR_TYPES.contains(type.getSqlTypeName()); boolean isDateTime = SqlTypeName.DATETIME_TYPES.contains(type.getSqlTypeName()); return new Object[]{ CATALOG_NAME, // TABLE_CATALOG schemaName, // TABLE_SCHEMA tableName, // TABLE_NAME field.getName(), // COLUMN_NAME String.valueOf(field.getIndex()), // ORDINAL_POSITION "", // COLUMN_DEFAULT type.isNullable() ? "YES" : "NO", // IS_NULLABLE type.getSqlTypeName().toString(), // DATA_TYPE null, // CHARACTER_MAXIMUM_LENGTH null, // CHARACTER_OCTET_LENGTH isNumeric ? String.valueOf(type.getPrecision()) : null, // NUMERIC_PRECISION isNumeric ? "10" : null, // NUMERIC_PRECISION_RADIX isNumeric ? String.valueOf(type.getScale()) : null, // NUMERIC_SCALE isDateTime ? String.valueOf(type.getPrecision()) : null, // DATETIME_PRECISION isCharacter ? type.getCharset().name() : null, // CHARACTER_SET_NAME isCharacter ? type.getCollation().getCollationName() : null, // COLLATION_NAME Long.valueOf(type.getSqlTypeName().getJdbcOrdinal()) // JDBC_TYPE (Druid extension) }; } }
typeFactory.createTypeWithCharsetAndCollation( newInferredType, inferredType.getCharset(), inferredType.getCollation());
/** * Checks whether a type represents Unicode character data. * * @param type type to test * @return whether type represents Unicode character data */ public static boolean isUnicode(RelDataType type) { Charset charset = type.getCharset(); if (charset == null) { return false; } return charset.name().startsWith("UTF"); }
/** * Checks whether a type represents Unicode character data. * * @param type type to test * @return whether type represents Unicode character data */ public static boolean isUnicode(RelDataType type) { Charset charset = type.getCharset(); if (charset == null) { return false; } return charset.name().startsWith("UTF"); }
/** * Checks whether a type represents Unicode character data. * * @param type type to test * @return whether type represents Unicode character data */ public static boolean isUnicode(RelDataType type) { Charset charset = type.getCharset(); if (charset == null) { return false; } return charset.name().startsWith("UTF"); }
public Charset getCharset() { return delegate.getCharset(); }
public Charset getCharset() { return delegate.getCharset(); }
/** * Determines whether two types both have different character sets. If one * or the other type has no character set (e.g. in cast from INT to * VARCHAR), that is not a mismatch. * * @param t1 first type * @param t2 second type * @return true iff mismatched */ public static boolean areCharacterSetsMismatched( RelDataType t1, RelDataType t2) { if (isAny(t1) || isAny(t2)) { return false; } Charset cs1 = t1.getCharset(); Charset cs2 = t2.getCharset(); if ((cs1 != null) && (cs2 != null)) { if (!cs1.equals(cs2)) { return true; } } return false; }
/** * Determines whether two types both have different character sets. If one * or the other type has no character set (e.g. in cast from INT to * VARCHAR), that is not a mismatch. * * @param t1 first type * @param t2 second type * @return true iff mismatched */ public static boolean areCharacterSetsMismatched( RelDataType t1, RelDataType t2) { if (isAny(t1) || isAny(t2)) { return false; } Charset cs1 = t1.getCharset(); Charset cs2 = t2.getCharset(); if ((cs1 != null) && (cs2 != null)) { if (!cs1.equals(cs2)) { return true; } } return false; }
/** * Determines whether two types both have different character sets. If one * or the other type has no character set (e.g. in cast from INT to * VARCHAR), that is not a mismatch. * * @param t1 first type * @param t2 second type * @return true iff mismatched */ public static boolean areCharacterSetsMismatched( RelDataType t1, RelDataType t2) { if (isAny(t1) || isAny(t2)) { return false; } Charset cs1 = t1.getCharset(); Charset cs2 = t2.getCharset(); if ((cs1 != null) && (cs2 != null)) { if (!cs1.equals(cs2)) { return true; } } return false; }
public static void checkCharsetAndCollateConsistentIfCharType( RelDataType type) { // (every charset must have a default collation) if (SqlTypeUtil.inCharFamily(type)) { Charset strCharset = type.getCharset(); Charset colCharset = type.getCollation().getCharset(); assert null != strCharset; assert null != colCharset; if (!strCharset.equals(colCharset)) { if (false) { // todo: enable this checking when we have a charset to // collation mapping throw new Error(type.toString() + " was found to have charset '" + strCharset.name() + "' and a mismatched collation charset '" + colCharset.name() + "'"); } } } }
public static void checkCharsetAndCollateConsistentIfCharType( RelDataType type) { // (every charset must have a default collation) if (SqlTypeUtil.inCharFamily(type)) { Charset strCharset = type.getCharset(); Charset colCharset = type.getCollation().getCharset(); assert null != strCharset; assert null != colCharset; if (!strCharset.equals(colCharset)) { if (false) { // todo: enable this checking when we have a charset to // collation mapping throw new Error(type.toString() + " was found to have charset '" + strCharset.name() + "' and a mismatched collation charset '" + colCharset.name() + "'"); } } } }
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 void checkCharset( String expression, Charset expectedCharset) { for (String sql : buildQueries(expression)) { RelDataType actualType = getColumnType(sql); Charset actualCharset = actualType.getCharset(); if (!expectedCharset.equals(actualCharset)) { fail("\n" + "Expected=" + expectedCharset.name() + "\n" + " actual=" + actualCharset.name()); } } }
public void checkCharset( String expression, Charset expectedCharset) { for (String sql : buildQueries(expression)) { RelDataType actualType = getColumnType(sql); Charset actualCharset = actualType.getCharset(); if (!expectedCharset.equals(actualCharset)) { fail("\n" + "Expected=" + expectedCharset.name() + "\n" + " actual=" + actualCharset.name()); } } }
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); }
protected RelDataType adjustType( SqlValidator validator, SqlCall call, RelDataType type) { if (SqlTypeUtil.inCharFamily(type)) { // Determine coercibility and resulting collation name of // unary operator if needed. RelDataType operandType = validator.getValidatedNodeType(call.operand(0)); if (null == operandType) { throw new AssertionError("operand's type should have been derived"); } if (SqlTypeUtil.inCharFamily(operandType)) { SqlCollation collation = operandType.getCollation(); assert null != collation : "An implicit or explicit collation should have been set"; type = validator.getTypeFactory() .createTypeWithCharsetAndCollation( type, type.getCharset(), new SqlCollation( collation.getCollationName(), collation.getCoercibility())); } } return type; }
protected RelDataType adjustType( SqlValidator validator, SqlCall call, RelDataType type) { if (SqlTypeUtil.inCharFamily(type)) { // Determine coercibility and resulting collation name of // unary operator if needed. RelDataType operandType = validator.getValidatedNodeType(call.operand(0)); if (null == operandType) { throw new AssertionError("operand's type should have been derived"); } if (SqlTypeUtil.inCharFamily(operandType)) { SqlCollation collation = operandType.getCollation(); assert null != collation : "An implicit or explicit collation should have been set"; type = validator.getTypeFactory() .createTypeWithCharsetAndCollation( type, type.getCharset(), new SqlCollation( collation.getCollationName(), collation.getCoercibility())); } } return type; }
public RelDataType transformType( SqlOperatorBinding opBinding, RelDataType typeToTransform) { switch (typeToTransform.getSqlTypeName()) { case VARCHAR: case VARBINARY: return typeToTransform; } SqlTypeName retTypeName = toVar(typeToTransform); RelDataType ret = opBinding.getTypeFactory().createSqlType( retTypeName, typeToTransform.getPrecision()); if (SqlTypeUtil.inCharFamily(typeToTransform)) { ret = opBinding.getTypeFactory() .createTypeWithCharsetAndCollation( ret, typeToTransform.getCharset(), typeToTransform.getCollation()); } return opBinding.getTypeFactory().createTypeWithNullability( ret, typeToTransform.isNullable()); }
public RelDataType transformType( SqlOperatorBinding opBinding, RelDataType typeToTransform) { switch (typeToTransform.getSqlTypeName()) { case VARCHAR: case VARBINARY: return typeToTransform; } SqlTypeName retTypeName = toVar(typeToTransform); RelDataType ret = opBinding.getTypeFactory().createSqlType( retTypeName, typeToTransform.getPrecision()); if (SqlTypeUtil.inCharFamily(typeToTransform)) { ret = opBinding.getTypeFactory() .createTypeWithCharsetAndCollation( ret, typeToTransform.getCharset(), typeToTransform.getCollation()); } return opBinding.getTypeFactory().createTypeWithNullability( ret, typeToTransform.isNullable()); }