Github user mike0sv commented on the issue:

    https://github.com/apache/spark/pull/18488
  
    Ran into something strange. Changed ints to strings and it worked fine. But 
then I added a test for encoding bean with enum inside and the test failed. It 
failed because in my implementation deserializer returns Object (AnyRef), and 
if enum is top-level object it works fine. But if enum is a field, it tries to 
set it via setter, which does not accept arbitrary object. So, I changed 
implementation of deserializer to the following.
    ```  
      def enumDeserializer[T <: Enum[T]](enum: Class[T]): InternalRow => T = {
        assert(enum.isEnum)
        value: InternalRow =>
          Enum.valueOf(enum, value.toString)
      }
    
      def deserializeEnumName[T <: Enum[T]](typeDummy: T, inputObject: 
InternalRow): T = {
        enumDeserializer(typeDummy.getClass.asInstanceOf[Class[T]])(inputObject)
      }
    ```
    
    Now it failed with "Assignment conversion not possible from type 
"java.lang.Enum" to type "test.org.apache.spark.sql.JavaDatasetSuite$EnumBean"" 
at 
    ```
    private test.org.apache.spark.sql.JavaDatasetSuite$EnumBean argValue;
    private InternalRow argValue1;
    ........
    final test.org.apache.spark.sql.JavaDatasetSuite$EnumBean value2 = 
resultIsNull ? null : 
org.apache.spark.sql.types.DataTypes.deserializeEnumName(argValue, argValue1);
    ```
    which is odd, because if I call it from regular code it compiles just fine.
    ```  
        EnumBean argValue = EnumBean.values()[0];
        InternalRow argValue1 = null;
        final EnumBean bean = deserializeEnumName(argValue, argValue1);
    ```
    
    I even tried moving code to java class just in case, but that did no good.
    Is there any difference in compiling environments that could be the cause 
of that?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to