do
avro = require('avro_schema')
schematext = [[
{
"name":"test",
"type":"record",
"fields":
[
{
"name": "usageType",
"type":
{
"name": "usageTypeEnum",
"type": "enum*",
"symbols": [ "monetary", "voice", "data", "sms", "other" ]
}
},
{
"name":"stub",
"type":"string"
}
]
}]]
json = require('json')
ok, schema = avro.create(json.decode(schematext))
if not ok then error (schema) end
ok, methods = avro.compile(schema)
if not ok then error (methods) end
ok, flt = methods.flatten({usageType='voice',stub='stub'})
if not ok then error (flt) end
ok, uflt = methods.unflatten(flt)
if not ok then error (flt) end
return uflt
end
With different data layout 'unflatten' may complain '27: Expecting LONG, encountered STR' where 27-th member of the tuple is string and it should be string, but 26-th is 'enum'.
Changing 'enum' to 'enum' produces expected result in both cases
expected result:
{'stub': 'stub', 'usageType': 'voice'}
actual result:{'stub': !!binary DpIg1AcAAACS, 'usageType': 'voice'}
With different data layout 'unflatten' may complain '27: Expecting LONG, encountered STR' where 27-th member of the tuple is string and it should be string, but 26-th is 'enum'. Changing 'enum' to 'enum' produces expected result in both cases