Comments (2)
Fast-written & dirty workaround for both cases described above.
local _slow_xflatten_helper
_slow_xflatten_helper = function(schema_names, top_path, obj_partial)
local exps = {}
for k, v in pairs(obj_partial) do
local cur_path = (top_path == '') and k or (top_path .. '.' .. k)
if type(v) == 'table' then
local ok, new_exps = _slow_xflatten_helper(
schema_names, cur_path, v)
if not ok then
return false, new_exps
end
for _, exp in ipairs(new_exps) do
exps[#exps + 1] = exp
end
else
local column_no = -1
for i, name in ipairs(schema_names) do
if name == cur_path then
column_no = i
break
end
end
if column_no == -1 then
local reason = 'cannot find fields name: ' .. cur_path
return false, reason
end
exps[#exps + 1] = {'=', column_no, v}
end
end
return true, exps
end
-- Note: no array, no enum support
local slow_xflatten = function(schema_handle, obj_partial)
local schema_names = avro.get_names(schema_handle)
return _slow_xflatten_helper(schema_names, '', obj_partial)
end
local xflatten_wrapper = function(model, schema_handle, obj_partial)
local valid_exps = function(exps)
for _, exp in ipairs(exps) do
local valid_exp = type(exp) == 'table' and #exp == 3
if valid_exp then
-- XXX: more checks?
-- local op, field_no, value = unpack(exp)
else
return false
end
end
return true
end
local ok, exps = model.xflatten(obj_partial)
local unkn_msg = 'Internal error: unknown code'
local is_case_1 = not ok and type(exps) == 'string' and exps == unkn_msg
local is_case_2 = ok and type(exps) == 'table' and not valid_exps(exps)
if not (is_case_1 or is_case_2) then
return ok, exps
end
return slow_xflatten(schema_handle, obj_partial)
end
Then invoke xflatten_wrapper(model, schema_handle, obj_partial)
instead of model.xflatten(obj_partial)
, where schema_handle
is what avro.create()
returns and model
is what avro.compile()
returns (assuming local avro = require('avro_schema')
).
from avro-schema.
Works correctly in both cases with debug (w/o optimization):
local _, model = avro.compile({schema_handler, debug=true})
The input of unparse_msgpack
w/o optimization:
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 2 !!!
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 3
unparse_msgpack; *typeid: 0x12 (18) -- PUTSTRC; value: 1
unparse_msgpack; *typeid: 0x04 (4) -- PUTINT / PUTLONG; value: 2
unparse_msgpack; *typeid: 0x08 (8) -- PUTSTR; value: 3
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 3
unparse_msgpack; *typeid: 0x12 (18) -- PUTSTRC; value: 1
unparse_msgpack; *typeid: 0x04 (4) -- PUTINT / PUTLONG; value: 1
unparse_msgpack; *typeid: 0x08 (8) -- PUTSTR; value: 3
The input w/ optimization (broken):
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 3 !!!
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 3
unparse_msgpack; *typeid: 0x12 (18) -- PUTSTRC; value: 1
unparse_msgpack; *typeid: 0x04 (4) -- PUTINT / PUTLONG; value: 2
unparse_msgpack; *typeid: 0x08 (8) -- PUTSTR; value: 3
unparse_msgpack; *typeid: 0x00 (0) -- (zero); value: 0 !!!
unparse_msgpack; *typeid: 0x0B (11) -- PUTARRAYC; value: 3
unparse_msgpack; *typeid: 0x12 (18) -- PUTSTRC; value: 1
unparse_msgpack; *typeid: 0x04 (4) -- PUTINT / PUTLONG; value: 1
unparse_msgpack; *typeid: 0x08 (8) -- PUTSTR; value: 3
from avro-schema.
Related Issues (20)
- Random flatten errors HOT 1
- Create validate which do not copy a data
- Document 'hidden' field feature
- nil and box.NULL are treated differently in validate of a union
- Consider adding package level constants for types HOT 2
- Wrong array validation HOT 1
- flatten says 'Expecting MAP, encountered LONG' for a string
- validate, default value MAP convert to ARRAY HOT 2
- Attempt to get element -1 from stack of size -1 HOT 8
- LuajitError: <schema-jit>:<LINE>: function at line <LINE> has more than 200 local variables HOT 4
- Non-informative error on empty model creation HOT 3
- Support decimal
- document: add doc for avro.create options argument
- validation for "long" allows "string" HOT 3
- [string "avro.utils.fstack"]:31: attempt to call field 'clear' (a nil value)
- Consider replacing back fstack with debug.getlocal() HOT 1
- Error when a schema has defaults array values HOT 1
- Set up simple CI based on GitHub Actions
- Nullable enum field causes data corruption on unflatten
- RPM fails to build with packpack HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avro-schema.