tarantool / avro-schema

Apache Avro schema tools for Tarantool
57 stars 4 forks source link

Nullable enum field causes data corruption on unflatten #146

Open RojinBaka opened 2 years ago

RojinBaka commented 2 years ago
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

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