Search in sources :

Example 1 with HazelcastTableFunctionParameter

use of com.hazelcast.jet.sql.impl.schema.HazelcastTableFunctionParameter in project hazelcast by hazelcast.

the class HazelcastOperandTypeInference method inferOperandTypes.

@Override
public void inferOperandTypes(SqlCallBinding callBinding, RelDataType returnType, RelDataType[] operandTypes) {
    SqlCall call = callBinding.getCall();
    if (ValidationUtil.hasAssignment(call)) {
        RelDataTypeFactory typeFactory = callBinding.getTypeFactory();
        RelDataType[] parameterTypes = new RelDataType[parametersByName.size()];
        for (int i = 0; i < call.operandCount(); i++) {
            SqlCall assignment = call.operand(i);
            SqlIdentifier id = assignment.operand(1);
            String name = id.getSimple();
            HazelcastTableFunctionParameter parameter = parametersByName.get(name);
            if (parameter != null) {
                SqlTypeName parameterType = parameter.type();
                parameterTypes[parameter.ordinal()] = toType(parameterType, typeFactory);
            } else {
                throw SqlUtil.newContextException(id.getParserPosition(), RESOURCE.unknownArgumentName(name));
            }
        }
        // noinspection ResultOfMethodCallIgnored
        Arrays.stream(parameterTypes).filter(Objects::nonNull).toArray(ignored -> operandTypes);
    } else {
        positionalOperandTypeInference.inferOperandTypes(callBinding, returnType, operandTypes);
    }
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) SqlCall(org.apache.calcite.sql.SqlCall) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) HazelcastTableFunctionParameter(com.hazelcast.jet.sql.impl.schema.HazelcastTableFunctionParameter) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Aggregations

HazelcastTableFunctionParameter (com.hazelcast.jet.sql.impl.schema.HazelcastTableFunctionParameter)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 SqlCall (org.apache.calcite.sql.SqlCall)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1