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

C++ Resolving Decoding doesn't work if element removed from record in array.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.8.2
    • c++
    • None

    Description

      Writer schema:

      { 
          "type": "record",
          "name": "TestRecord",
          "fields": [
              {
                  "name": "array",
                  "type": {
                      "type": "array",
                      "items": {
                          "name": "item",
                          "type": "record",
                          "fields": [
                              { "name": "A", "type": "string" },
                              { "name": "B", "type": "string", "default": "foo" }
                          ]
                      }
                  }
              }
          ] 
      }
      

      Reader schema:

      { 
          "type": "record",
          "name": "TestRecord",
          "fields": [
              {
                  "name": "array",
                  "type": {
                      "type": "array",
                      "items": {
                          "name": "item",
                          "type": "record",
                          "fields": [
                              { "name": "A", "type": "string" }
                          ]
                      }
                  }
              }
          ] 
      }
      

      Data is:

      {
        "array": [
          {
            "A": "",
            "B": ""
          }
        ]
      }
      

      The following code fails with an exception “Expected: Repeater got String”. The equivalent java code works fine on the same schema and data.

      auto decoder = avro::resolvingDecoder(writerSchema,
                                            readerSchema,
                                            avro::jsonDecoder(writerSchema));
      
      strinstream ss = loadData();  
      auto_ptr<avro::InputStream> in = avro::istreamInputStream(ss);
      decoder->init(*in);
      
      auto record = reader::TestRecord();
      decode(*decoder, record);
      

      I stepped through the code and what seems to be happening is that the code is treating “A” and “B” as distinct elements in the array, as if the array had two elements rather than one.

      I'm not sure how to go about fixing this. Any pointers would be appreciated. (I don't think it's my C++ test code. It works fine if the record above isn't in an array.)

      Attachments

        1. AVRO-1912.patch
          5 kB
          John McClean

        Activity

          People

            comm@squotd.net John McClean
            comm@squotd.net John McClean
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: