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

Avro should have support for common constructs like UUID and Date

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.6
    • Fix Version/s: 1.8.1
    • Component/s: java
    • Labels:
      None

      Description

      Consider the following code:

      public class AvroExample
      {
          public static void main (String [] args) throws Exception
          {
              ReflectData rdata = ReflectData.AllowNull.get();
              Schema schema = rdata.getSchema(Temp.class);
              
              ReflectDatumWriter<Temp> datumWriter = 
                     new ReflectDatumWriter (Temp.class, rdata);
              DataFileWriter<Temp> fileWriter = 
                     new DataFileWriter<Temp> (datumWriter);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              fileWriter.create(schema, baos);
              fileWriter.append(new Temp());
              fileWriter.close();
      
              byte[] bytes = baos.toByteArray();
              GenericDatumReader<GenericRecord> datumReader = 
                      new GenericDatumReader<GenericRecord> ();
              SeekableByteArrayInput avroInputStream = 
                      new SeekableByteArrayInput(bytes);
              DataFileReader<GenericRecord> fileReader = 
                      new DataFileReader<GenericRecord>(avroInputStream, datumReader);
      
              schema = fileReader.getSchema();
              GenericRecord record = null;
              record = fileReader.next(record);
              System.out.println (record);
              System.out.println (record.get("id"));
          }
      }
      
      class Temp
      {
          UUID id = UUID.randomUUID();
          Date date = new Date();
          BigInteger bi = BigInteger.TEN;
      }
      

      Output from this code is:

      {"id": {}, "date": {}, "bi": "10"}
      

      UUID and Date type fields are very common in Java and can be found a lot in third-party code as well (where it may be difficult to put annotations).
      So Avro should include a default serialization/deserialization support for such fields.

        Attachments

        1. AVRO-1554.patch
          17 kB
          Sachin Goyal
        2. CustomEncodingUnionBug.zip
          4 kB
          Sachin Goyal
        3. AVRO-1554_2.patch
          20 kB
          Sachin Goyal
        4. AVRO-1554_3.patch
          20 kB
          Sachin Goyal

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sachingoyal Sachin Goyal
              • Votes:
                9 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: