use of com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType in project hazelcast by hazelcast.
the class HazelcastAbsFunction method checkOperandTypes.
@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
RelDataType operandType = binding.getOperandType(0);
if (HazelcastTypeUtils.isNumericIntegerType(operandType)) {
int bitWidth = ((HazelcastIntegerType) operandType).getBitWidth();
operandType = HazelcastIntegerType.create(bitWidth + 1, operandType.isNullable());
}
TypedOperandChecker checker = TypedOperandChecker.forType(operandType);
if (checker.isNumeric()) {
return checker.check(binding, throwOnFailure, 0);
}
if (throwOnFailure) {
throw binding.newValidationSignatureError();
} else {
return false;
}
}
use of com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType in project hazelcast by hazelcast.
the class HazelcastUnaryOperator method checkOperandTypes.
@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
RelDataType operandType = binding.getOperandType(0);
if (HazelcastTypeUtils.isNumericIntegerType(operandType) && extend) {
int bitWidth = ((HazelcastIntegerType) operandType).getBitWidth();
operandType = HazelcastIntegerType.create(bitWidth + 1, operandType.isNullable());
}
TypedOperandChecker checker = TypedOperandChecker.forType(operandType);
if (checker.isNumeric()) {
return checker.check(binding, throwOnFailure, 0);
}
if (throwOnFailure) {
throw binding.newValidationSignatureError();
} else {
return false;
}
}
use of com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType 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);
}
Aggregations