node-avro-io icon indicating copy to clipboard operation
node-avro-io copied to clipboard

Union encode/decode

Open wision opened this issue 11 years ago • 0 comments

I tried three different implementations of avro (java/php/nodejs) and with yours I'm encountering a problem while encoding unions.

Consider schema:

avro_schema =
    name: 'foo'
    type: 'record'
    fields:
        [
            name: 'bar'
            type: ['null', 'string']
        ]

..and data..

data1 =
    bar: 'foo'

data2 =
    bar: null

I had no problems encoding exactly the same data and schema in php/java, but node-avro-io gives me this error:

TypeError: Object.keys called on non-object
  at Function.keys (native)
  at Object.DatumWriter.writeUnion (./node_modules/node-avro-io/lib/io.js:529:53)
  at Object.DatumWriter.writeData (./node_modules/node-avro-io/lib/io.js:481:34)
  at DatumWriter.writeRecord (./node_modules/node-avro-io/lib/io.js:547:18)
  at Array.forEach (native)
  at Function._.each._.forEach (./node_modules/node-avro-io/node_modules/underscore/underscore.js:79:11)
  at Object.DatumWriter.writeRecord (./node_modules/node-avro-io/lib/io.js:546:11)
  at Object.DatumWriter.writeData (./node_modules/node-avro-io/lib/io.js:484:34)
  at Object.DatumWriter.write (./node_modules/node-avro-io/lib/io.js:459:14)
  at Object.<anonymous> (./avro.coffee:199:1, <js>:301:14)
  at Object.<anonymous> (./avro.coffee:1:1, <js>:317:4)
  at Module._compile (module.js:449:26)

I believe the problem is that you expect data in the format of encoded data (according to Apache Avro specification):

data1 =
    bar:
        string: 'foo'

data2 =
    bar:
        null: null

Could you please look into this issue?

Cheers, Martin

wision avatar Jul 10 '13 17:07 wision