From: Oleg Babin <olegrok@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, lvasiliev@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua Date: Sat, 21 Nov 2020 22:07:42 +0300 [thread overview] Message-ID: <52439555-a382-189e-941a-22aa4b0e2683@tarantool.org> (raw) In-Reply-To: <caa0f815-c076-ab7a-9419-d41c00638afa@tarantool.org> Thanks for your comments. I've force-pushed fixes to my branch (https://github.com/tarantool/tarantool/tree/olegrok/5511-uuid-cmp-v2). See my answers below. On 21/11/2020 18:17, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > See 3 comments below. > > On 18.11.2020 08:56,olegrok@tarantool.org wrote: >> From: Oleg Babin<babinoleg@mail.ru> >> >> Since Tarantool has uuid data type sometimes we want to compare >> uuid vaues as it's possible for primitive types and decimals. This > 1. vaues -> values. Thanks! Fixed. Consider a new commit message. I moved docbot request to the next patch. ``` uuid: support comparison of uuid values in Lua Since Tarantool has uuid data type sometimes we want to compare uuid values as it's possible for primitive types and decimals. This patch exports function for uuid comparison and implements le and lt metamethods for uuid type. Closes #5511 ``` >> patch exports function for uuid comparison and implements le and >> lt metamethods for uuid type. >> >> Closes #5511 >> >> @TarantoolBot document >> Title: uuid comparison is supported >> >> Currently comparison between uuid values is supported. >> Example: >> ```lua >> u1 = uuid.fromstr('aaaaaaaa-aaaa-4000-b000-000000000001') >> u2 = uuid.fromstr('bbbbbbbb-bbbb-4000-b000-000000000001') >> >> u1 > u2 -- false >> u1 >= u2 -- false >> u1 <= u2 -- true >> u1 < u2 -- true >> ``` >> --- >> Issue:https://github.com/tarantool/tarantool/issues/5511 >> Branch:https://github.com/tarantool/tarantool/tree/olegrok/5511-uuid-cmp-v2 >> >> src/exports.h | 1 + >> src/lua/uuid.lua | 25 +++++++++++++ >> test/app/uuid.result | 79 ++++++++++++++++++++++++++++++++++++++++++ >> test/app/uuid.test.lua | 29 ++++++++++++++++ >> 4 files changed, 134 insertions(+) >> >> diff --git a/src/exports.h b/src/exports.h >> index 867a027dc..ffbb84e3b 100644 >> --- a/src/exports.h >> +++ b/src/exports.h >> @@ -508,6 +508,7 @@ EXPORT(tnt_iconv_close) >> EXPORT(tnt_iconv_open) >> EXPORT(tt_uuid_bswap) >> EXPORT(tt_uuid_create) >> +EXPORT(tt_uuid_compare) > 2. Please, keep the lines sorted, as it is asked in the > first lines of this file. 'r' > 'o', so tt_uuid_compare > should be before tt_uuid_create. My bad. Fixed. >> EXPORT(tt_uuid_from_string) >> EXPORT(tt_uuid_is_equal) >> EXPORT(tt_uuid_is_nil) >> diff --git a/src/lua/uuid.lua b/src/lua/uuid.lua >> index 42016601d..08991cfeb 100644 >> --- a/src/lua/uuid.lua >> +++ b/src/lua/uuid.lua >> @@ -118,9 +120,32 @@ local uuid_new_str = function() >> return uuid_tostring(uuidbuf) >> end >> >> +local check_uuid = function(value, index) >> + if is_uuid(value) then >> + return value >> + end >> + >> + local err_fmt = 'incorrect value to compare with uuid as %d argument' >> + error(err_fmt:format(index), 0) > 3. Why did you use 0? You loose the error location then. > I changed it to 4, and got more informative messages, showing > the error location: > > [001] 'abc' <= u1 > [001] --- > [001] -- error: incorrect value to compare with uuid as 1 argument > [001] +- error: '[string "return ''abc'' <= u1 "]:1: incorrect value to compare with uuid > [001] + as 1 argument' > > I also noticed just now, that we already have uuid_eq, which looks > different. I think you should unify the comparators, while you are > here. Otherwise eq has its own 'check_uuid', and here you add a second > one. It is inconsistent, even error messages look different. Also you > anyway change it in the next commit, so it should not increase diff > much. Agree. Consider new diff diff --git a/src/exports.h b/src/exports.h index ffbb84e3b..2116036fa 100644 --- a/src/exports.h +++ b/src/exports.h @@ -507,8 +507,8 @@ EXPORT(tnt_iconv) EXPORT(tnt_iconv_close) EXPORT(tnt_iconv_open) EXPORT(tt_uuid_bswap) -EXPORT(tt_uuid_create) EXPORT(tt_uuid_compare) +EXPORT(tt_uuid_create) EXPORT(tt_uuid_from_string) EXPORT(tt_uuid_is_equal) EXPORT(tt_uuid_is_nil) diff --git a/src/lua/uuid.lua b/src/lua/uuid.lua index 08991cfeb..275f4e5c5 100644 --- a/src/lua/uuid.lua +++ b/src/lua/uuid.lua @@ -93,13 +93,20 @@ local uuid_isnil = function(uu) return builtin.tt_uuid_is_nil(uu) end +local check_uuid = function(value, index) + if is_uuid(value) then + return value + end + + local err_fmt = 'incorrect value to compare with uuid as %d argument' + error(err_fmt:format(index), 4) +end + local uuid_eq = function(lhs, rhs) if not is_uuid(rhs) then return false end - if not is_uuid(lhs) then - return error('Usage: uuid == var') - end + lhs = check_uuid(lhs, 1) return builtin.tt_uuid_is_equal(lhs, rhs) end @@ -120,15 +127,6 @@ local uuid_new_str = function() return uuid_tostring(uuidbuf) end -local check_uuid = function(value, index) - if is_uuid(value) then - return value - end - - local err_fmt = 'incorrect value to compare with uuid as %d argument' - error(err_fmt:format(index), 0) -end - local uuid_cmp = function(lhs, rhs) lhs = check_uuid(lhs, 1) rhs = check_uuid(rhs, 2) diff --git a/test/app/uuid.result b/test/app/uuid.result index e06331001..b70cb0e32 100644 --- a/test/app/uuid.result +++ b/test/app/uuid.result @@ -334,35 +334,41 @@ u1 < u2 ... u1 < 1 --- -- error: incorrect value to compare with uuid as 2 argument +- error: '[string "return u1 < 1 "]:1: incorrect value to compare with uuid as 2 argument' ... u1 <= 1 --- -- error: incorrect value to compare with uuid as 2 argument +- error: '[string "return u1 <= 1 "]:1: incorrect value to compare with uuid as 2 + argument' ... u1 < 'abc' --- -- error: incorrect value to compare with uuid as 2 argument +- error: '[string "return u1 < ''abc'' "]:1: incorrect value to compare with uuid + as 2 argument' ... u1 <= 'abc' --- -- error: incorrect value to compare with uuid as 2 argument +- error: '[string "return u1 <= ''abc'' "]:1: incorrect value to compare with uuid + as 2 argument' ... 1 < u1 --- -- error: incorrect value to compare with uuid as 1 argument +- error: '[string "return 1 < u1 "]:1: incorrect value to compare with uuid as 1 argument' ... 1 <= u1 --- -- error: incorrect value to compare with uuid as 1 argument +- error: '[string "return 1 <= u1 "]:1: incorrect value to compare with uuid as 1 + argument' ... 'abc' < u1 --- -- error: incorrect value to compare with uuid as 1 argument +- error: '[string "return ''abc'' < u1 "]:1: incorrect value to compare with uuid + as 1 argument' ... 'abc' <= u1 --- -- error: incorrect value to compare with uuid as 1 argument +- error: '[string "return ''abc'' <= u1 "]:1: incorrect value to compare with uuid + as 1 argument' ... u1 = nil ---
next prev parent reply other threads:[~2020-11-21 19:07 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-18 7:56 [Tarantool-patches] [PATCH v2 0/2] Make uuid values comparable olegrok 2020-11-18 7:56 ` [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua olegrok 2020-11-21 15:17 ` Vladislav Shpilevoy 2020-11-21 19:07 ` Oleg Babin [this message] 2020-11-23 21:58 ` Vladislav Shpilevoy 2020-11-24 5:57 ` Oleg Babin 2020-11-24 13:06 ` Igor Munkin 2020-11-27 15:17 ` Oleg Babin 2020-11-24 15:20 ` Igor Munkin 2020-11-24 19:23 ` Oleg Babin 2020-11-18 7:56 ` [Tarantool-patches] [PATCH v2 2/2] uuid: support uuid comparison with strings olegrok 2020-11-21 15:17 ` Vladislav Shpilevoy 2020-11-21 19:07 ` Oleg Babin 2020-11-24 15:20 ` Igor Munkin 2020-11-24 19:23 ` Oleg Babin 2020-11-18 8:02 ` [Tarantool-patches] [PATCH v2 0/2] Make uuid values comparable Oleg Babin 2020-11-27 22:39 ` Vladislav Shpilevoy 2020-11-27 22:40 ` Vladislav Shpilevoy 2020-12-04 8:13 ` Oleg Babin 2020-12-07 23:04 ` Alexander V. Tikhonov 2020-12-07 23:24 ` Vladislav Shpilevoy
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=52439555-a382-189e-941a-22aa4b0e2683@tarantool.org \ --to=olegrok@tarantool.org \ --cc=lvasiliev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua' \ /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