public JavaType( Class clazz, boolean nullable, Charset charset, SqlCollation collation) { super(fieldsOf(clazz)); this.clazz = clazz; this.nullable = nullable; assert (charset != null) == SqlTypeUtil.inCharFamily(this) : "Need to be a chartype"; this.charset = charset; this.collation = collation; computeDigest(); }
public JavaType( Class clazz, boolean nullable, Charset charset, SqlCollation collation) { super(fieldsOf(clazz)); this.clazz = clazz; this.nullable = nullable; assert (charset != null) == SqlTypeUtil.inCharFamily(this) : "Need to be a chartype"; this.charset = charset; this.collation = collation; computeDigest(); }
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() + "'"); } } } }
/** * Constructs a type with charset and collation * * @pre SqlTypeUtil.inCharFamily(this) */ BasicSqlType createWithCharsetAndCollation( Charset charset, SqlCollation collation) { Util.pre(SqlTypeUtil.inCharFamily(this), "Not an chartype"); BasicSqlType ret; try { ret = (BasicSqlType) this.clone(); } catch (CloneNotSupportedException e) { throw Util.newInternal(e); } ret.wrappedCharset = SerializableCharset.forCharset(charset); ret.collation = collation; ret.computeDigest(); return ret; }
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() + "'"); } } } }
/** * Constructs a type with charset and collation * * @pre SqlTypeUtil.inCharFamily(this) */ BasicSqlType createWithCharsetAndCollation( Charset charset, SqlCollation collation) { Util.pre(SqlTypeUtil.inCharFamily(this), "Not an chartype"); BasicSqlType ret; try { ret = (BasicSqlType) this.clone(); } catch (CloneNotSupportedException e) { throw Util.newInternal(e); } ret.wrappedCharset = SerializableCharset.forCharset(charset); ret.collation = collation; ret.computeDigest(); return ret; }
RelDataType t1 = argTypes.get(j + 1); if (!inCharFamily(t0) || !inCharFamily(t1)) { return false;
private RelDataType copySimpleType( RelDataType type, boolean nullable) { if (type instanceof JavaType) { JavaType javaType = (JavaType) type; if (SqlTypeUtil.inCharFamily(javaType)) { return new JavaType( javaType.clazz, nullable, javaType.charset, javaType.collation); } else { return new JavaType( nullable ? Primitive.box(javaType.clazz) : Primitive.unbox(javaType.clazz), nullable); } } else { // REVIEW: RelCrossType if it stays around; otherwise get rid of // this comment return type; } }
private RelDataType copySimpleType( RelDataType type, boolean nullable) { if (type instanceof JavaType) { JavaType javaType = (JavaType) type; if (SqlTypeUtil.inCharFamily(javaType)) { return new JavaType( javaType.clazz, nullable, javaType.charset, javaType.collation); } else { return new JavaType( nullable ? Primitive.box(javaType.clazz) : Primitive.unbox(javaType.clazz), nullable); } } else { // REVIEW: RelCrossType if it stays around; otherwise get rid of // this comment return type; } }
/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. */ public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.toValue(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.toValue(); } else if (node instanceof SqlCall && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) { return stringValue(((SqlCall) node).operand(0)); } else { throw Util.newInternal("invalid string literal: " + node); } }
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.operands[0]); if (null == operandType) { throw Util.newInternal( "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; }
/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. */ public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.toValue(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.toValue(); } else if ( (node instanceof SqlCall) && (((SqlCall) node).getOperator() == SqlStdOperatorTable.castFunc)) { return stringValue(((SqlCall) node).getOperands()[0]); } else { throw Util.newInternal("invalid string literal: " + node); } }
RelDataType type) if (SqlTypeUtil.inCharFamily(type)) { "operand's type should have been derived"); if (SqlTypeUtil.inCharFamily(operandType)) { SqlCollation collation = operandType.getCollation(); assert null != collation
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 Util.newInternal( "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 Util.newInternal( "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; }
RelDataTypeFactory typeFactory) if (!inCharFamily(type)) { return type;
public RelDataType createTypeWithCharsetAndCollation( RelDataType type, Charset charset, SqlCollation collation) { assert SqlTypeUtil.inCharFamily(type) : type; assert charset != null; assert collation != null; RelDataType newType; if (type instanceof BasicSqlType) { BasicSqlType sqlType = (BasicSqlType) type; newType = sqlType.createWithCharsetAndCollation(charset, collation); } else if (type instanceof JavaType) { JavaType javaType = (JavaType) type; newType = new JavaType( javaType.getJavaClass(), javaType.isNullable(), charset, collation); } else { throw Util.needToImplement("need to implement " + type); } return canonize(newType); }
public RelDataType createTypeWithCharsetAndCollation( RelDataType type, Charset charset, SqlCollation collation) { Util.pre( SqlTypeUtil.inCharFamily(type), "Not a chartype"); Util.pre(charset != null, "charset!=null"); Util.pre(collation != null, "collation!=null"); RelDataType newType; if (type instanceof BasicSqlType) { BasicSqlType sqlType = (BasicSqlType) type; newType = sqlType.createWithCharsetAndCollation(charset, collation); } else if (type instanceof JavaType) { JavaType javaType = (JavaType) type; newType = new JavaType( javaType.getJavaClass(), javaType.isNullable(), charset, collation); } else { throw Util.needToImplement("need to implement " + type); } return canonize(newType); }
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()); }