From: imeevma@tarantool.org To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: v.shpilevoy@tarantool.org Subject: [PATCH v2 1/1] lua: wrong 'tomap' work with nullable fields Date: Fri, 24 Aug 2018 14:04:06 +0300 [thread overview] Message-ID: <50a0f1e87e6c6fd90b6472b420c330cec0325ce9.1535108521.git.imeevma@gmail.com> (raw) Tuple method 'tomap' in some cases worked improperly if tuple length less than it should be according to space format. Fixed in this patch. Closes #3631 --- Branch: https://github.com/tarantool/tarantool/tree/imeevma/gh-3631-wrong-tomap-work-with-nullable-fields Issue: https://github.com/tarantool/tarantool/issues/3631 src/box/lua/tuple.c | 4 +-- test/engine/tuple.result | 63 ++++++++++++++++++++++++++++++++++++++++++++++ test/engine/tuple.test.lua | 23 +++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index 7ca4299..5acbecb 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -284,12 +284,12 @@ lbox_tuple_to_map(struct lua_State *L) luaL_error(L, "Usage: tuple:tomap()"); const struct tuple *tuple = lua_checktuple(L, 1); const struct tuple_format *format = tuple_format(tuple); - const struct tuple_field *field = &format->fields[0]; const char *pos = tuple_data(tuple); int field_count = (int)mp_decode_array(&pos); int n_named = format->dict->name_count; lua_createtable(L, field_count, n_named); - for (int i = 0; i < n_named; ++i, ++field) { + int named_and_presented = MIN(field_count, n_named); + for (int i = 0; i < named_and_presented; ++i) { /* Access by name. */ const char *name = format->dict->names[i]; lua_pushstring(L, name); diff --git a/test/engine/tuple.result b/test/engine/tuple.result index b3b23b2..88bb3b4 100644 --- a/test/engine/tuple.result +++ b/test/engine/tuple.result @@ -590,6 +590,69 @@ maplen(t1map), t1map[1], t1map[2], t1map[3] s:drop() --- ... +-- +-- gh-3631: Wrong 'tomap' work with nullable fields +-- +format = {} +--- +... +format[1] = {'first', 'unsigned'} +--- +... +format[2] = {'second', 'unsigned'} +--- +... +format[3] = {'third', 'unsigned'} +--- +... +format[4] = {'fourth', 'string', is_nullable = true} +--- +... +s = box.schema.space.create('test', {format = format, engine = engine}) +--- +... +pk = s:create_index('primary', {parts = {1, 'unsigned'}}) +--- +... +s:insert({1, 2, 3}) +--- +- [1, 2, 3] +... +tuple = s:get(1) +--- +... +tuple +--- +- [1, 2, 3] +... +-- Should be NULL +tuple.fourth +--- +- null +... +-- Should have only three named fields +tuple:tomap() +--- +- 1: 1 + 2: 2 + 3: 3 + third: 3 + second: 2 + first: 1 +... +-- Should be NULL +tuple:tomap().fourth +--- +- null +... +-- Should be nil +type(tuple:tomap().fourth) +--- +- nil +... +s:drop() +--- +... engine = nil --- ... diff --git a/test/engine/tuple.test.lua b/test/engine/tuple.test.lua index 6d7d254..723dde4 100644 --- a/test/engine/tuple.test.lua +++ b/test/engine/tuple.test.lua @@ -200,5 +200,28 @@ t1map = t1:tomap() maplen(t1map), t1map[1], t1map[2], t1map[3] s:drop() +-- +-- gh-3631: Wrong 'tomap' work with nullable fields +-- +format = {} +format[1] = {'first', 'unsigned'} +format[2] = {'second', 'unsigned'} +format[3] = {'third', 'unsigned'} +format[4] = {'fourth', 'string', is_nullable = true} +s = box.schema.space.create('test', {format = format, engine = engine}) +pk = s:create_index('primary', {parts = {1, 'unsigned'}}) +s:insert({1, 2, 3}) +tuple = s:get(1) +tuple +-- Should be NULL +tuple.fourth +-- Should have only three named fields +tuple:tomap() +-- Should be NULL +tuple:tomap().fourth +-- Should be nil +type(tuple:tomap().fourth) +s:drop() + engine = nil test_run = nil -- 2.7.4
next reply other threads:[~2018-08-24 11:04 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-24 11:04 imeevma [this message] 2018-08-24 11:50 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=50a0f1e87e6c6fd90b6472b420c330cec0325ce9.1535108521.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v2 1/1] lua: wrong '\''tomap'\'' work with nullable fields' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox