[ 
https://issues.apache.org/jira/browse/FLINK-14380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16952597#comment-16952597
 ] 

Timo Walther commented on FLINK-14380:
--------------------------------------

Hi [~elliotvilhelm], I agree that we should support immutable types in the 
future. The issues you have mentioned and also the interoperability with Scala 
are big arguments for improvements here. For the Table API, we will support 
immutable types as mentioned in 
[FLIP-65|https://docs.google.com/document/d/1Zf8-okGvCiTTRaTN0IqtTGrrjXYNGFJnhUQyinF4xcU/edit?ts=5d9f20a2#].
 I hope some of the improvements will bubble up into Flink's the core modules. 
But for this (as Aljoscha mentioned) we need changes on the serializer side as 
well. The type extractor must be kept in sync with what the serializers support.

> Type Extractor POJO setter check does not allow for Immutable Case Class
> ------------------------------------------------------------------------
>
>                 Key: FLINK-14380
>                 URL: https://issues.apache.org/jira/browse/FLINK-14380
>             Project: Flink
>          Issue Type: Bug
>          Components: API / Scala
>    Affects Versions: 1.8.2, 1.9.0
>         Environment: Not relavent
>  
>            Reporter: Elliot Pourmand
>            Priority: Major
>
> When deciding if a class conforms to POJO using the type extractor Flink 
> checks that the class implements a setter and getter method. For the setter 
> method Flink makes the assertion that the return type is `Void`. This is an 
> issue if using a case class as often the return type of a case class setter 
> is a copy of the objects class. Consider the following case class:
> {code:scala}
> case class  SomeClass(x: Int) {
>     x_=(newX: Int): SomeClass = { this.copy(x = newX) }
> }
> {code}
> This class will be identified as not being valid POJO although getter 
> (generated) and setter methods are provided because the return type of the 
> setter is not void. 
> This issue discourages immutabilaty and makes the usage of case classes not 
> possible without falling back to Kryo Serializer.
> The issue is located in 
> https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
>  on line 1806. Here is a permalink to the line 
> https://github.com/apache/flink/blob/80b27a150026b7b5cb707bd9fa3e17f565bb8112/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L1806
> A copy of the if check is here
> {code:java}
> if((methodNameLow.equals("set"+fieldNameLow) || 
> methodNameLow.equals(fieldNameLow+"_$eq")) &&
>                                       m.getParameterTypes().length == 1 && // 
> one parameter of the field's type
>                                       
> (m.getGenericParameterTypes()[0].equals( fieldType ) || (fieldTypeWrapper != 
> null && m.getParameterTypes()[0].equals( fieldTypeWrapper )) || 
> (fieldTypeGeneric != null && 
> m.getGenericParameterTypes()[0].equals(fieldTypeGeneric) ) )&&
>                                       // return type is void.
>                                       m.getReturnType().equals(Void.TYPE)
>                               ) {
>                                       hasSetter = true;
>                               }
>                       }
> {code}
> I believe the 
> {code:java}
> m.getReturnType().equals(Void.TYPE)
> {code}
> should be modified to 
> {code:java}
> m.getReturnType().equals(Void.TYPE) || m.getReturnType().equals(clazz)
> {code}
> This will allow for case class setters which return copies of the object 
> enabling to use case classes. This allows us to maintain immutability without 
> being forced to fall back to the Kryo Serializer.  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to