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();
}
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()));
}
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);
}
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()));
}
Aggregations