Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-717

SpecificDatumWriter is using GenericData.resolveUnion sometimes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4.1
    • 1.5.0
    • java
    • None
    • Mac, Java 6.

    • Reviewed

    Description

      From: avro-user

      I've tried to use union of null and the enum-type, but I've run into an issue with this approach when using the AvroOutputFormat. The following code summarizes my issue:

         public void testDataWriteWithSchema() throws IOException {
           final DataFileWriter<Event writer =
             new DataFileWriter<Event>(new SpecificDatumWriter<Event>());
      
           writer.create(Event.SCHEMA$, new File("target/datafile-test.avro"));
           writer.append(getEvent());
           writer.close();
         }
      
         public void testDataWriteWithSchemaWithClass() throws IOException {
           final DataFileWriter<Event writer =
             new DataFileWriter<Event>(new SpecificDatumWriter<Event>(Event.class));
      
           writer.create(Event.SCHEMA$, new File("target/datafile-test.avro"));
           writer.append(getEvent());
           writer.close();
         }
      

      When I don't pass in the Event.class to SpecificDatumWriter (the first test method), the above test fails with the following exception:

       Not in union ["null", {"type":"enum","name":"Suit","namespace":"foo","symbols":["SPADES","CLUBS","HEARS","DIAMONDS"]}]: SPADES
       at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:382)
       at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
       at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:100)
       at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:62)
       at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:54)
       at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:245)
      

      Scott Carey's reply:

      This looks like a bug. Can you file a ticket? In the first case, the constructor is not
      initializing the SpecificData object, which means that it is using GenericData.resolveUnion()
      instead of SpecificData.resolveUnion().

      The empty param constructor in SpecificDatumWriter should be
      public SpecificDatumWriter() { super(SpecificData.get()); }

      public SpecificDatumWriter() { }

      Attachments

        1. AVRO-717.patch
          4 kB
          Joe Crobak
        2. AVRO-717.patch
          1 kB
          Joe Crobak

        Activity

          People

            joecrobak Joe Crobak
            joecrobak Joe Crobak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: