use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class TypedOperandChecker method coerce.
@Override
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
protected boolean coerce(HazelcastSqlValidator validator, HazelcastCallBinding callBinding, SqlNode operand, RelDataType operandType, int operandIndex) {
if (targetTypeName == SqlTypeName.ROW || targetTypeName == SqlTypeName.COLUMN_LIST) {
return false;
}
QueryDataType targetType0 = getTargetHazelcastType();
QueryDataType operandType0 = HazelcastTypeUtils.toHazelcastType(operandType);
boolean canCoerce = isTemporalType(operandType) && isTemporalType(targetTypeName) || isNumericType(operandType) && isNumericType(targetTypeName) || // we can assign VARCHAR to JSON fields
operandType.getSqlTypeName() == SqlTypeName.VARCHAR && type != null && type.getFamily() == HazelcastJsonType.FAMILY;
if (!canCoerce) {
return false;
}
if (targetType0.getTypeFamily().getPrecedence() < operandType0.getTypeFamily().getPrecedence()) {
// Cannot convert type with higher precedence to lower precedence (e.g. DOUBLE to INTEGER)
return false;
}
// Otherwise, we are good to go. Construct the new type of the operand.
RelDataType newOperandType = getTargetType(validator.getTypeFactory(), operandType.isNullable());
// Perform coercion
validator.getTypeCoercion().coerceOperandType(callBinding.getScope(), callBinding.getCall(), operandIndex, newOperandType);
return true;
}
Aggregations