avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vinicius Carvalho <viniciusccarva...@gmail.com>
Subject Project renamed fields on readers with old schema
Date Sat, 19 Mar 2016 23:18:44 GMT
Hi there, I have a question on forward compatibility and field renaming.

I have two schemas:

v1:

{
  "namespace" : "io.igx.android",
  "type" : "record",
  "name" : "Sensor",
  "fields" : [
    {"name":"id","type":"string"},
    {"name":"temperature", "type":"float", "default":0.0},
    {"name":"acceleration", "type":"float","default":0.0},
    {"name":"velocity","type":"float","default":0.0},
    {"name":"accelerometer","type":[
      "null",{
        "type":"array",
        "items":"float"
      }
    ]},
    {"name":"magneticField","type":[
      "null",{
        "type":"array",
        "items":"float"
      }
    ]},
    {"name":"orientation","type":[
      "null",{
        "type":"array",
        "items":"float"
      }
    ],"default":null}

  ]

}

v2:

{
  "namespace" : "io.igx.android",
  "type" : "record",
  "name" : "Sensor",
  "fields" : [
    {"name":"id","type":"string"},
    {"name":"internalTemperature", "type":"float", "default":0.0,
"aliases":["temperature"]},
    {"name":"externalTemperature", "type":"float", "default":0.0},
    {"name":"acceleration", "type":"float","default":0.0},
    {"name":"velocity","type":"float","default":0.0},
    {"name":"accelerometer","type":[
      "null",{
        "type":"array",
        "items":"float"
      }
    ]},
    {"name":"magneticField","type":[
      "null",{
        "type":"array",
        "items":"float"
      }
    ]}
  ]

}


So in v2 I've added a field, removed one, and renamed temperature to
"internalTemperature"

When I have producers of v1 and consumers using v2 there's no issues

But when I produce the message using v2 and try to read from v1 temperature
gets the default value of 0.0, I was hoping that since v2 has an alias to
temperature, the v1 reader would understand and read that as well.

Is there a way to project renamed fields on readers using old schema
versions?

Thanks

Mime
View raw message