flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kostas Kloudas (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-6024) Need more fine-grained info for "InvalidProgramException: This type (...) cannot be used as key"
Date Mon, 13 Mar 2017 13:11:42 GMT

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

Kostas Kloudas commented on FLINK-6024:

I totally agree that the Error message should be more explanatory. 

With the fix for the Streaming API, we just do not accept any Arrays as keys and for POJOs
we check if the class overrides the {{hashCode}} method. Essentially the check is

(type instanceof PojoTypeInfo) {
		? !type.getTypeClass().getMethod("hashCode").getDeclaringClass().equals(Object.class)
		:  !(type instanceof PrimitiveArrayTypeInfo || type instanceof BasicArrayTypeInfo || type
instanceof ObjectArrayTypeInfo)

Still you can violate the contract and provide an invalid key by using a {{KeySelector}} that
returns {{Object}} as a key. The reason is that we get the type of the key from the {{TypeInformation}},
which now will think that your key is a simple {{Object}}. The reason for allowing it is because
many people leave their {{KeySelector}} implementation return {{Object}}, which is the default.

> Need more fine-grained info for "InvalidProgramException: This type (...) cannot be used
as key"
> ------------------------------------------------------------------------------------------------
>                 Key: FLINK-6024
>                 URL: https://issues.apache.org/jira/browse/FLINK-6024
>             Project: Flink
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.2.0
>            Reporter: Luke Hutchison
> I got this very confusing exception:
> {noformat}
> InvalidProgramException: This type (MyType) cannot be used as key
> {noformat}
> I dug through the code, and could not find what was causing this. The help text for type.isKeyType(),
in Keys.java:329, right before the exception is thrown, says: "Checks whether this type can
be used as a key. As a bare minimum, types have to be hashable and comparable to be keys."
However, this didn't solve the problem.
> I discovered that in my case, the error was occurring because I added a new constructor
to the type, and I didn't have a default constructor. This is probably quite a common thing
to happen for POJOs, so the error message should give some detail saying that this is the
> Other things that can cause this to fail, including that the class is not public, or
the constructor is not public, or the key field is not public, or that the key field is not
a serializable type, or the key is not Comparable, or the key is not hashable, should be given
in the error message instead, depending on the actual cause of the problem.

This message was sent by Atlassian JIRA

View raw message