Search in sources :

Example 11 with HazelcastSqlValidator

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

the class HazelcastCoalesceFunction method checkOperandTypes.

@Override
protected boolean checkOperandTypes(HazelcastCallBinding callBinding, boolean throwOnFailure) {
    HazelcastSqlValidator validator = callBinding.getValidator();
    SqlValidatorScope scope = callBinding.getScope();
    SqlBasicCall sqlCall = (SqlBasicCall) callBinding.getCall();
    List<SqlNode> operandList = sqlCall.getOperandList();
    List<RelDataType> argTypes = new ArrayList<>(operandList.size());
    for (SqlNode node : operandList) {
        argTypes.add(validator.deriveType(scope, node));
    }
    assert !argTypes.isEmpty();
    RelDataType returnType = argTypes.stream().reduce(HazelcastTypeUtils::withHigherPrecedence).get();
    for (int i = 0; i < operandList.size(); i++) {
        int finalI = i;
        boolean elementTypeCoerced = validator.getTypeCoercion().rowTypeElementCoercion(scope, operandList.get(i), returnType, sqlNode -> sqlCall.getOperands()[finalI] = sqlNode);
        if (!elementTypeCoerced) {
            if (throwOnFailure) {
                throw validator.newValidationError(sqlCall, RESOURCES.cannotInferCaseResult(argTypes.toString(), getName()));
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) ArrayList(java.util.ArrayList) 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