@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) }; } }
newInferredType, inferredType.getCharset(), inferredType.getCollation());
public SqlCollation getCollation() { return delegate.getCollation(); }
public SqlCollation getCollation() { return delegate.getCollation(); }
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() + "'"); } } } }
if (t0.getCollation() == null) { throw new AssertionError("RelDataType object should have been assigned " + "a (default) collation when calling deriveType"); } else if (!t0.getCollation().getCharset().equals( t1.getCollation().getCharset())) { return false;
@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[]{ EMPTY_CATALOG, // 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) }; } }
charset = typeFactory.getDefaultCharset(); SqlCollation collation = type.getCollation(); if (collation == null) { collation = SqlCollation.IMPLICIT;
charset = typeFactory.getDefaultCharset(); SqlCollation collation = type.getCollation(); if (collation == null) { collation = SqlCollation.IMPLICIT;
charset = typeFactory.getDefaultCharset(); SqlCollation collation = type.getCollation(); if (collation == null) { collation = SqlCollation.IMPLICIT;
SqlCollation col1 = operandType1.getCollation(); SqlCollation col2 = operandType2.getCollation(); assert (null != col1) && (null != col2) : "An implicit or explicit collation should have been set";
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; }
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 void checkCollation( String expression, String expectedCollationName, SqlCollation.Coercibility expectedCoercibility) { for (String sql : buildQueries(expression)) { RelDataType actualType = getColumnType(sql); SqlCollation collation = actualType.getCollation(); assertEquals( expectedCollationName, collation.getCollationName()); assertEquals(expectedCoercibility, collation.getCoercibility()); } }
public void checkCollation( String expression, String expectedCollationName, SqlCollation.Coercibility expectedCoercibility) { for (String sql : buildQueries(expression)) { RelDataType actualType = getColumnType(sql); SqlCollation collation = actualType.getCollation(); assertEquals( expectedCollationName, collation.getCollationName()); assertEquals(expectedCoercibility, collation.getCoercibility()); } }
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()); }