use of com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram in project hazelcast by hazelcast.
the class HazelcastSqlOperandMetadata method checkOperandTypes.
@Override
public final boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
HazelcastCallBinding binding = prepareBinding(callBinding, operandTypeInference);
boolean checkResult;
if (ValidationUtil.hasAssignment(binding.getCall())) {
OperandChecker[] checkers = parameters.stream().map(HazelcastTableFunctionParameter::checker).toArray(OperandChecker[]::new);
checkResult = new NamedOperandCheckerProgram(checkers).check(binding, throwOnFailure);
} else {
OperandChecker[] checkers = parameters.stream().limit(binding.getOperandCount()).map(HazelcastTableFunctionParameter::checker).toArray(OperandChecker[]::new);
checkResult = new OperandCheckerProgram(checkers).check(binding, throwOnFailure);
}
return checkResult && checkOperandTypes(binding, throwOnFailure);
}
use of com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram in project hazelcast by hazelcast.
the class HazelcastArithmeticOperatorUtils method checkOperandTypes.
public static boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure, SqlKind kind) {
RelDataType firstType = binding.getOperandType(0);
RelDataType secondType = binding.getOperandType(1);
if (isTemporalType(firstType) || isTemporalType(secondType)) {
return checkTemporalOperands(binding, throwOnFailure, kind, firstType, secondType);
}
if (!isNumericType(firstType) || !isNumericType(secondType)) {
return fail(binding, throwOnFailure);
}
RelDataType type = HazelcastTypeUtils.withHigherPrecedence(firstType, secondType);
switch(kind) {
case PLUS:
case MINUS:
case DIVIDE:
if (HazelcastTypeUtils.isNumericIntegerType(type)) {
int bitWidth = ((HazelcastIntegerType) type).getBitWidth() + 1;
type = HazelcastIntegerType.create(bitWidth, type.isNullable());
}
break;
case TIMES:
if (HazelcastTypeUtils.isNumericIntegerType(type)) {
assert firstType instanceof HazelcastIntegerType;
assert secondType instanceof HazelcastIntegerType;
int firstBitWidth = ((HazelcastIntegerType) firstType).getBitWidth();
int secondBitWidth = ((HazelcastIntegerType) secondType).getBitWidth();
type = HazelcastIntegerType.create(firstBitWidth + secondBitWidth, type.isNullable());
}
break;
default:
// For the MOD operation, we just pick the operand with a higher precedence, but do not extend the width.
assert kind == SqlKind.MOD;
// Like many major databases, we do not support inexact numeric operands.
if (HazelcastTypeUtils.isNumericInexactType(type)) {
return fail(binding, throwOnFailure);
}
}
TypedOperandChecker checker = TypedOperandChecker.forType(type);
return new OperandCheckerProgram(checker, checker).check(binding, throwOnFailure);
}
use of com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram in project hazelcast by hazelcast.
the class HazelcastAndOrPredicate method checkOperandTypes.
@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
OperandChecker[] checkers = new OperandChecker[binding.getOperandCount()];
Arrays.fill(checkers, TypedOperandChecker.BOOLEAN);
return new OperandCheckerProgram(checkers).check(binding, throwOnFailure);
}
Aggregations