Search in sources :

Example 6 with HazelcastSqlValidator

use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.

the class HazelcastConcatOperator method checkOperandTypes.

@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
    HazelcastSqlValidator validator = binding.getValidator();
    for (int i = 0; i < binding.getOperandCount(); i++) {
        SqlNode operand = binding.operand(i);
        RelDataType operandType = binding.getOperandType(i);
        if (operandType.getSqlTypeName() != VARCHAR) {
            // Coerce everything to VARCHAR
            RelDataType newOperandType = HazelcastTypeUtils.createType(validator.getTypeFactory(), VARCHAR, operandType.isNullable());
            validator.getTypeCoercion().coerceOperandType(binding.getScope(), binding.getCall(), i, newOperandType);
        }
        // Set parameter converters
        if (operand.getKind() == SqlKind.DYNAMIC_PARAM) {
            int paramIndex = ((SqlDynamicParam) operand).getIndex();
            ParameterConverter paramConverter = new AnyToVarcharParameterConverter(paramIndex, operand.getParserPosition());
            validator.setParameterConverter(paramIndex, paramConverter);
        }
    }
    return true;
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Example 7 with HazelcastSqlValidator

use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.

the class HazelcastConcatWSOperator method checkOperandTypes.

@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
    HazelcastSqlValidator validator = binding.getValidator();
    if (binding.getOperandType(0).getSqlTypeName() != VARCHAR) {
        if (throwOnFailure) {
            throw binding.newValidationSignatureError();
        }
        return false;
    }
    for (int i = 1; i < binding.getOperandCount(); i++) {
        SqlNode operand = binding.operand(i);
        RelDataType operandType = binding.getOperandType(i);
        if (operandType.getSqlTypeName() != VARCHAR) {
            // Coerce everything to VARCHAR
            RelDataType newOperandType = HazelcastTypeUtils.createType(validator.getTypeFactory(), VARCHAR, operandType.isNullable());
            validator.getTypeCoercion().coerceOperandType(binding.getScope(), binding.getCall(), i, newOperandType);
        }
        // Set parameter converters
        if (operand.getKind() == SqlKind.DYNAMIC_PARAM) {
            int paramIndex = ((SqlDynamicParam) operand).getIndex();
            ParameterConverter paramConverter = new AnyToVarcharParameterConverter(paramIndex, operand.getParserPosition());
            validator.setParameterConverter(paramIndex, paramConverter);
        }
    }
    return true;
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) ParameterConverter(com.hazelcast.sql.impl.ParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) AnyToVarcharParameterConverter(com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Example 8 with HazelcastSqlValidator

use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.

the class HazelcastDynamicTableFunction method toArguments.

private static List<Object> toArguments(String functionName, List<HazelcastTableFunctionParameter> parameters, SqlOperatorBinding callBinding) {
    SqlCallBinding binding = (SqlCallBinding) callBinding;
    SqlCall call = binding.getCall();
    HazelcastSqlValidator validator = (HazelcastSqlValidator) binding.getValidator();
    return ValidationUtil.hasAssignment(call) ? fromNamedArguments(functionName, parameters, call, validator) : fromPositionalArguments(functionName, parameters, call, validator);
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)

Example 9 with HazelcastSqlValidator

use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.

the class HazelcastBetweenOperator method checkOperandTypes.

@Override
protected boolean checkOperandTypes(HazelcastCallBinding callBinding, boolean throwOnFailure) {
    assert callBinding.getOperandCount() == OPERANDS;
    for (int i = 0; i < OPERANDS; ++i) {
        RelDataType type = callBinding.getOperandType(i);
        // fast fail-forward path.
        if (type.getComparability().ordinal() < RelDataTypeComparability.ALL.ordinal()) {
            if (throwOnFailure) {
                throw callBinding.newValidationSignatureError();
            } else {
                return false;
            }
        }
    }
    HazelcastSqlValidator validator = callBinding.getValidator();
    RelDataType winningType = withHigherPrecedence(callBinding.getOperandType(0), withHigherPrecedence(callBinding.getOperandType(1), callBinding.getOperandType(2)));
    QueryDataType winnerQueryDataType = toHazelcastType(winningType);
    // Set more flexible parameter converter that allows TINYINT/SMALLINT/INTEGER -> BIGINT conversions.
    if (winnerQueryDataType.getTypeFamily().isNumeric()) {
        setNumericParameterConverter(validator, callBinding.getCall().getOperandList().get(1), winnerQueryDataType);
        setNumericParameterConverter(validator, callBinding.getCall().getOperandList().get(2), winnerQueryDataType);
    }
    return true;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)

Example 10 with HazelcastSqlValidator

use of com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator in project hazelcast by hazelcast.

the class HazelcastComparisonPredicateUtils method checkOperandTypes.

public static boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
    SqlNode first = binding.operand(0);
    SqlNode second = binding.operand(1);
    HazelcastSqlValidator validator = binding.getValidator();
    RelDataType firstType = validator.deriveType(binding.getScope(), first);
    RelDataType secondType = validator.deriveType(binding.getScope(), second);
    assert !firstType.equals(validator.getUnknownType());
    assert !secondType.equals(validator.getUnknownType());
    return checkOperandTypes(binding, throwOnFailure, validator, first, firstType, second, secondType);
}
Also used : HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

HazelcastSqlValidator (com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)11 RelDataType (org.apache.calcite.rel.type.RelDataType)8 SqlNode (org.apache.calcite.sql.SqlNode)7 SqlCall (org.apache.calcite.sql.SqlCall)3 AnyToVarcharParameterConverter (com.hazelcast.jet.sql.impl.validate.param.AnyToVarcharParameterConverter)2 ParameterConverter (com.hazelcast.sql.impl.ParameterConverter)2 ArrayList (java.util.ArrayList)2 SqlCallBinding (org.apache.calcite.sql.SqlCallBinding)2 SqlDynamicParam (org.apache.calcite.sql.SqlDynamicParam)2 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 SqlValidatorScope (org.apache.calcite.sql.validate.SqlValidatorScope)2 DistributionTraitDef (com.hazelcast.jet.sql.impl.opt.distribution.DistributionTraitDef)1 QueryConverter (com.hazelcast.jet.sql.impl.parse.QueryConverter)1 QueryParser (com.hazelcast.jet.sql.impl.parse.QueryParser)1 HazelcastCallBinding (com.hazelcast.jet.sql.impl.validate.HazelcastCallBinding)1 HazelcastResources (com.hazelcast.jet.sql.impl.validate.HazelcastResources)1 HazelcastSqlCase (com.hazelcast.jet.sql.impl.validate.operators.special.HazelcastSqlCase)1 HazelcastReturnTypeInference.wrap (com.hazelcast.jet.sql.impl.validate.operators.typeinference.HazelcastReturnTypeInference.wrap)1 HazelcastTypeUtils (com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils)1 HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName (com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName)1