Search in sources :

Example 1 with OperandCheckerProgram

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);
}
Also used : NamedOperandCheckerProgram(com.hazelcast.jet.sql.impl.validate.operand.NamedOperandCheckerProgram) OperandChecker(com.hazelcast.jet.sql.impl.validate.operand.OperandChecker) OperandCheckerProgram(com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram) NamedOperandCheckerProgram(com.hazelcast.jet.sql.impl.validate.operand.NamedOperandCheckerProgram) HazelcastCallBinding(com.hazelcast.jet.sql.impl.validate.HazelcastCallBinding)

Example 2 with OperandCheckerProgram

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);
}
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)

Example 3 with OperandCheckerProgram

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);
}
Also used : OperandChecker(com.hazelcast.jet.sql.impl.validate.operand.OperandChecker) TypedOperandChecker(com.hazelcast.jet.sql.impl.validate.operand.TypedOperandChecker) OperandCheckerProgram(com.hazelcast.jet.sql.impl.validate.operand.OperandCheckerProgram)

Aggregations

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