code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
51
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
default Set<String> listFunctions(boolean includeHiddenFunctions) { return listFunctions(); }
List names of all functions in this module. <p>A module can decide to hide certain functions. For example, internal functions that can be resolved via {@link #getFunctionDefinition(String)} but should not be listed by default. @param includeHiddenFunctions whether to list hidden functions or not @return a set of function names
listFunctions
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
Apache-2.0
default Optional<FunctionDefinition> getFunctionDefinition(String name) { return Optional.empty(); }
Get an optional of {@link FunctionDefinition} by a given name. <p>It includes hidden functions even though not listed in {@link #listFunctions()}. @param name name of the {@link FunctionDefinition}. @return an optional function definition
getFunctionDefinition
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
Apache-2.0
default Optional<DynamicTableSourceFactory> getTableSourceFactory() { return Optional.empty(); }
Returns a {@link DynamicTableSourceFactory} for creating source tables. <p>A factory is determined with the following precedence rule: <ul> <li>1. Factory provided by the corresponding catalog of a persisted table. <li>2. Factory provided by a module. <li>3. Factory discovered using Java SPI. </ul> <p>This will be called on loaded modules in the order in which they have been loaded. The first factory returned will be used. <p>This method can be useful to disable Java SPI completely or influence how temporary table sources should be created without a corresponding catalog.
getTableSourceFactory
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
Apache-2.0
default Optional<DynamicTableSinkFactory> getTableSinkFactory() { return Optional.empty(); }
Returns a {@link DynamicTableSinkFactory} for creating sink tables. <p>A factory is determined with the following precedence rule: <ul> <li>1. Factory provided by the corresponding catalog of a persisted table. <li>2. Factory provided by a module. <li>3. Factory discovered using Java SPI. </ul> <p>This will be called on loaded modules in the order in which they have been loaded. The first factory returned will be used. <p>This method can be useful to disable Java SPI completely or influence how temporary table sinks should be created without a corresponding catalog.
getTableSinkFactory
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
Apache-2.0
default Optional<ModelProviderFactory> getModelProviderFactory() { return Optional.empty(); }
Returns a {@link ModelProviderFactory} for creating model providers. <p>A factory is determined with the following precedence rule: <ul> <li>1. Factory provided by the corresponding catalog of a persisted model. See {@link Catalog#getFactory()} <li>2. Factory provided by a module. <li>3. Factory discovered using Java SPI. </ul> <p>This will be called on loaded modules in the order in which they have been loaded. The first factory returned will be used. <p>This method can be useful to disable Java SPI completely or influence how temporary model providers should be created without a corresponding catalog.
getModelProviderFactory
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
Apache-2.0
public static void validateTableSource(TableSource<?> tableSource, TableSchema schema) { List<RowtimeAttributeDescriptor> rowtimeAttributes = getRowtimeAttributes(tableSource); Optional<String> proctimeAttribute = getProctimeAttribute(tableSource); validateNoGeneratedColumns(schema); validateSingleRowtimeAttribute(rowtimeAttributes); validateRowtimeAttributesExistInSchema(rowtimeAttributes, schema); validateProctimeAttributesExistInSchema(proctimeAttribute, schema); validateLogicalToPhysicalMapping(tableSource, schema); validateTimestampExtractorArguments(rowtimeAttributes, tableSource); validateNotOverlapping(rowtimeAttributes, proctimeAttribute); }
Validates a TableSource. <ul> <li>checks that all fields of the schema can be resolved <li>checks that resolved fields have the correct type <li>checks that the time attributes are correctly configured. </ul> @param tableSource The {@link TableSource} for which the time attributes are checked.
validateTableSource
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
Apache-2.0
public static boolean hasRowtimeAttribute(TableSource<?> tableSource) { return !getRowtimeAttributes(tableSource).isEmpty(); }
Checks if the given {@link TableSource} defines a rowtime attribute. @param tableSource The table source to check. @return true if the given table source defines rowtime attribute
hasRowtimeAttribute
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
Apache-2.0
private static List<RowtimeAttributeDescriptor> getRowtimeAttributes( TableSource<?> tableSource) { if (tableSource instanceof DefinedRowtimeAttributes) { return ((DefinedRowtimeAttributes) tableSource).getRowtimeAttributeDescriptors(); } return Collections.emptyList(); }
Returns a list with all rowtime attribute descriptors of the {@link TableSource}.
getRowtimeAttributes
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
Apache-2.0
private static Optional<String> getProctimeAttribute(TableSource<?> tableSource) { if (tableSource instanceof DefinedProctimeAttribute) { return Optional.ofNullable( ((DefinedProctimeAttribute) tableSource).getProctimeAttribute()); } return Optional.empty(); }
Returns the proctime attribute of the {@link TableSource} if it is defined.
getProctimeAttribute
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/sources/TableSourceValidation.java
Apache-2.0
public LogicalType getLogicalType() { return logicalType; }
Returns the corresponding logical type. @return a parameterized instance of {@link LogicalType}
getLogicalType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
public Class<?> getConversionClass() { return conversionClass; }
Returns the corresponding conversion class for representing values. If no conversion class was defined manually, the default conversion defined by the logical type is used. @see LogicalType#getDefaultConversion() @return the expected conversion class
getConversionClass
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
public static List<String> getFieldNames(DataType dataType) { final LogicalType type = dataType.getLogicalType(); if (type.is(LogicalTypeRoot.DISTINCT_TYPE)) { return getFieldNames(dataType.getChildren().get(0)); } else if (isCompositeType(type)) { return LogicalTypeChecks.getFieldNames(type); } return Collections.emptyList(); }
Returns the first-level field names for the provided {@link DataType}. <p>Note: This method returns an empty list for every {@link DataType} that is not a composite type.
getFieldNames
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
public static List<DataType> getFieldDataTypes(DataType dataType) { final LogicalType type = dataType.getLogicalType(); if (type.is(LogicalTypeRoot.DISTINCT_TYPE)) { return getFieldDataTypes(dataType.getChildren().get(0)); } else if (isCompositeType(type)) { return dataType.getChildren(); } return Collections.emptyList(); }
Returns the first-level field data types for the provided {@link DataType}. <p>Note: This method returns an empty list for every {@link DataType} that is not a composite type.
getFieldDataTypes
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
public static int getFieldCount(DataType dataType) { return getFieldDataTypes(dataType).size(); }
Returns the count of the first-level fields for the provided {@link DataType}. <p>Note: This method returns {@code 0} for every {@link DataType} that is not a composite type.
getFieldCount
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
public static List<DataTypes.Field> getFields(DataType dataType) { final List<String> names = getFieldNames(dataType); final List<DataType> dataTypes = getFieldDataTypes(dataType); return IntStream.range(0, names.size()) .mapToObj(i -> DataTypes.FIELD(names.get(i), dataTypes.get(i))) .collect(Collectors.toList()); }
Returns an ordered list of fields starting from the provided {@link DataType}. <p>Note: This method returns an empty list for every {@link DataType} that is not a composite type.
getFields
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/DataType.java
Apache-2.0
Map<FunctionSignatureTemplate, FunctionOutputTemplate> extractOutputMapping() { try { return extractResultMappings( outputExtraction, FunctionTemplate::getOutputTemplate, outputVerification); } catch (Throwable t) { throw extractionError(t, "Error in extracting a signature to output mapping."); } }
Base utility for extracting function/procedure mappings from signature to result, e.g. from (INT, STRING) to BOOLEAN. <p>It can not only be used for {@link UserDefinedFunction}, but also for {@link Procedure} which is almost same to {@link UserDefinedFunction} with regard to extracting the mapping from signature to result.
extractOutputMapping
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
static ResultExtraction createStateFromParametersExtraction() { return (extractor, method) -> { final List<StateParameter> stateParameters = extractStateParameters(method); return createStateTemplateFromParameters(extractor, method, stateParameters); }; }
Extraction that uses the method parameters with {@link StateHint} for state entries.
createStateFromParametersExtraction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
private Map<FunctionSignatureTemplate, FunctionResultTemplate> collectMethodMappings( Method method, Set<FunctionTemplate> global, Set<FunctionResultTemplate> globalResultOnly, ResultExtraction resultExtraction, Function<FunctionTemplate, FunctionResultTemplate> accessor) { final Map<FunctionSignatureTemplate, FunctionResultTemplate> collectedMappingsPerMethod = new LinkedHashMap<>(); final Set<FunctionTemplate> local = extractLocalFunctionTemplates(method); final Set<FunctionResultTemplate> localResultOnly = findResultOnlyTemplates(local, accessor); final Set<FunctionTemplate> explicitMappings = findResultMappingTemplates(global, local, accessor); final FunctionResultTemplate resultOnly = findResultOnlyTemplate( globalResultOnly, localResultOnly, explicitMappings, accessor, getHintType()); final Set<FunctionSignatureTemplate> inputOnly = findInputOnlyTemplates(global, local, accessor); // add all explicit mappings because they contain complete signatures putExplicitMappings(collectedMappingsPerMethod, explicitMappings, inputOnly, accessor); // add result only template with explicit or extracted signatures putUniqueResultMappings(collectedMappingsPerMethod, resultOnly, inputOnly, method); // handle missing result by extraction with explicit or extracted signatures putExtractedResultMappings(collectedMappingsPerMethod, inputOnly, resultExtraction, method); return collectedMappingsPerMethod; }
Extracts mappings from signature to result (either accumulator or output) for the given method. It considers both global hints for the entire function and local hints just for this method. <p>The algorithm aims to find an input signature for every declared result. If no result is declared, it will be extracted. If no input signature is declared, it will be extracted.
collectMethodMappings
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
private static Method correctVarArgMethod(Method method) { final int paramCount = method.getParameterCount(); final Class<?>[] paramClasses = method.getParameterTypes(); if (paramCount > 0 && paramClasses[paramCount - 1].getName().equals("scala.collection.Seq")) { final Type[] paramTypes = method.getGenericParameterTypes(); final ParameterizedType seqType = (ParameterizedType) paramTypes[paramCount - 1]; final Type varArgType = seqType.getActualTypeArguments()[0]; return ExtractionUtils.collectMethods(method.getDeclaringClass(), method.getName()) .stream() .filter(Method::isVarArgs) .filter(candidate -> candidate.getParameterCount() == paramCount) .filter( candidate -> { final Type[] candidateParamTypes = candidate.getGenericParameterTypes(); for (int i = 0; i < paramCount - 1; i++) { if (candidateParamTypes[i] != paramTypes[i]) { return false; } } final Class<?> candidateVarArgType = candidate.getParameterTypes()[paramCount - 1]; return candidateVarArgType.isArray() && // check for Object is needed in case of Scala primitives // (e.g. Int) (varArgType == Object.class || candidateVarArgType.getComponentType() == varArgType); }) .findAny() .orElse(method); } return method; }
Special case for Scala which generates two methods when using var-args (a {@code Seq < String >} and {@code String...}). This method searches for the Java-like variant.
correctVarArgMethod
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
private void putExplicitMappings( Map<FunctionSignatureTemplate, FunctionResultTemplate> collectedMappings, Set<FunctionTemplate> explicitMappings, Set<FunctionSignatureTemplate> signatureOnly, Function<FunctionTemplate, FunctionResultTemplate> accessor) { explicitMappings.forEach( t -> { // signature templates are valid everywhere and are added to the explicit // mapping Stream.concat(signatureOnly.stream(), Stream.of(t.getSignatureTemplate())) .forEach(v -> putMapping(collectedMappings, v, accessor.apply(t))); }); }
Explicit mappings with complete signature to result declaration.
putExplicitMappings
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
private void putUniqueResultMappings( Map<FunctionSignatureTemplate, FunctionResultTemplate> collectedMappings, @Nullable FunctionResultTemplate uniqueResult, Set<FunctionSignatureTemplate> signatureOnly, Method method) { if (uniqueResult == null) { return; } // input only templates are valid everywhere if they don't exist fallback to extraction if (!signatureOnly.isEmpty()) { signatureOnly.forEach(s -> putMapping(collectedMappings, s, uniqueResult)); } else { putMapping(collectedMappings, signatureExtraction.extract(this, method), uniqueResult); } }
Result only template with explicit or extracted signatures.
putUniqueResultMappings
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
private void verifyMappingForMethod( Method method, Map<FunctionSignatureTemplate, FunctionResultTemplate> collectedMappingsPerMethod, @Nullable MethodVerification verification) { if (verification == null) { return; } collectedMappingsPerMethod.forEach( (signature, result) -> { if (result instanceof FunctionStateTemplate) { final FunctionStateTemplate stateTemplate = (FunctionStateTemplate) result; verification.verify(method, stateTemplate, signature, null); } else if (result instanceof FunctionOutputTemplate) { final FunctionOutputTemplate outputTemplate = (FunctionOutputTemplate) result; verification.verify(method, null, signature, outputTemplate); } }); }
Checks if the given method can be called and returns what hints declare.
verifyMappingForMethod
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/BaseMappingExtractor.java
Apache-2.0
public static DataType extractFromType(DataTypeFactory typeFactory, Type type) { return extractDataTypeWithClassContext( typeFactory, DataTypeTemplate.fromDefaults(), null, type, ""); }
Extracts a data type from a type without considering surrounding classes or templates.
extractFromType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
public static DataType extractFromType( DataTypeFactory typeFactory, DataTypeTemplate template, Type type) { return extractDataTypeWithClassContext(typeFactory, template, null, type, ""); }
Extracts a data type from a type without considering surrounding classes but templates.
extractFromType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
public static DataType extractFromGeneric( DataTypeFactory typeFactory, Class<?> baseClass, int genericPos, Type contextType) { final TypeVariable<?> variable = baseClass.getTypeParameters()[genericPos]; return extractDataTypeWithClassContext( typeFactory, DataTypeTemplate.fromDefaults(), contextType, variable, String.format( " in generic class '%s' in %s", baseClass.getName(), contextType.toString())); }
Extracts a data type from a type variable at {@code genericPos} of {@code baseClass} using the information of the most specific type {@code contextType}.
extractFromGeneric
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
public static DataType extractFromMethodParameter( DataTypeFactory typeFactory, Class<?> baseClass, Method method, int paramPos) { final Parameter parameter = method.getParameters()[paramPos]; final DataTypeHint hint = parameter.getAnnotation(DataTypeHint.class); final ArgumentHint argumentHint = parameter.getAnnotation(ArgumentHint.class); final StateHint stateHint = parameter.getAnnotation(StateHint.class); final DataTypeTemplate template; if (stateHint != null) { template = DataTypeTemplate.fromAnnotation(typeFactory, stateHint.type()); } else if (argumentHint != null) { template = DataTypeTemplate.fromAnnotation(typeFactory, argumentHint.type()); } else if (hint != null) { template = DataTypeTemplate.fromAnnotation(typeFactory, hint); } else { template = DataTypeTemplate.fromDefaults(); } return extractDataTypeWithClassContext( typeFactory, template, baseClass, parameter.getParameterizedType(), String.format( " in parameter %d of method '%s' in class '%s'", paramPos, method.getName(), baseClass.getName())); }
Extracts a data type from a method parameter by considering surrounding classes and parameter annotation.
extractFromMethodParameter
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
public static DataType extractFromGenericMethodParameter( DataTypeFactory typeFactory, Class<?> baseClass, Method method, int paramPos, int genericPos) { Type parameterType = method.getGenericParameterTypes()[paramPos]; parameterType = resolveVariableWithClassContext(baseClass, parameterType); if (!(parameterType instanceof ParameterizedType)) { throw extractionError( "The method '%s' needs generic parameters for the %d arg.", method.getName(), paramPos); } final Type genericParameterType = ((ParameterizedType) parameterType).getActualTypeArguments()[genericPos]; final Parameter parameter = method.getParameters()[paramPos]; final DataTypeHint hint = parameter.getAnnotation(DataTypeHint.class); final DataTypeTemplate template; if (hint != null) { template = DataTypeTemplate.fromAnnotation(typeFactory, hint); } else { template = DataTypeTemplate.fromDefaults(); } return extractDataTypeWithClassContext( typeFactory, template, baseClass, genericParameterType, String.format( " in generic parameter %d of method '%s' in class '%s'", paramPos, method.getName(), baseClass.getName())); }
Extracts a data type from a method parameter by considering surrounding classes and parameter annotation. This version assumes that the parameter is a generic type, and uses the generic position type as the extracted data type. For example, if the parameter is a CompletableFuture&lt;Long&gt; and genericPos is 0, it will extract Long.
extractFromGenericMethodParameter
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
public static DataType extractFromMethodReturnType( DataTypeFactory typeFactory, Class<?> baseClass, Method method) { return extractFromMethodReturnType( typeFactory, baseClass, method, method.getGenericReturnType()); }
Extracts a data type from a method return type by considering surrounding classes and method annotation.
extractFromMethodReturnType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
private DataTypeTemplate mergeFieldTemplate( DataTypeFactory typeFactory, Field field, DataTypeTemplate structuredTemplate) { final DataTypeHint hint = field.getAnnotation(DataTypeHint.class); if (hint == null) { return structuredTemplate.copyWithoutDataType(); } return structuredTemplate.mergeWithInnerAnnotation(typeFactory, hint); }
Merges the template of a structured type with a possibly more specific field annotation.
mergeFieldTemplate
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
private DataType closestBridging(DataType dataType, @Nullable Class<?> clazz) { // no context class or conversion class is already more specific than context class if (clazz == null || clazz.isAssignableFrom(dataType.getConversionClass())) { return dataType; } final LogicalType logicalType = dataType.getLogicalType(); final boolean supportsConversion = logicalType.supportsInputConversion(clazz) || logicalType.supportsOutputConversion(clazz); if (supportsConversion) { return dataType.bridgedTo(clazz); } return dataType; }
Use closest class for data type if possible. Even though a hint might have provided some data type, in many cases, the conversion class can be enriched with the extraction type itself.
closestBridging
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
private DataType handleDataViewHints(DataType dataType, @Nullable Class<?> clazz) { if (clazz == null || !DataView.class.isAssignableFrom(clazz)) { return dataType; } // data type went through regular extraction logic if (isCompositeType(dataType.getLogicalType())) { return dataType; } // view was annotated if (ListView.class.isAssignableFrom(clazz)) { if (!dataType.getLogicalType().is(LogicalTypeRoot.ARRAY)) { throw extractionError("Annotated list views should have a logical type of ARRAY."); } final CollectionDataType collectionDataType = (CollectionDataType) dataType; return ListView.newListViewDataType(collectionDataType.getElementDataType()); } else if (MapView.class.isAssignableFrom(clazz)) { if (!dataType.getLogicalType().is(LogicalTypeRoot.MAP)) { throw extractionError("Annotated map views should have a logical type of MAP."); } final KeyValueDataType keyValueDataType = (KeyValueDataType) dataType; return MapView.newMapViewDataType( keyValueDataType.getKeyDataType(), keyValueDataType.getValueDataType()); } else { throw extractionError("Invalid data view: %s", clazz.getName()); } }
Data type hints are allowed on top of {@link DataView}s. They are validated and mapped to the underlying collection by this method.
handleDataViewHints
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeExtractor.java
Apache-2.0
static DataTypeTemplate fromAnnotation(DataTypeFactory typeFactory, DataTypeHint hint) { final String typeName = defaultAsNull(hint, DataTypeHint::value); final Class<?> conversionClass = defaultAsNull(hint, DataTypeHint::bridgedTo); if (typeName != null || conversionClass != null) { // chicken and egg problem // a template can contain a data type but in order to extract a data type we might need // a template final DataTypeTemplate extractionTemplate = fromAnnotation(hint, null); return fromAnnotation( hint, extractDataType(typeFactory, typeName, conversionClass, extractionTemplate)); } return fromAnnotation(hint, null); }
Creates an instance from the given {@link DataTypeHint}. Resolves an explicitly defined data type if {@link DataTypeHint#value()} and/or {@link DataTypeHint#bridgedTo()} are defined.
fromAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
static DataTypeTemplate fromAnnotation(ArgumentHint argumentHint, @Nullable DataType dataType) { return fromAnnotation(argumentHint.type(), dataType); }
Creates an instance from the given {@link ArgumentHint} with a resolved data type if available.
fromAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
static DataTypeTemplate fromAnnotation(DataTypeHint hint, @Nullable DataType dataType) { return new DataTypeTemplate( dataType, defaultAsNull(hint, DataTypeHint::rawSerializer), defaultAsNull(hint, DataTypeHint::inputGroup), defaultAsNull(hint, DataTypeHint::version), hintFlagToBoolean(defaultAsNull(hint, DataTypeHint::allowRawGlobally)), defaultAsNull(hint, DataTypeHint::allowRawPattern), defaultAsNull(hint, DataTypeHint::forceRawPattern), defaultAsNull(hint, DataTypeHint::defaultDecimalPrecision), defaultAsNull(hint, DataTypeHint::defaultDecimalScale), defaultAsNull(hint, DataTypeHint::defaultYearPrecision), defaultAsNull(hint, DataTypeHint::defaultSecondPrecision)); }
Creates an instance from the given {@link DataTypeHint} with a resolved data type if available.
fromAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
static DataTypeTemplate fromDefaults() { return new DataTypeTemplate( null, null, null, null, null, null, null, null, null, null, null); }
Creates an instance with no parameter content.
fromDefaults
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
DataTypeTemplate copyWithoutDataType() { return new DataTypeTemplate( null, rawSerializer, inputGroup, version, allowRawGlobally, allowRawPattern, forceRawPattern, defaultDecimalPrecision, defaultDecimalScale, defaultYearPrecision, defaultSecondPrecision); }
Copies this template but removes the explicit data type (if available).
copyWithoutDataType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
DataTypeTemplate mergeWithInnerAnnotation(DataTypeFactory typeFactory, DataTypeHint hint) { final DataTypeTemplate otherTemplate = fromAnnotation(typeFactory, hint); return new DataTypeTemplate( otherTemplate.dataType, rightValueIfNotNull(rawSerializer, otherTemplate.rawSerializer), rightValueIfNotNull(inputGroup, otherTemplate.inputGroup), rightValueIfNotNull(version, otherTemplate.version), rightValueIfNotNull(allowRawGlobally, otherTemplate.allowRawGlobally), rightValueIfNotNull(allowRawPattern, otherTemplate.allowRawPattern), rightValueIfNotNull(forceRawPattern, otherTemplate.forceRawPattern), rightValueIfNotNull(defaultDecimalPrecision, otherTemplate.defaultDecimalPrecision), rightValueIfNotNull(defaultDecimalScale, otherTemplate.defaultDecimalScale), rightValueIfNotNull(defaultYearPrecision, otherTemplate.defaultYearPrecision), rightValueIfNotNull(defaultSecondPrecision, otherTemplate.defaultSecondPrecision)); }
Merges this template with an inner annotation. The inner annotation has highest precedence and definitely determines the explicit data type (if available).
mergeWithInnerAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
boolean isAllowRawGlobally() { return allowRawGlobally != null && allowRawGlobally; }
Returns whether RAW types are allowed everywhere.
isAllowRawGlobally
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
boolean isAllowAnyPattern(@Nullable Class<?> clazz) { if (allowRawPattern == null || clazz == null) { return false; } final String className = clazz.getName(); for (String pattern : allowRawPattern) { if (className.startsWith(pattern)) { return true; } } return false; }
Returns whether the given class is eligible for being treated as RAW type.
isAllowAnyPattern
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/DataTypeTemplate.java
Apache-2.0
public static List<Method> collectMethods(Class<?> function, String methodName) { return Arrays.stream(function.getMethods()) .filter(method -> method.getName().equals(methodName)) .sorted(Comparator.comparing(Method::toString)) // for deterministic order .collect(Collectors.toList()); }
Collects methods of the given name.
collectMethods
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static String createMethodSignatureString( String methodName, Class<?>[] parameters, @Nullable Class<?> returnType) { final StringBuilder builder = new StringBuilder(); if (returnType != null) { builder.append(returnType.getCanonicalName()).append(" "); } builder.append(methodName) .append( Stream.of(parameters) .map( parameter -> { // in case we don't know the parameter at this location // (i.e. for accumulators) if (parameter == null) { return "_"; } else { return parameter.getCanonicalName(); } }) .collect(Collectors.joining(", ", "(", ")"))); return builder.toString(); }
Creates a method signature string like {@code int eval(Integer, String)}.
createMethodSignatureString
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static void validateStructuredClass(Class<?> clazz) { final int m = clazz.getModifiers(); if (Modifier.isAbstract(m)) { throw extractionError("Class '%s' must not be abstract.", clazz.getName()); } if (!Modifier.isPublic(m)) { throw extractionError("Class '%s' is not public.", clazz.getName()); } if (clazz.getEnclosingClass() != null && (clazz.getDeclaringClass() == null || !Modifier.isStatic(m))) { throw extractionError( "Class '%s' is a not a static, globally accessible class.", clazz.getName()); } }
Validates the characteristics of a class for a {@link StructuredType} such as accessibility.
validateStructuredClass
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static Field getStructuredField(Class<?> clazz, String fieldName) { final String normalizedFieldName = fieldName.toUpperCase(); final List<Field> fields = collectStructuredFields(clazz); for (Field field : fields) { if (field.getName().toUpperCase().equals(normalizedFieldName)) { return field; } } throw extractionError( "Could not find a field named '%s' in class '%s' for structured type.", fieldName, clazz.getName()); }
Returns the field of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors.
getStructuredField
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static Optional<Method> getStructuredFieldGetter(Class<?> clazz, Field field) { final String normalizedFieldName = normalizeAccessorName(field.getName()); final List<Method> methods = collectStructuredMethods(clazz); for (Method method : methods) { // check name: // get<Name>() // is<Name>() // <Name>() for Scala final String normalizedMethodName = normalizeAccessorName(method.getName()); final boolean hasName = normalizedMethodName.equals("GET" + normalizedFieldName) || normalizedMethodName.equals("IS" + normalizedFieldName) || normalizedMethodName.equals(normalizedFieldName); if (!hasName) { continue; } // check return type: // equal to field type final Type returnType = method.getGenericReturnType(); final boolean hasReturnType = returnType.equals(field.getGenericType()); if (!hasReturnType) { continue; } // check parameters: // no parameters final boolean hasNoParameters = method.getParameterCount() == 0; if (!hasNoParameters) { continue; } // matching getter found return Optional.of(method); } // no getter found return Optional.empty(); }
Checks for a field getter of a structured type. The logic is as broad as possible to support both Java and Scala in different flavors.
getStructuredFieldGetter
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static boolean hasInvokableConstructor(Class<?> clazz, Class<?>... classes) { for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { if (isInvokable(Autoboxing.JVM, constructor, classes)) { return true; } } return false; }
Checks for an invokable constructor matching the given arguments. @see #isInvokable(Autoboxing, Executable, Class[])
hasInvokableConstructor
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static boolean isStructuredFieldDirectlyReadable(Field field) { final int m = field.getModifiers(); // field is directly readable return Modifier.isPublic(m); }
Checks whether a field is directly readable without a getter.
isStructuredFieldDirectlyReadable
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static boolean isStructuredFieldDirectlyWritable(Field field) { final int m = field.getModifiers(); // field is immutable if (Modifier.isFinal(m)) { return false; } // field is directly writable return Modifier.isPublic(m); }
Checks whether a field is directly writable without a setter or constructor.
isStructuredFieldDirectlyWritable
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static Optional<Class<?>> extractSimpleGeneric( Class<?> baseClass, Class<?> clazz, int pos) { try { if (!baseClass.isAssignableFrom(clazz)) { return Optional.empty(); } final Type t = ((ParameterizedType) clazz.getGenericSuperclass()) .getActualTypeArguments()[pos]; return Optional.ofNullable(toClass(t)); } catch (Exception unused) { return Optional.empty(); } }
A minimal version to extract a generic parameter from a given class. <p>This method should only be used for very specific use cases, in most cases {@link DataTypeExtractor#extractFromGeneric(DataTypeFactory, Class, int, Type)} should be more appropriate.
extractSimpleGeneric
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static Type resolveVariableWithClassContext(@Nullable Type contextType, Type type) { final List<Type> typeHierarchy; if (contextType != null) { typeHierarchy = collectTypeHierarchy(contextType); } else { typeHierarchy = Collections.emptyList(); } if (!containsTypeVariable(type)) { return type; } if (type instanceof TypeVariable) { return resolveVariable(typeHierarchy, (TypeVariable<?>) type); } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; List<Type> paramTypes = new ArrayList<>(); for (Type paramType : parameterizedType.getActualTypeArguments()) { paramType = resolveVariableWithClassContext(contextType, paramType); paramTypes.add(paramType); } return new ParameterizedTypeImpl( paramTypes.toArray(paramTypes.toArray(new Type[0])), parameterizedType.getRawType(), parameterizedType.getOwnerType()); } else if (type instanceof GenericArrayType) { Type componentType = resolveVariableWithClassContext( contextType, ((GenericArrayType) type).getGenericComponentType()); return new GenericArrayTypeImpl(componentType); } else { return type; } }
Resolves a variable type while accepting a context for resolution.
resolveVariableWithClassContext
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static Class<?> getClassFromType(Type type) { if (type instanceof ParameterizedType) { return (Class<?>) ((ParameterizedType) type).getRawType(); } else if (type instanceof GenericArrayType) { return Array.newInstance( (Class<?>) ((GenericArrayType) type).getGenericComponentType(), 0) .getClass(); } // Otherwise assume it's a basic type that can be cast. return (Class<?>) type; }
Gets the associated class type from a Type parameter.
getClassFromType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
public static void checkStateDataType(DataType dataType) { final LogicalType type = dataType.getLogicalType(); if (!LogicalTypeChecks.isCompositeType(type)) { throw extractionError( "State entries must use a mutable, composite data type. But was: %s", dataType); } if (type.is(LogicalTypeRoot.ROW)) { return; } if (!hasInvokableConstructor(dataType.getConversionClass())) { throw extractionError( "Class '%s' cannot be used as state because a default constructor is missing. " + "State entries must provide an argument-less constructor so that all " + "fields are mutable.", dataType.getConversionClass().getName()); } }
Checks whether the given data type can be used as a state entry for {@link ProcessTableFunction}.
checkStateDataType
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static List<Type> collectTypeHierarchy(Type type) { Type currentType = type; Class<?> currentClass = toClass(type); final List<Type> typeHierarchy = new ArrayList<>(); while (currentClass != null) { // collect type typeHierarchy.add(currentType); // collect super interfaces for (Type genericInterface : currentClass.getGenericInterfaces()) { final Class<?> interfaceClass = toClass(genericInterface); if (interfaceClass != null) { typeHierarchy.addAll(collectTypeHierarchy(genericInterface)); } } currentType = currentClass.getGenericSuperclass(); currentClass = toClass(currentType); } return typeHierarchy; }
Collects the partially ordered type hierarchy (i.e. all involved super classes and super interfaces) of the given type.
collectTypeHierarchy
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static @Nullable Class<?> toClass(Type type) { if (type instanceof Class) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { // this is always a class return (Class<?>) ((ParameterizedType) type).getRawType(); } // unsupported: generic arrays, type variables, wildcard types return null; }
Converts a {@link Type} to {@link Class} if possible, {@code null} otherwise.
toClass
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static void validateStructuredSelfReference(Type t, List<Type> typeHierarchy) { final Class<?> clazz = toClass(t); if (clazz != null && !clazz.isInterface() && clazz != Object.class && typeHierarchy.contains(t)) { throw extractionError( "Cyclic reference detected for class '%s'. Attributes of structured types must not " + "(transitively) reference the structured type itself.", clazz.getName()); } }
Validates if a given type is not already contained in the type hierarchy of a structured type. <p>Otherwise this would lead to infinite data type extraction cycles.
validateStructuredSelfReference
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static List<Field> collectStructuredFields(Class<?> clazz) { final List<Field> fields = new ArrayList<>(); while (clazz != Object.class) { final Field[] declaredFields = clazz.getDeclaredFields(); Stream.of(declaredFields) .filter( field -> { final int m = field.getModifiers(); return !Modifier.isStatic(m) && !Modifier.isTransient(m); }) .forEach(fields::add); clazz = clazz.getSuperclass(); } return fields; }
Returns the fields of a class for a {@link StructuredType}.
collectStructuredFields
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static void validateStructuredFieldReadability(Class<?> clazz, Field field) { // field is accessible if (isStructuredFieldDirectlyReadable(field)) { return; } // field needs a getter if (!getStructuredFieldGetter(clazz, field).isPresent()) { throw extractionError( "Field '%s' of class '%s' is neither publicly accessible nor does it have " + "a corresponding getter method.", field.getName(), clazz.getName()); } }
Validates if a field is properly readable either directly or through a getter.
validateStructuredFieldReadability
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static boolean isStructuredFieldMutable(Class<?> clazz, Field field) { final int m = field.getModifiers(); // field is immutable if (Modifier.isFinal(m)) { return false; } // field is directly mutable if (Modifier.isPublic(m)) { return true; } // field has setters by which it is mutable if (getStructuredFieldSetter(clazz, field).isPresent()) { return true; } throw extractionError( "Field '%s' of class '%s' is mutable but is neither publicly accessible nor does it have " + "a corresponding setter method.", field.getName(), clazz.getName()); }
Checks if a field is mutable or immutable. Returns {@code true} if the field is properly mutable. Returns {@code false} if it is properly immutable.
isStructuredFieldMutable
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static List<Method> collectStructuredMethods(Class<?> clazz) { final List<Method> methods = new ArrayList<>(); while (clazz != Object.class) { final Method[] declaredMethods = clazz.getDeclaredMethods(); Stream.of(declaredMethods) .filter( field -> { final int m = field.getModifiers(); return Modifier.isPublic(m) && !Modifier.isNative(m) && !Modifier.isAbstract(m); }) .forEach(methods::add); clazz = clazz.getSuperclass(); } return methods; }
Collects all methods that qualify as methods of a {@link StructuredType}.
collectStructuredMethods
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static <T extends Annotation> Set<T> collectAnnotationsOfClass( Class<T> annotation, Class<?> annotatedClass) { final List<Class<?>> classHierarchy = new ArrayList<>(); Class<?> currentClass = annotatedClass; while (currentClass != null) { classHierarchy.add(currentClass); currentClass = currentClass.getSuperclass(); } // convert to top down Collections.reverse(classHierarchy); return classHierarchy.stream() .flatMap(c -> Stream.of(c.getAnnotationsByType(annotation))) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Collects all annotations of the given type defined in the current class or superclasses. Duplicates are ignored.
collectAnnotationsOfClass
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static <T extends Annotation> Set<T> collectAnnotationsOfMethod( Class<T> annotation, Method annotatedMethod) { return new LinkedHashSet<>(Arrays.asList(annotatedMethod.getAnnotationsByType(annotation))); }
Collects all annotations of the given type defined in the given method. Duplicates are ignored.
collectAnnotationsOfMethod
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
static @Nullable List<String> extractMethodParameterNames(Method method) { return extractExecutableNames(method); }
Extracts the parameter names of a method if possible.
extractMethodParameterNames
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
private static boolean containsTypeVariable(Type type) { if (type instanceof TypeVariable) { return true; } else if (type instanceof ParameterizedType) { return Arrays.stream(((ParameterizedType) type).getActualTypeArguments()) .anyMatch(ExtractionUtils::containsTypeVariable); } else if (type instanceof GenericArrayType) { return containsTypeVariable(((GenericArrayType) type).getGenericComponentType()); } // WildcardType does not contain a type variable, and we don't consider it resolvable. return false; }
Utility to know if the type contains a type variable that needs to be resolved.
containsTypeVariable
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java
Apache-2.0
Map<FunctionSignatureTemplate, FunctionStateTemplate> extractStateMapping() { Preconditions.checkState(supportsState()); try { return extractResultMappings( stateExtraction, FunctionTemplate::getStateTemplate, stateVerification); } catch (Throwable t) { throw extractionError(t, "Error in extracting a signature to state mapping."); } }
Utility for extracting function mappings from signature to result, e.g. from (INT, STRING) to BOOLEAN for {@link UserDefinedFunction}. <p>Both the signature and result can either come from local or global {@link FunctionHint}s, or are extracted reflectively using the implementation methods and/or function generics.
extractStateMapping
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static ResultExtraction createOutputFromGenericInClass( Class<? extends UserDefinedFunction> baseClass, int genericPos, boolean allowDataTypeHint) { return (extractor, method) -> { if (allowDataTypeHint) { Optional<FunctionResultTemplate> hints = extractHints(extractor, method); if (hints.isPresent()) { return hints.get(); } } final DataType dataType = DataTypeExtractor.extractFromGeneric( extractor.typeFactory, baseClass, genericPos, extractor.getFunctionClass()); return FunctionResultTemplate.ofOutput(dataType); }; }
Extraction that uses a generic type variable for producing a {@link FunctionResultTemplate}. <p>If enabled, a {@link DataTypeHint} from method or class has higher priority.
createOutputFromGenericInClass
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static ResultExtraction createOutputFromGenericInMethod( int paramPos, int genericPos, boolean allowDataTypeHint) { return (extractor, method) -> { if (allowDataTypeHint) { Optional<FunctionResultTemplate> hints = extractHints(extractor, method); if (hints.isPresent()) { return hints.get(); } } final DataType dataType = DataTypeExtractor.extractFromGenericMethodParameter( extractor.typeFactory, extractor.getFunctionClass(), method, paramPos, genericPos); return FunctionResultTemplate.ofOutput(dataType); }; }
Extraction that uses a generic type variable of a method parameter for producing a {@link FunctionResultTemplate}. <p>If enabled, a {@link DataTypeHint} from method or class has higher priority.
createOutputFromGenericInMethod
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static MethodVerification createParameterAndReturnTypeVerification() { return (method, state, arguments, result) -> { checkNoState(state); checkScalarArgumentsOnly(arguments); final Class<?>[] parameters = assembleParameters(null, arguments); assert result != null; final Class<?> resultClass = result.toClass(); final Class<?> returnType = method.getReturnType(); // Parameters should be validated using strict autoboxing. // For return types, we can be more flexible as the UDF should know what it declared. final boolean isValid = isInvokable(Autoboxing.STRICT, method, parameters) && isAssignable(resultClass, returnType, Autoboxing.JVM); if (!isValid) { throw createMethodNotFoundError(method.getName(), parameters, resultClass, ""); } }; }
Verification that checks a method by parameters (arguments only) and return type.
createParameterAndReturnTypeVerification
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static MethodVerification createParameterVerification(boolean requireAccumulator) { return (method, state, arguments, result) -> { if (requireAccumulator) { checkSingleState(state); } else { checkNoState(state); } checkScalarArgumentsOnly(arguments); final Class<?>[] parameters = assembleParameters(state, arguments); // Parameters should be validated using strict autoboxing. if (!isInvokable(Autoboxing.STRICT, method, parameters)) { throw createMethodNotFoundError( method.getName(), parameters, null, requireAccumulator ? "(<accumulator> [, <argument>]*)" : ""); } }; }
Verification that checks a method by parameters (arguments only or with accumulator).
createParameterVerification
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static MethodVerification createParameterAndCompletableFutureVerification(Class<?> baseClass) { return (method, state, arguments, result) -> { checkNoState(state); checkScalarArgumentsOnly(arguments); final Class<?>[] parameters = assembleParameters(null, arguments); final Class<?>[] parametersWithFuture = Stream.concat(Stream.of(CompletableFuture.class), Arrays.stream(parameters)) .toArray(Class<?>[]::new); assert result != null; final Class<?> resultClass = result.toClass(); Type genericType = method.getGenericParameterTypes()[0]; genericType = resolveVariableWithClassContext(baseClass, genericType); if (!(genericType instanceof ParameterizedType)) { throw extractionError( "The method '%s' needs generic parameters for the CompletableFuture at position %d.", method.getName(), 0); } final Type returnType = ((ParameterizedType) genericType).getActualTypeArguments()[0]; Class<?> returnTypeClass = getClassFromType(returnType); // Parameters should be validated using strict autoboxing. // For return types, we can be more flexible as the UDF should know what it declared. if (!(isInvokable(Autoboxing.STRICT, method, parametersWithFuture) && isAssignable(resultClass, returnTypeClass, Autoboxing.JVM))) { throw createMethodNotFoundError( method.getName(), parametersWithFuture, null, "(<completable future> [, <argument>]*)"); } }; }
Verification that checks a method by parameters (arguments only) with mandatory {@link CompletableFuture}.
createParameterAndCompletableFutureVerification
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
private static Optional<FunctionResultTemplate> extractHints( BaseMappingExtractor extractor, Method method) { final Set<DataTypeHint> dataTypeHints = new HashSet<>(); dataTypeHints.addAll(collectAnnotationsOfMethod(DataTypeHint.class, method)); dataTypeHints.addAll( collectAnnotationsOfClass(DataTypeHint.class, extractor.getFunctionClass())); if (dataTypeHints.size() > 1) { throw extractionError( "More than one data type hint found for output of function. " + "Please use a function hint instead."); } if (dataTypeHints.size() == 1) { return Optional.ofNullable( FunctionTemplate.createOutputTemplate( extractor.typeFactory, dataTypeHints.iterator().next())); } // otherwise continue with regular extraction return Optional.empty(); }
Uses hints to extract functional template.
extractHints
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionMappingExtractor.java
Apache-2.0
static FunctionSignatureTemplate of( List<FunctionArgumentTemplate> argumentTemplates, boolean isVarArgs, EnumSet<StaticArgumentTrait>[] argumentTraits, @Nullable String[] argumentNames, boolean[] argumentOptionals) { if (argumentNames != null && argumentNames.length != argumentTemplates.size()) { throw extractionError( "Mismatch between number of argument names '%s' and argument types '%s'.", argumentNames.length, argumentTemplates.size()); } if (argumentNames != null && argumentNames.length != Arrays.stream(argumentNames).distinct().count()) { throw extractionError( "Argument name conflict, there are at least two argument names that are the same."); } if (argumentOptionals != null && argumentOptionals.length != argumentTemplates.size()) { throw extractionError( "Mismatch between number of argument optionals '%s' and argument types '%s'.", argumentOptionals.length, argumentTemplates.size()); } if (argumentOptionals != null) { for (int i = 0; i < argumentTemplates.size(); i++) { DataType dataType = argumentTemplates.get(i).toDataType(); if (dataType != null && !dataType.getLogicalType().isNullable() && argumentOptionals[i]) { throw extractionError( "Argument at position %s is optional but its type doesn't accept null value.", i); } } } return new FunctionSignatureTemplate( argumentTemplates, isVarArgs, argumentTraits, argumentNames, argumentOptionals); }
Template of a function signature with argument types and argument names.
of
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionSignatureTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionSignatureTemplate.java
Apache-2.0
@SuppressWarnings("deprecation") static FunctionTemplate fromAnnotation(DataTypeFactory typeFactory, FunctionHint hint) { return new FunctionTemplate( createSignatureTemplate( typeFactory, defaultAsNull(hint, FunctionHint::input), defaultAsNull(hint, FunctionHint::argumentNames), defaultAsNull(hint, FunctionHint::argument), defaultAsNull(hint, FunctionHint::arguments), hint.isVarArgs()), createStateTemplate( typeFactory, defaultAsNull(hint, FunctionHint::accumulator), defaultAsNull(hint, FunctionHint::state)), createOutputTemplate(typeFactory, defaultAsNull(hint, FunctionHint::output))); }
Creates an instance using the given {@link FunctionHint}. It resolves explicitly defined data types.
fromAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
Apache-2.0
@SuppressWarnings("deprecation") static FunctionTemplate fromAnnotation(DataTypeFactory typeFactory, ProcedureHint hint) { return new FunctionTemplate( createSignatureTemplate( typeFactory, defaultAsNull(hint, ProcedureHint::input), defaultAsNull(hint, ProcedureHint::argumentNames), defaultAsNull(hint, ProcedureHint::argument), defaultAsNull(hint, ProcedureHint::arguments), hint.isVarArgs()), createStateTemplate(typeFactory, null, null), createOutputTemplate(typeFactory, defaultAsNull(hint, ProcedureHint::output))); }
Creates an instance using the given {@link ProcedureHint}. It resolves explicitly defined data types.
fromAnnotation
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
Apache-2.0
static @Nullable FunctionOutputTemplate createOutputTemplate( DataTypeFactory typeFactory, @Nullable DataTypeHint hint) { if (hint == null) { return null; } final DataTypeTemplate template; try { template = DataTypeTemplate.fromAnnotation(typeFactory, hint); } catch (Throwable t) { throw extractionError(t, "Error in data type hint annotation."); } if (template.dataType != null) { return FunctionResultTemplate.ofOutput(template.dataType); } throw extractionError( "Data type hint does not specify a data type for use as function result."); }
Creates an instance of {@link FunctionResultTemplate} from a {@link DataTypeHint}.
createOutputTemplate
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/FunctionTemplate.java
Apache-2.0
static Set<FunctionTemplate> extractGlobalFunctionTemplates( DataTypeFactory typeFactory, Class<? extends UserDefinedFunction> function) { return asFunctionTemplates( typeFactory, collectAnnotationsOfClass(FunctionHint.class, function)); }
Retrieve global templates from function class.
extractGlobalFunctionTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> extractProcedureGlobalFunctionTemplates( DataTypeFactory typeFactory, Class<? extends Procedure> procedure) { return asFunctionTemplatesForProcedure( typeFactory, collectAnnotationsOfClass(ProcedureHint.class, procedure)); }
Retrieve global templates from procedure class.
extractProcedureGlobalFunctionTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> extractLocalFunctionTemplates( DataTypeFactory typeFactory, Method method) { return asFunctionTemplates( typeFactory, collectAnnotationsOfMethod(FunctionHint.class, method)); }
Retrieve local templates from function method.
extractLocalFunctionTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> extractProcedureLocalFunctionTemplates( DataTypeFactory typeFactory, Method method) { return asFunctionTemplatesForProcedure( typeFactory, collectAnnotationsOfMethod(ProcedureHint.class, method)); }
Retrieve local templates from procedure method.
extractProcedureLocalFunctionTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> asFunctionTemplates( DataTypeFactory typeFactory, Set<FunctionHint> hints) { return hints.stream() .map( hint -> { try { return FunctionTemplate.fromAnnotation(typeFactory, hint); } catch (Throwable t) { throw extractionError(t, "Error in function hint annotation."); } }) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Converts {@link FunctionHint}s to {@link FunctionTemplate}.
asFunctionTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> asFunctionTemplatesForProcedure( DataTypeFactory typeFactory, Set<ProcedureHint> hints) { return hints.stream() .map( hint -> { try { return FunctionTemplate.fromAnnotation(typeFactory, hint); } catch (Throwable t) { throw extractionError(t, "Error in procedure hint annotation."); } }) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Converts {@link ProcedureHint}s to {@link FunctionTemplate}.
asFunctionTemplatesForProcedure
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionResultTemplate> findResultOnlyTemplates( Set<FunctionTemplate> functionTemplates, Function<FunctionTemplate, FunctionResultTemplate> accessor) { return functionTemplates.stream() .filter(t -> t.getSignatureTemplate() == null && accessor.apply(t) != null) .map(accessor) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Find a template that only specifies a result.
findResultOnlyTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static @Nullable FunctionResultTemplate findResultOnlyTemplate( Set<FunctionResultTemplate> globalResultOnly, Set<FunctionResultTemplate> localResultOnly, Set<FunctionTemplate> explicitMappings, Function<FunctionTemplate, FunctionResultTemplate> accessor, String hintType) { final Set<FunctionResultTemplate> resultOnly = Stream.concat(globalResultOnly.stream(), localResultOnly.stream()) .collect(Collectors.toCollection(LinkedHashSet::new)); final Set<FunctionResultTemplate> allResults = Stream.concat(resultOnly.stream(), explicitMappings.stream().map(accessor)) .collect(Collectors.toCollection(LinkedHashSet::new)); if (resultOnly.size() == 1 && allResults.size() == 1) { return resultOnly.stream().findFirst().orElse(null); } // different results is only fine as long as those come from a mapping if (resultOnly.size() > 1 || (!resultOnly.isEmpty() && !explicitMappings.isEmpty())) { throw extractionError( String.format( "%s hints that lead to ambiguous results are not allowed.", hintType)); } return null; }
Hints that only declare a result (either accumulator or output).
findResultOnlyTemplate
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionTemplate> findResultMappingTemplates( Set<FunctionTemplate> globalTemplates, Set<FunctionTemplate> localTemplates, Function<FunctionTemplate, FunctionResultTemplate> accessor) { return Stream.concat(globalTemplates.stream(), localTemplates.stream()) .filter(t -> t.getSignatureTemplate() != null && accessor.apply(t) != null) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Hints that map a signature to a result.
findResultMappingTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
static Set<FunctionSignatureTemplate> findInputOnlyTemplates( Set<FunctionTemplate> global, Set<FunctionTemplate> local, Function<FunctionTemplate, FunctionResultTemplate> accessor) { return Stream.concat(global.stream(), local.stream()) .filter(t -> t.getSignatureTemplate() != null && accessor.apply(t) == null) .map(FunctionTemplate::getSignatureTemplate) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Hints that only declare an input.
findInputOnlyTemplates
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TemplateUtils.java
Apache-2.0
public static TypeInference forScalarFunction( DataTypeFactory typeFactory, Class<? extends ScalarFunction> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.SCALAR_EVAL, createArgumentsFromParametersExtraction(0), null, null, createOutputFromReturnTypeInMethod(), createParameterAndReturnTypeVerification()); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link ScalarFunction}.
forScalarFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forAsyncScalarFunction( DataTypeFactory typeFactory, Class<? extends AsyncScalarFunction> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.ASYNC_SCALAR_EVAL, createArgumentsFromParametersExtraction(1), null, null, createOutputFromGenericInMethod(0, 0, true), createParameterAndCompletableFutureVerification(function)); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link AsyncScalarFunction}.
forAsyncScalarFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forAggregateFunction( DataTypeFactory typeFactory, Class<? extends AggregateFunction<?, ?>> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.AGGREGATE_ACCUMULATE, createArgumentsFromParametersExtraction(1), createStateFromGenericInClassOrParametersExtraction( AggregateFunction.class, 1), createParameterVerification(true), createOutputFromGenericInClass(AggregateFunction.class, 0, true), null); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link AggregateFunction}.
forAggregateFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forTableFunction( DataTypeFactory typeFactory, Class<? extends TableFunction<?>> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.TABLE_EVAL, createArgumentsFromParametersExtraction(0), null, null, createOutputFromGenericInClass(TableFunction.class, 0, true), createParameterVerification(false)); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link TableFunction}.
forTableFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forTableAggregateFunction( DataTypeFactory typeFactory, Class<? extends TableAggregateFunction<?, ?>> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.TABLE_AGGREGATE_ACCUMULATE, createArgumentsFromParametersExtraction(1), createStateFromGenericInClassOrParametersExtraction( TableAggregateFunction.class, 1), createParameterVerification(true), createOutputFromGenericInClass(TableAggregateFunction.class, 0, true), null); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link TableAggregateFunction}.
forTableAggregateFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forAsyncTableFunction( DataTypeFactory typeFactory, Class<? extends AsyncTableFunction<?>> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.ASYNC_TABLE_EVAL, createArgumentsFromParametersExtraction(1), null, null, createOutputFromGenericInClass(AsyncTableFunction.class, 0, true), createParameterAndCompletableFutureVerification(function)); return extractTypeInference(mappingExtractor, false); }
Extracts a type inference from a {@link AsyncTableFunction}.
forAsyncTableFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
public static TypeInference forProcessTableFunction( DataTypeFactory typeFactory, Class<? extends ProcessTableFunction<?>> function) { final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor( typeFactory, function, UserDefinedFunctionHelper.PROCESS_TABLE_EVAL, createArgumentsFromParametersExtraction( 0, ProcessTableFunction.Context.class), createStateFromParametersExtraction(), createParameterAndOptionalContextVerification( ProcessTableFunction.Context.class, true), createOutputFromGenericInClass(ProcessTableFunction.class, 0, true), null); return extractTypeInference(mappingExtractor, true); }
Extracts a type inference from a {@link ProcessTableFunction}.
forProcessTableFunction
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/TypeInferenceExtractor.java
Apache-2.0
default Optional<TableSemantics> getTableSemantics(int pos) { return Optional.empty(); }
Returns information about the table that has been passed to a table argument. <p>This method applies only to {@link ProcessTableFunction}s. <p>Semantics are only available for table arguments that are annotated with {@code @ArgumentHint(TABLE_AS_SET)} or {@code @ArgumentHint(TABLE_AS_ROW)}).
getTableSemantics
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
Apache-2.0
default Optional<ChangelogMode> getOutputChangelogMode() { return Optional.empty(); }
Returns the {@link ChangelogMode} that the framework requires from the function. <p>This method applies only to {@link ProcessTableFunction}. <p>Returns empty during type inference phase as the changelog mode is still unknown. Returns an actual changelog mode, when the PTF implements the {@link ChangelogFunction} interface.
getOutputChangelogMode
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
Apache-2.0
default ValidationException newValidationError(String message, Object... args) { final String formatted; if (args.length > 0) { formatted = String.format(message, args); } else { formatted = message; } return new ValidationException(formatted); }
Creates a validation exception for exiting the type inference process with a meaningful exception.
newValidationError
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
Apache-2.0
default <T> Optional<T> fail(boolean throwOnFailure, String message, Object... args) { if (throwOnFailure) { throw newValidationError(message, args); } return Optional.empty(); }
Helper method for handling failures during the type inference process while considering the {@code throwOnFailure} flag. <p>Shorthand for {@code if (throwOnFailure) throw ValidationException(...) else return Optional.empty()}.
fail
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/CallContext.java
Apache-2.0
public static InputTypeStrategy sequence(ArgumentTypeStrategy... strategies) { return new SequenceInputTypeStrategy(Arrays.asList(strategies), null); }
Strategy for a function signature like {@code f(STRING, NUMERIC)} using a sequence of {@link ArgumentTypeStrategy}s.
sequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0
public static InputTypeStrategy varyingSequence(ArgumentTypeStrategy... strategies) { return new VaryingSequenceInputTypeStrategy(Arrays.asList(strategies), null); }
Strategy for a varying function signature like {@code f(INT, STRING, NUMERIC...)} using a sequence of {@link ArgumentTypeStrategy}s. The first n - 1 arguments must be constant. The n-th argument can occur 0, 1, or more times.
varyingSequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0
public static InputTypeStrategy repeatingSequence(ArgumentTypeStrategy... strategies) { return new RepeatingSequenceInputTypeStrategy(Arrays.asList(strategies)); }
Arbitrarily often repeating sequence of argument type strategies.
repeatingSequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0
public static InputTypeStrategy explicitSequence(DataType... expectedDataTypes) { final List<ArgumentTypeStrategy> strategies = Arrays.stream(expectedDataTypes) .map(InputTypeStrategies::explicit) .collect(Collectors.toList()); return new SequenceInputTypeStrategy(strategies, null); }
Strategy for a function signature of explicitly defined types like {@code f(STRING, INT)}. Implicit casts will be inserted if possible. <p>This is equivalent to using {@link #sequence(ArgumentTypeStrategy...)} and {@link #explicit(DataType)}.
explicitSequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0
public static InputTypeStrategy explicitSequence( String[] argumentNames, DataType[] expectedDataTypes) { final List<ArgumentTypeStrategy> strategies = Arrays.stream(expectedDataTypes) .map(InputTypeStrategies::explicit) .collect(Collectors.toList()); return new SequenceInputTypeStrategy(strategies, Arrays.asList(argumentNames)); }
Strategy for a named function signature of explicitly defined types like {@code f(s STRING, i INT)}. Implicit casts will be inserted if possible. <p>This is equivalent to using {@link #sequence(String[], ArgumentTypeStrategy[])} and {@link #explicit(DataType)}.
explicitSequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0
public static SubsequenceStrategyBuilder compositeSequence() { return new SubsequenceStrategyBuilder(); }
An strategy that lets you apply other strategies for subsequences of the actual arguments. <p>The {@link #sequence(ArgumentTypeStrategy...)} should be preferred in most of the cases. Use this strategy only if you need to apply a common logic to a subsequence of the arguments.
compositeSequence
java
apache/flink
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeStrategies.java
Apache-2.0