Any advice would be appreciated :)

Thanks,

Dongwon

---------- Forwarded message ---------
From: Dongwon Kim <eastcirc...@gmail.com>
Date: Mon, Dec 14, 2020 at 11:27 PM
Subject: How to gracefully avoid "Generic types have been disabled in the
ExecutionConfig and type java.util.List is treated as a generic type"?
To: user <user@flink.apache.org>


Hi,

The following program compiles and runs w/o exceptions:

> public class Test {
>
>   public static class A {
>     private int n;
>
>     public A() { }
>     public int getN() {  return n;  }
>     public void setN(int n) {  this.n = n;  }
>   }
>
>   public static class B {
>     private List<A> lst;
>
>     public B() { }
>     public List<A> getLst() {  return lst;  }
>     public void setLst(List<A> lst) {  this.lst = lst;  }
>   }
>
>   public static void main(String[] args) throws Exception {
>     StreamExecutionEnvironment env =
> StreamExecutionEnvironment.createLocalEnvironment();
>
>     env.fromElements(new B())
>       .print();
>
>     env.execute();
>   }
> }
>

When I add the following line,

> env.getConfig().disableGenericTypes();

then the program shows me an exception:

> Exception in thread "main" java.lang.UnsupportedOperationException:
> Generic types have been disabled in the ExecutionConfig and type
> java.util.List is treated as a generic type.
> at
> org.apache.flink.api.java.typeutils.GenericTypeInfo.createSerializer(GenericTypeInfo.java:86)
> at
> org.apache.flink.api.java.typeutils.PojoTypeInfo.createPojoSerializer(PojoTypeInfo.java:319)
> at
> org.apache.flink.api.java.typeutils.PojoTypeInfo.createSerializer(PojoTypeInfo.java:311)
> at
> org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.fromCollection(StreamExecutionEnvironment.java:970)
> at
> org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.fromElements(StreamExecutionEnvironment.java:871)
> at Test.main(Test.java:29)


To avoid this exception, I found that I have to declare a type factory like:

>   public static class BTypeFactory extends TypeInfoFactory<B> {
>     @Override
>     public TypeInformation<B> createTypeInfo(Type t, Map<String,
> TypeInformation<?>> genericParameters) {
>       return Types.POJO(
>         B.class,
>         ImmutableMap.<String, TypeInformation<?>>builder()
>           .put("lst", Types.LIST(Types.POJO(A.class)))
>         .build()
>       );
>     }
>   }

and give it to class B as follows:

>   @TypeInfo(BTypeFactory.class)
>   public static class B {


Is there no other way but to declare BTypeFactory in such cases?
I don't like the way I have to type a field name twice, one for a member
variable and the other for an Map entry in TypeInfoFactory.

Thanks in advance,

Dongwon

Reply via email to