Avro
  1. Avro
  2. AVRO-1320

Java: Trevni incorrectly reads specific enums.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.5
    • Component/s: java
    • Labels:
      None

      Description

      Enums generated by the specific compiler are not read correctly when written to an Avro data file.

      Reported by Bernd Fondermann on the developer mailing list.

      1. AVRO-1320.patch
        4 kB
        Doug Cutting
      2. AVRO-1320.patch
        5 kB
        Doug Cutting

        Activity

        Hide
        Doug Cutting added a comment -

        Here's a patch that should fix this.

        Bernd, can you please verify whether this fixes things for you?

        Show
        Doug Cutting added a comment - Here's a patch that should fix this. Bernd, can you please verify whether this fixes things for you?
        Hide
        Bernd Fondermann added a comment -

        the patch itself works, but does not resolve things for me.
        after applying the patch, WPPage now contains in put()
        case 3: type = (generated.WPPageType)value$; break;
        However, even with a freshly generated trevi file, when reading it I still get:
        Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to generated.WPPageType
        It seems the deserialization still creates an Integer.

        Show
        Bernd Fondermann added a comment - the patch itself works, but does not resolve things for me. after applying the patch, WPPage now contains in put() case 3: type = (generated.WPPageType)value$; break; However, even with a freshly generated trevi file, when reading it I still get: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to generated.WPPageType It seems the deserialization still creates an Integer.
        Hide
        Doug Cutting added a comment -

        Can you please post the full schema and stack trace? Thanks!

        Show
        Doug Cutting added a comment - Can you please post the full schema and stack trace? Thanks!
        Hide
        Bernd Fondermann added a comment -

        stack trace:

        Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to generated.WPPageType
        at generated.WPPage.put(WPPage.java:50)
        at org.apache.avro.generic.GenericData.setField(GenericData.java:530)
        at org.apache.trevni.avro.AvroColumnReader.read(AvroColumnReader.java:221)
        at org.apache.trevni.avro.AvroColumnReader.next(AvroColumnReader.java:190)
        at trevni.TrevniFileDump.main(TrevniFileDump.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

        schema:
        {
        "namespace": "generated",
        "type": "record",
        "name": "WPPage",
        "fields": [

        { "name": "name", "type": "string" }

        ,

        { "name": "size", "type": "int" }

        ,
        {
        "name": "links",
        "type":

        { "type": "array", "items": "string" }

        },
        {
        "name": "type",
        "type": [

        { "namespace": "generated", "name": "WPPageType", "type": "enum", "symbols": ["article", "redirect", "disambiguation"] }

        ,
        "null"
        ]
        }
        ]
        }

        I'll try again without the union.

        Show
        Bernd Fondermann added a comment - stack trace: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to generated.WPPageType at generated.WPPage.put(WPPage.java:50) at org.apache.avro.generic.GenericData.setField(GenericData.java:530) at org.apache.trevni.avro.AvroColumnReader.read(AvroColumnReader.java:221) at org.apache.trevni.avro.AvroColumnReader.next(AvroColumnReader.java:190) at trevni.TrevniFileDump.main(TrevniFileDump.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) schema: { "namespace": "generated", "type": "record", "name": "WPPage", "fields": [ { "name": "name", "type": "string" } , { "name": "size", "type": "int" } , { "name": "links", "type": { "type": "array", "items": "string" } }, { "name": "type", "type": [ { "namespace": "generated", "name": "WPPageType", "type": "enum", "symbols": ["article", "redirect", "disambiguation"] } , "null" ] } ] } I'll try again without the union.
        Hide
        Bernd Fondermann added a comment -

        with a simple nested enum type the patch fixes this issue.

        Show
        Bernd Fondermann added a comment - with a simple nested enum type the patch fixes this issue.
        Hide
        Doug Cutting added a comment -

        I found the problem with the union. The wrong schema was passed down. Here's a patch that fixes that too and adds a test for it.

        Show
        Doug Cutting added a comment - I found the problem with the union. The wrong schema was passed down. Here's a patch that fixes that too and adds a test for it.
        Hide
        Bernd Fondermann added a comment -

        problem is fixed for me. thanks for the quick help.

        Show
        Bernd Fondermann added a comment - problem is fixed for me. thanks for the quick help.
        Hide
        Doug Cutting added a comment -

        I committed this.

        Show
        Doug Cutting added a comment - I committed this.

          People

          • Assignee:
            Doug Cutting
            Reporter:
            Doug Cutting
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development