Class TypeInferenceUtil
- java.lang.Object
-
- org.apache.flink.table.types.inference.TypeInferenceUtil
-
@Internal public final class TypeInferenceUtil extends Object
Utility for performing type inference.It assumes that argument assignments have been applied by argument reordering and inserting values for optional arguments.
The following steps summarize the type inference process.
- 1. Validate number of arguments.
- 2. For resolving unknown (NULL) operands: Access the outer wrapping call and try to get its
operand type for the return type of the actual call. E.g. for
takes_string(this_function(NULL))infer operands fromtakes_string(NULL)and use the inferred string type as the return type ofthis_function(NULL). - 3. Try infer unknown operands, fail if not possible.
- 4. Perform input type validation.
- 5. Infer return type.
- 6. (Optional) Infer state types.
- 7. In the planner: Call the strategies again at any point in time to enrich a DataType that has been created from a logical type with a conversion class.
- 8. In the planner: Check for an implementation evaluation method matching the operands. The
matching happens class-based. Thus, for example,
eval(Object)is valid for (INT). Oreval(Object...)is valid for (INT, STRING). We rely on the conversion classes specified byDataType.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeInferenceUtil.ResultThe result of a type inference run.static classTypeInferenceUtil.StateInfoResult of runningStateTypeStrategy.static interfaceTypeInferenceUtil.SurroundingInfoInformation what the outer world (i.e. an outer wrapping call) expects from the current function call.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CallContextcastArguments(TypeInference typeInference, CallContext callContext, DataType outputType)Casts the call's argument if necessary.static ValidationExceptioncreateInvalidCallException(CallContext callContext, ValidationException cause)Returns an exception for an invalid call to a function.static ValidationExceptioncreateInvalidInputException(TypeInference typeInference, CallContext callContext, ValidationException cause)Returns an exception for invalid input arguments.static TableExceptioncreateUnexpectedException(CallContext callContext, Throwable cause)Returns an exception for an unexpected error during type inference.static StringgenerateSignature(TypeInference typeInference, String name, FunctionDefinition definition)Generates a signature of the givenFunctionDefinition.static DataTypeinferOutputType(CallContext callContext, TypeStrategy outputTypeStrategy)Infers an output type using the givenTypeStrategy.static LinkedHashMap<String,TypeInferenceUtil.StateInfo>inferStateInfos(CallContext callContext, LinkedHashMap<String,StateTypeStrategy> stateTypeStrategies)InfersTypeInferenceUtil.StateInfos using the givenStateTypeStrategys.static TypeInferenceUtil.ResultrunTypeInference(TypeInference typeInference, CallContext callContext, TypeInferenceUtil.SurroundingInfo surroundingInfo)Runs the entire type inference process.static booleanvalidateArgumentCount(ArgumentCount argumentCount, int actualCount, boolean throwOnFailure)Validates argument counts.
-
-
-
Method Detail
-
runTypeInference
public static TypeInferenceUtil.Result runTypeInference(TypeInference typeInference, CallContext callContext, @Nullable TypeInferenceUtil.SurroundingInfo surroundingInfo)
Runs the entire type inference process.- Parameters:
typeInference- type inference of the current callcallContext- call context of the current callsurroundingInfo- information about the outer wrapping call of a current function call for performing input type inference
-
castArguments
public static CallContext castArguments(TypeInference typeInference, CallContext callContext, @Nullable DataType outputType)
Casts the call's argument if necessary.
-
inferOutputType
public static DataType inferOutputType(CallContext callContext, TypeStrategy outputTypeStrategy)
Infers an output type using the givenTypeStrategy. It assumes that input arguments have been adapted before if necessary.
-
inferStateInfos
public static LinkedHashMap<String,TypeInferenceUtil.StateInfo> inferStateInfos(CallContext callContext, LinkedHashMap<String,StateTypeStrategy> stateTypeStrategies)
InfersTypeInferenceUtil.StateInfos using the givenStateTypeStrategys. It assumes that input arguments have been adapted before if necessary.
-
generateSignature
public static String generateSignature(TypeInference typeInference, String name, FunctionDefinition definition)
Generates a signature of the givenFunctionDefinition.
-
createInvalidInputException
public static ValidationException createInvalidInputException(TypeInference typeInference, CallContext callContext, ValidationException cause)
Returns an exception for invalid input arguments.
-
createInvalidCallException
public static ValidationException createInvalidCallException(CallContext callContext, ValidationException cause)
Returns an exception for an invalid call to a function.
-
createUnexpectedException
public static TableException createUnexpectedException(CallContext callContext, Throwable cause)
Returns an exception for an unexpected error during type inference.
-
validateArgumentCount
public static boolean validateArgumentCount(ArgumentCount argumentCount, int actualCount, boolean throwOnFailure)
Validates argument counts.- Parameters:
argumentCount- expected argument countactualCount- actual argument countthrowOnFailure- if true, the function throws aValidationExceptionif the actual value does not meet the expected argument count- Returns:
- a boolean indicating if expected argument counts match the actual counts
-
-