Search in sources :

Example 1 with TypedOperandChecker

use of com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker 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;
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastIntegerType(com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType) TypedOperandChecker(com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker)

Example 2 with TypedOperandChecker

use of com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker 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;
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastIntegerType(com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType) TypedOperandChecker(com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker)

Example 3 with TypedOperandChecker

use of com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker 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);
}
Also used : OperandCheckerProgram(com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram) RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastIntegerType(com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType) TypedOperandChecker(com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker)

Aggregations

TypedOperandChecker (com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker)3 HazelcastIntegerType (com.hazelcast.jet.sql.impl.validate.types.HazelcastIntegerType)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 OperandCheckerProgram (com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram)1