While trying to fix
FLINK-14042, FlinkTypeFactory causes a couple of problems that can not be fixed easily. Some issues:
- Inconsistent caching: FlinkTypeFactory still maintains its own seenTypes whereas the legacy planner already removed it due to inconsistent equality issues. The same problem still exists in the Blink planner regarding time attributes. Let's investigate if we can implement a TimestampType.equals including this metadata.
- Mutation of nullability: createTypeWithNullability removes NOT NULL information when copying fields
- Handling of RAW types: According to FLIP-37, raw types should work with type serializer. Currently, type information is used.
- Relation to JavaTypeFactoryImpl: There is no concrete reason why we use JavaTypeFactoryImpl as far I can see. SqlTypeFactoryImpl should do the job.
I suggest to reimplement the FlinkTypeFactory in Java and perform a code review, code simplification at the same time.