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

the problem of resolving schema

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.7.5
    • None
    • java
    • jdk1.7.0_45

    • schema,serialize

    Description

      In Apache Avro™ 1.7.5 Documentation, have a sentence like this:

      Since both client and server both have the other's full schema, correspondence between same named fields, missing fields, extra fields, etc. can all be easily resolved.

      But if client has two fields and server has three fields, the server can't resolve.

      Client avsc:
      {"type":"record",
      "name":"UserLess",
      "namespace":"com.joyveb.test.bean",
      "fields":[

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

      ,

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

      ]}

      serialize codes:
      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      GenericDatumWriter<Object> w = new GenericDatumWriter<Object>(userLess.getSchema());
      Encoder e = EncoderFactory.get().binaryEncoder(bao, null);
      w.write(object, e);
      e.flush();
      ByteBuffer.wrap(bao.toByteArray());

      Server avsc:
      {"type":"record",
      "name":"UserMore",
      "namespace":"com.joyveb.test.bean",
      "fields":[

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

      ,

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

      ,

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

      ]}

      deserialize codes:
      BinaryDecoder in = DecoderFactory.get().binaryDecoder(bytes, null);
      Object result = new GenericDatumReader<Object>(userMore.getSchema()).read(null, in);

      After run the program, following exception comes out.

      Exception in thread "main" java.io.EOFException
      at org.apache.avro.io.BinaryDecoder.ensureBounds(BinaryDecoder.java:473)
      at org.apache.avro.io.BinaryDecoder.readInt(BinaryDecoder.java:128)
      at org.apache.avro.io.BinaryDecoder.readString(BinaryDecoder.java:259)
      at org.apache.avro.io.ValidatingDecoder.readString(ValidatingDecoder.java:107)
      at org.apache.avro.generic.GenericDatumReader.readString(GenericDatumReader.java:363)
      at org.apache.avro.generic.GenericDatumReader.readString(GenericDatumReader.java:355)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:157)
      at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:193)
      at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:183)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:151)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:142)
      at com.joyveb.dbpapi.AvroByteUtil.deserialize(AvroByteUtil.java:81)
      at com.joyveb.dbpapi.test.avro.SchemaByteTest.less2more(SchemaByteTest.java:34)
      at com.joyveb.dbpapi.test.avro.SchemaByteTest.main(SchemaByteTest.java:15)

      Attachments

        Activity

          People

            Unassigned Unassigned
            nivance nivance
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: