Hi, When I run the code implementing a generic FlatMapFunction, Flink complained about InvalidTypesException: public class GenericFlatMapper<T> implements FlatMapFunction<SortedMap<T, Long>, Tuple2<T, Long>> {Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface. ... Caused by: org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'T' in 'class GenericFlatMapper' could not be determined. This is most likely a type erasure problem. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s). This puzzles me as Flink should be able to infer the type from arguments. I know returns(...) or other workarounds to give type hint, but they are kind of verbose. Any suggestions? |
Hi Yukun, can you also post the code how you are invoking the GenericFlatMapper on the mailing list? The Java compiler is usually dropping the generic types during compilation ("type erasure"), that's why we can not infer the types. On Fri, Jul 8, 2016 at 12:27 PM, Yukun Guo <[hidden email]> wrote:
|
Hi Robert,
On 9 July 2016 at 00:25, Robert Metzger <[hidden email]> wrote:
Here is the code defining the topology: DataStream<String> stream = ...;
The error message implies type extraction should be possible when "all variables in the return type can be deduced from the input type(s)". This is true for flatMap(Tuple2<Long, T>, Collector<Tuple2<T, String>>), but if the signature is changed to void flatMap(SortedMap<T, Long>, Collector<Tuple2<T, Long>>), type inference fails.
|
Hi Yukun,
I think the problem of the input type inference is that SortedMap is a GenericType and not a Flink native type (like Tuple or POJO). This case is not supported at the moment. You can create an issue if you like, maybe there is a way to support this special type inference case. Timo On 09.07.2016 11:55, Yukun Guo wrote:
-- Freundliche Grüße / Kind Regards Timo Walther Follow me: @twalthr https://www.linkedin.com/in/twalthr |
Free forum by Nabble | Edit this page |