use of com.hazelcast.jet.sql.impl.validate.HazelcastCallBinding in project hazelcast by hazelcast.
the class CoalesceOperandTypeInference method inferOperandTypes.
@Override
public void inferOperandTypes(SqlCallBinding binding, RelDataType returnType, RelDataType[] operandTypes) {
if (operandTypes.length == 0) {
// will be handled later
return;
}
assert binding.getOperandCount() == operandTypes.length;
boolean hasParameters = HazelcastTypeUtils.hasParameters(binding);
List<Integer> unknownOperandIndexes = new ArrayList<>();
RelDataType knownType = null;
int knownTypePrecedence = Integer.MIN_VALUE;
for (int i = 0; i < binding.getOperandCount(); i++) {
operandTypes[i] = binding.getOperandType(i);
if (!operandTypes[i].equals(binding.getValidator().getUnknownType())) {
if (hasParameters && toHazelcastType(operandTypes[i]).getTypeFamily().isNumericInteger()) {
// If there are parameters in the operands, widen all the integers to BIGINT so that an expression
// `COALESCE(1, ?)` is resolved to `COALESCE((BIGINT)1, (BIGINT)?)` rather than
// `COALESCE((TINYINT)1, (TINYINT)?)`
operandTypes[i] = createType(binding.getTypeFactory(), SqlTypeName.BIGINT, operandTypes[i].isNullable());
}
int precedence = precedenceOf(operandTypes[i]);
if (knownTypePrecedence < precedence) {
knownType = operandTypes[i];
knownTypePrecedence = precedence;
}
} else {
unknownOperandIndexes.add(i);
}
}
// since we cannot deduce the return type
if (knownType == null || knownType.getSqlTypeName() == SqlTypeName.NULL && hasParameters) {
throw new HazelcastCallBinding(binding).newValidationSignatureError();
}
for (Integer index : unknownOperandIndexes) {
operandTypes[index] = knownType;
}
}
Aggregations