use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.
the class HazelcastCoalesceFunction method checkOperandTypes.
@Override
protected boolean checkOperandTypes(HazelcastCallBinding callBinding, boolean throwOnFailure) {
HazelcastSqlValidator validator = callBinding.getValidator();
SqlValidatorScope scope = callBinding.getScope();
SqlBasicCall sqlCall = (SqlBasicCall) callBinding.getCall();
List<SqlNode> operandList = sqlCall.getOperandList();
List<RelDataType> argTypes = new ArrayList<>(operandList.size());
for (SqlNode node : operandList) {
argTypes.add(validator.deriveType(scope, node));
}
assert !argTypes.isEmpty();
RelDataType returnType = argTypes.stream().reduce(HazelcastTypeUtils::withHigherPrecedence).get();
for (int i = 0; i < operandList.size(); i++) {
int finalI = i;
boolean elementTypeCoerced = validator.getTypeCoercion().rowTypeElementCoercion(scope, operandList.get(i), returnType, sqlNode -> sqlCall.getOperands()[finalI] = sqlNode);
if (!elementTypeCoerced) {
if (throwOnFailure) {
throw validator.newValidationError(sqlCall, RESOURCES.cannotInferCaseResult(argTypes.toString(), getName()));
} else {
return false;
}
}
}
return true;
}
Aggregations