if (SqlTypeUtil.inCharFamily(inferredType)) { newInferredType = typeFactory.createTypeWithCharsetAndCollation(
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(); }
/** * Constructs a type with charset and collation. * * <p>This must be a character type. */ BasicSqlType createWithCharsetAndCollation(Charset charset, SqlCollation collation) { Preconditions.checkArgument(SqlTypeUtil.inCharFamily(this)); return new BasicSqlType(this.typeSystem, this.typeName, this.isNullable, this.precision, this.scale, collation, SerializableCharset.forCharset(charset)); }
/** * Constructs a type with charset and collation. * * <p>This must be a character tyoe. */ BasicSqlType createWithCharsetAndCollation( Charset charset, SqlCollation collation) { Preconditions.checkArgument(SqlTypeUtil.inCharFamily(this)); BasicSqlType ret; try { ret = (BasicSqlType) this.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(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() + "'"); } } } }
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() + "'"); } } } }
/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. * * @deprecated Use {@link #value(SqlNode)} */ @Deprecated // to be removed before 2.0 public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (node instanceof SqlCall && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) { //noinspection deprecation return stringValue(((SqlCall) node).operand(0)); } else { throw new AssertionError("invalid string literal: " + node); } }
/** * Extracts the string value from a string literal, a chain of string * literals, or a CAST of a string literal. * * @deprecated Use {@link #value(SqlNode)} */ @Deprecated // to be removed before 2.0 public static String stringValue(SqlNode node) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (SqlUtil.isLiteralChain(node)) { final SqlLiteral literal = SqlLiteralChainOperator.concatenateOperands((SqlCall) node); assert SqlTypeUtil.inCharFamily(literal.getTypeName()); return literal.value.toString(); } else if (node instanceof SqlCall && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) { //noinspection deprecation return stringValue(((SqlCall) node).operand(0)); } else { throw new AssertionError("invalid string literal: " + node); } }
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; } }
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 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) { 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); }
@Override public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) { final int count = callBinding.getOperandCount(); for (int i = 1; i < count; i += 2) { RelDataType nameType = callBinding.getOperandType(i); if (!SqlTypeUtil.inCharFamily(nameType)) { if (throwOnFailure) { throw callBinding.newError(RESOURCE.expectedCharacter()); } return false; } if (nameType.isNullable()) { if (throwOnFailure) { throw callBinding.newError( RESOURCE.argumentMustNotBeNull( callBinding.operand(i).toString())); } return false; } } return true; }
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()); }