Search in sources :

Example 1 with DataTypeHint

use of org.apache.flink.table.annotation.DataTypeHint in project flink by apache.

the class FunctionMappingExtractor method tryExtractInputGroupArgument.

private static Optional<FunctionArgumentTemplate> tryExtractInputGroupArgument(Method method, int paramPos) {
    final Parameter parameter = method.getParameters()[paramPos];
    final DataTypeHint hint = parameter.getAnnotation(DataTypeHint.class);
    if (hint != null) {
        final DataTypeTemplate template = DataTypeTemplate.fromAnnotation(hint, null);
        if (template.inputGroup != null) {
            return Optional.of(FunctionArgumentTemplate.of(template.inputGroup));
        }
    }
    return Optional.empty();
}
Also used : Parameter(java.lang.reflect.Parameter) DataTypeHint(org.apache.flink.table.annotation.DataTypeHint)

Example 2 with DataTypeHint

use of org.apache.flink.table.annotation.DataTypeHint in project flink by apache.

the class DataTypeExtractor method extractFromMethodParameter.

/**
 * Extracts a data type from a method parameter by considering surrounding classes and parameter
 * annotation.
 */
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 DataTypeTemplate template;
    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()));
}
Also used : Parameter(java.lang.reflect.Parameter) DataTypeHint(org.apache.flink.table.annotation.DataTypeHint)

Example 3 with DataTypeHint

use of org.apache.flink.table.annotation.DataTypeHint in project flink by apache.

the class DataTypeExtractor method extractDataTypeOrRaw.

// --------------------------------------------------------------------------------------------
private DataType extractDataTypeOrRaw(DataTypeTemplate outerTemplate, List<Type> typeHierarchy, Type type) {
    // best effort resolution of type variables, the resolved type can still be a variable
    final Type resolvedType;
    if (type instanceof TypeVariable) {
        resolvedType = resolveVariable(typeHierarchy, (TypeVariable<?>) type);
    } else {
        resolvedType = type;
    }
    // merge outer template with template of type itself
    DataTypeTemplate template = outerTemplate;
    final Class<?> clazz = toClass(resolvedType);
    if (clazz != null) {
        final DataTypeHint hint = clazz.getAnnotation(DataTypeHint.class);
        if (hint != null) {
            template = outerTemplate.mergeWithInnerAnnotation(typeFactory, hint);
        }
    }
    // main work
    DataType dataType = extractDataTypeOrRawWithTemplate(template, typeHierarchy, resolvedType);
    // handle data views
    dataType = handleDataViewHints(dataType, clazz);
    // final work
    return closestBridging(dataType, clazz);
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) DataType(org.apache.flink.table.types.DataType) CollectionDataType(org.apache.flink.table.types.CollectionDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) Type(java.lang.reflect.Type) KeyValueDataType(org.apache.flink.table.types.KeyValueDataType) ExtractionUtils.createRawType(org.apache.flink.table.types.extraction.ExtractionUtils.createRawType) LogicalTypeChecks.isCompositeType(org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isCompositeType) ParameterizedType(java.lang.reflect.ParameterizedType) TypeVariable(java.lang.reflect.TypeVariable) DataTypeHint(org.apache.flink.table.annotation.DataTypeHint) DataType(org.apache.flink.table.types.DataType) CollectionDataType(org.apache.flink.table.types.CollectionDataType) KeyValueDataType(org.apache.flink.table.types.KeyValueDataType)

Example 4 with DataTypeHint

use of org.apache.flink.table.annotation.DataTypeHint in project flink by apache.

the class DataTypeExtractor method extractFromMethodOutput.

/**
 * Extracts a data type from a method return type by considering surrounding classes and method
 * annotation.
 */
public static DataType extractFromMethodOutput(DataTypeFactory typeFactory, Class<?> baseClass, Method method) {
    final DataTypeHint hint = method.getAnnotation(DataTypeHint.class);
    final DataTypeTemplate template;
    if (hint != null) {
        template = DataTypeTemplate.fromAnnotation(typeFactory, hint);
    } else {
        template = DataTypeTemplate.fromDefaults();
    }
    return extractDataTypeWithClassContext(typeFactory, template, baseClass, method.getGenericReturnType(), String.format(" in return type of method '%s' in class '%s'", method.getName(), baseClass.getName()));
}
Also used : DataTypeHint(org.apache.flink.table.annotation.DataTypeHint)

Aggregations

DataTypeHint (org.apache.flink.table.annotation.DataTypeHint)4 Parameter (java.lang.reflect.Parameter)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 CollectionDataType (org.apache.flink.table.types.CollectionDataType)1 DataType (org.apache.flink.table.types.DataType)1 KeyValueDataType (org.apache.flink.table.types.KeyValueDataType)1 ExtractionUtils.createRawType (org.apache.flink.table.types.extraction.ExtractionUtils.createRawType)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1 LogicalTypeChecks.isCompositeType (org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isCompositeType)1