Class TypeInferenceUtil
java.lang.Object
org.apache.flink.table.types.inference.TypeInferenceUtil
Utility for performing type inference.
The following steps summarize the envisioned type inference process. Not all features are implemented or exposed through the API yet (*).
- 1. Validate number of arguments.
- 2. (*) Apply assignment operators on the call by permuting operands and adding default
values. These are preparations for
CallContext. - 3. 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). - 4. Try infer unknown operands, fail if not possible.
- 5. (*) Check the usage of DEFAULT operands are correct using validator.isOptional().
- 6. Perform input type validation.
- 7. (Optional) Infer accumulator type.
- 8. Infer return type.
- 9. (*) 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.
- 10. (*) 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). Or eval(Object...) is valid for (INT, STRING). We rely on the conversion classes specified by DataType.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe result of a type inference run.static interfaceInformation what the outer world (i.e. an outer wrapping call) expects from the current function call. -
Method Summary
Modifier and TypeMethodDescriptionstatic CallContextadaptArguments(TypeInference typeInference, CallContext callContext, DataType outputType) Adapts 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 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 Details
-
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
-
adaptArguments
public static CallContext adaptArguments(TypeInference typeInference, CallContext callContext, @Nullable DataType outputType) Adapts the call's argument if necessary.This includes casts that need to be inserted, reordering of arguments (*), or insertion of default values (*) where (*) is future work.
-
inferOutputType
Infers an output type using the givenTypeStrategy. 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
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
-