Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 1/1] box: fix format of tuple produced with frommap()
Date: Wed, 20 Mar 2019 16:31:51 +0300	[thread overview]
Message-ID: <558c48af114ba67b997489ce2a150ffa1b7f5a22.1553088664.git.kshcherbatov@tarantool.org> (raw)

Previously, all tuples created with frommap() used default format
table_format_runtime, and therefore the created data tuples were
not checked for the ability to be inserted into the target space.

Moreover frommap(...):tomap(...) procedures sequence also did not
work because tomap(..) routine assumes that the tuple has format
with field names.

Closes #4045

Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-4045-frommap-tuple-format-fix
Issue: https://github.com/tarantool/tarantool/issues/4045
---
 src/box/lua/space.cc    |  2 +-
 src/box/lua/tuple.c     | 11 ++++++++---
 src/box/lua/tuple.h     |  3 ++-
 test/box/tuple.result   | 25 +++++++++++++++++++++----
 test/box/tuple.test.lua | 12 +++++++++---
 5 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
index 7aa0b6661..9dfc97b6a 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -510,7 +510,7 @@ lbox_space_frommap(struct lua_State *L)
 
 	lua_replace(L, 1);
 	lua_settop(L, 1);
-	return lbox_tuple_new(L);
+	return luaT_tuple_new(L, space->format);
 usage_error:
 	return luaL_error(L, "Usage: space:frommap(map, opts)");
 }
diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index 5f2bfc807..60c1a3999 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -94,7 +94,7 @@ luaT_istuple(struct lua_State *L, int narg)
 }
 
 int
-lbox_tuple_new(lua_State *L)
+luaT_tuple_new(struct lua_State *L, struct tuple_format *format)
 {
 	int argc = lua_gettop(L);
 	if (argc < 1) {
@@ -120,8 +120,7 @@ lbox_tuple_new(lua_State *L)
 	}
 	mpstream_flush(&stream);
 
-	box_tuple_format_t *fmt = box_tuple_format_default();
-	struct tuple *tuple = box_tuple_new(fmt, buf->buf,
+	struct tuple *tuple = box_tuple_new(format, buf->buf,
 					   buf->buf + ibuf_used(buf));
 	if (tuple == NULL)
 		return luaT_error(L);
@@ -131,6 +130,12 @@ lbox_tuple_new(lua_State *L)
 	return 1;
 }
 
+static int
+lbox_tuple_new(lua_State *L)
+{
+	return luaT_tuple_new(L, box_tuple_format_default());
+}
+
 static int
 lbox_tuple_gc(struct lua_State *L)
 {
diff --git a/src/box/lua/tuple.h b/src/box/lua/tuple.h
index 5d7062eb8..ba7f01f4b 100644
--- a/src/box/lua/tuple.h
+++ b/src/box/lua/tuple.h
@@ -37,6 +37,7 @@ extern "C" {
 #endif /* defined(__cplusplus) */
 
 struct tuple;
+struct tuple_format;
 typedef struct tuple box_tuple_t;
 struct lua_State;
 struct mpstream;
@@ -67,7 +68,7 @@ luaT_istuple(struct lua_State *L, int idx);
 /** \endcond public */
 
 int
-lbox_tuple_new(struct lua_State *L);
+luaT_tuple_new(struct lua_State *L, struct tuple_format *format);
 
 static inline int
 luaT_pushtupleornil(struct lua_State *L, struct tuple *tuple)
diff --git a/test/box/tuple.result b/test/box/tuple.result
index 16aa66b1a..82ad8404d 100644
--- a/test/box/tuple.result
+++ b/test/box/tuple.result
@@ -1069,13 +1069,13 @@ format = {}
 format[1] = {name = 'aaa', type = 'unsigned'}
 ---
 ...
-format[2] = {name = 'bbb', type = 'unsigned'}
+format[2] = {name = 'bbb', type = 'unsigned', is_nullable = true}
 ---
 ...
-format[3] = {name = 'ccc', type = 'unsigned'}
+format[3] = {name = 'ccc', type = 'unsigned', is_nullable = true}
 ---
 ...
-format[4] = {name = 'ddd', type = 'unsigned'}
+format[4] = {name = 'ddd', type = 'unsigned', is_nullable = true}
 ---
 ...
 s = box.schema.create_space('test', {format = format})
@@ -1100,7 +1100,7 @@ s:frommap()
 ...
 s:frommap({})
 ---
-- []
+- error: Tuple field 1 required by space format is missing
 ...
 s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true})
 ---
@@ -1211,6 +1211,23 @@ s2:frommap({a="1", k="11"})
 ---
 - ['1', null, null, null, null, null, null, null, null, null, '11']
 ...
+--
+-- gh-4045: space:frommap():tomap() conversion fail
+--
+s2:frommap({a="1", k="11"}):tomap({names_only = true})
+---
+- i: null
+  f: null
+  c: null
+  g: null
+  b: null
+  j: null
+  k: '11'
+  d: null
+  h: null
+  a: '1'
+  e: null
+...
 s2:drop()
 ---
 ...
diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
index 0c89feace..8030b0884 100644
--- a/test/box/tuple.test.lua
+++ b/test/box/tuple.test.lua
@@ -354,9 +354,9 @@ box.tuple.bsize == t.bsize
 --
 format = {}
 format[1] = {name = 'aaa', type = 'unsigned'}
-format[2] = {name = 'bbb', type = 'unsigned'}
-format[3] = {name = 'ccc', type = 'unsigned'}
-format[4] = {name = 'ddd', type = 'unsigned'}
+format[2] = {name = 'bbb', type = 'unsigned', is_nullable = true}
+format[3] = {name = 'ccc', type = 'unsigned', is_nullable = true}
+format[4] = {name = 'ddd', type = 'unsigned', is_nullable = true}
 s = box.schema.create_space('test', {format = format})
 s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4})
 s:frommap({ddd = 1, aaa = 2, bbb = 3})
@@ -409,4 +409,10 @@ s2:format({{name="a", type="str"}, {name="b", type="str", is_nullable=true},
            {name="k", type="str", is_nullable=true}});
 test_run:cmd("setopt delimiter ''");
 s2:frommap({a="1", k="11"})
+
+--
+-- gh-4045: space:frommap():tomap() conversion fail
+--
+s2:frommap({a="1", k="11"}):tomap({names_only = true})
+
 s2:drop()
-- 
2.21.0

             reply	other threads:[~2019-03-20 13:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 13:31 Kirill Shcherbatov [this message]
2019-03-21 13:36 ` [tarantool-patches] " Vladislav Shpilevoy
2019-03-21 15:41 ` Kirill Yukhin

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=558c48af114ba67b997489ce2a150ffa1b7f5a22.1553088664.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v1 1/1] box: fix format of tuple produced with frommap()' \
    /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