[
https://issues.apache.org/jira/browse/FLINK-16596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17072213#comment-17072213
]
Felix Wollschläger commented on FLINK-16596:
--------------------------------------------
Of course, users can as it currently is use Enums as a Key by simply calling
_name()_ or _ordinal()_ in the _KeySelector_. But to access the actual Key (the
enum) in a ProcessFunction they would have to call _valueOf(String)_ or
_values()[key]_ after that. It just doesn't feel so natural.
Another thing is if the Enum-Value is just a part of the Key, for example
_Tuple2<SomeEnumType, Long>_ , where the long is a SessionID and the SessionID
is only unique in that given Enum-Value. Also, a possible user-side solution
here would be to use a custom type instead of _Tuple2_ and implement _hashCode_
using the Enums _ordinal_ / _name_ in that class.
I'm with you, I would not want to add too much complexity in Flink for this
little improvement. If this can be done with an abstract
_KeySelector_-Implementation that Flink-Users can take advantage of in such a
case, it would be nice to have. If not, and/or it would need too much changes
internals of Flink, this ticket is not worth the effort and can be closed.
> Support Enum-Values as part of a Key
> ------------------------------------
>
> Key: FLINK-16596
> URL: https://issues.apache.org/jira/browse/FLINK-16596
> Project: Flink
> Issue Type: Improvement
> Components: API / DataStream
> Reporter: Felix Wollschläger
> Priority: Major
>
> See: FLINK-11774
> h2. Description:
> The hashCode implementation of Enum-Values is guaranteed to be stable inside
> a JVM, but not accross multiple JVMs. This leads to failures when restoring
> from a checkpoint/savepoint containing Keyed-State on Keys with Enums as a
> part of the key.
> For users of Flink there is a workaround to solve this problem:
> Don't rely on the hashCode-Implementation of Enum-Values in the
> hashCode-Implementation of the actual key. Use the ordinal() or
> name().hashCode() instead of the Enum hashCode.
> h2. Goals of this improvement:
> Implement a way to handle Enum-Values, by either handling Enum-Values on a
> internal level or implementing a abstract Base KeySelector class that users
> of flink can choose if their key contains a Enum-Value.
> Code to reproduce a failure and first thoughts can be found in FLINK-11774 .
--
This message was sent by Atlassian Jira
(v8.3.4#803005)