From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id E1E8C6EC58; Sat, 26 Jun 2021 00:26:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E1E8C6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1624656387; bh=1pX7d6GPbuJNmdEwu4GtpBNBAIGJJnr+ai8iHNvo+WQ=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=erwvUPTqKHuJTnO6BMEidSJvfMTUcWMphMC7qCReiwlBxNctyfjOXy7Pwwe/4IfJ3 BHEKswNkDqQ3t6uXM3pHkuJWSMTF+Z0XlI0QioN29uPUoCiltHAgN2Z8/dqcyZAvNO zuBQS6w53LyXznH3yEv4ROccVorSX6bk5kGITqzY= Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 09D116EC58 for ; Sat, 26 Jun 2021 00:26:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 09D116EC58 Received: by smtp29.i.mail.ru with esmtpa (envelope-from ) id 1lwtLC-0003Yq-22; Sat, 26 Jun 2021 00:26:22 +0300 To: "'Mergen Imeev'" Cc: References: <39ac18a73adc891f9ec615491c512b1a32237ed8.1623396615.git.tsafin@tarantool.org> <3e0a06c9-5ac4-fe91-8125-f216bc0b9085@tarantool.org> In-Reply-To: <3e0a06c9-5ac4-fe91-8125-f216bc0b9085@tarantool.org> Date: Sat, 26 Jun 2021 00:26:19 +0300 Message-ID: <13db01d76a08$bdeff020$39cfd060$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQH9YP+QCEY6e5VusJ0O6Ha7mUcGiQGPNGQgAQmg0A2qw86ucA== Content-Language: ru X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB96E19CC2B9345E2B1F8975EC27617E56182A05F53808504009C80C81FCA41512A0C8A7D1E56A2F533BCD7B0E09BBB16A4729123224421E33 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FDE19FEC90BA7BD7C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7066EEFE7DFC84324EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BD6CF32B5F8F9D404C949F5C64251902646075FE71BF419F2CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CC824672CB62AFFF2BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6E2CC40B64C206E6E76E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C468D16C903838CAB43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD64DA1745F4731B30A08CF520A74D2A4A X-C1DE0DAB: 0D63561A33F958A5E1674BD51E1C6795B1125A4264DC214BACB80E058A2664D1D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA755279A685C79E1982410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345DE7771146E56B08C5F7454A39298BC6822B6B8CC4CB6141226EE919D015D68753769194691D99341D7E09C32AA3244C2DD95D115F84EBDE98A87C08AD9975FC97FE24653F78E668729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojQMwavxIrnHbw2txTL9icIQ== X-Mailru-Sender: B5B6A6EBBD94DAD837E14476885DCAD6FAB2D8A05B5841A596C770947F3C663FE67F7FD98C08084C1EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 2/3] sql: updated explicit conversion table X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" : From: Mergen Imeev : Subject: Re: [PATCH v2 2/3] sql: updated explicit conversion table :=20 : Thank you for the fixes you did. See my 27 comments below. :=20 : 1. In general I do not think that it is good idea to squash all = previous : three : patches to one patch. I think that the first of previous patches was : quite good, : the second was useless and the third had some issues, but now all = these : patches : are squashed. The idea was to split modification to implicit and explicit changes.=20 And taking into account that changes in behavior should be at the same=20 commit with modified tests those patches grew a bit. If we split=20 code and test then commits are not passing build/test separately. :=20 : On Fri, Jun 11, 2021 at 10:48:12AM +0300, Timur Safin wrote: : > * fixes for `BOOLEAN` expressions in explicit converstion tables : > : > We need to modify explicit casts table according to the RFC = developed : > previously in /doc/rfc/5910-consistent-sql-lua-types.md. This patch : > introduces changes where BOOLEAN type involved, thus, for simplicity : > sake, we mark unchanged cells in the table below as '.' : 2. I still do not think that path to RFC is needed here.=20 It's matter of taste. : Also, what about '.'? They mark unchanged cell entries (as I said). Or I've not understood = your clearly.=20 : > * introduce `ANY` as target for explicit conversions : > : > For consistency sake it was decided to provide : > `CAST(anything TO ANY)` as allowed, but still noop. : > : 3. I still do not like that you added cast to unsupported field. That was part of RFC we all agreed upon, not my own invention. :=20 : 4. Why typeof() of value cast to any returns 'any'? : tarantool> box.execute('select typeof(cast(1 AS any));') : --- : - metadata: : - name: COLUMN_1 : type: string : rows: : - ['any'] : ... :=20 : tarantool> box.execute('select typeof(cast(1 AS scalar));') : --- : - metadata: : - name: COLUMN_1 : type: string : rows: : - ['integer'] : ... Good observation, thanks! `cast(1 as scalar)` should return expression=20 attributed as `scalar` also. (Because why this cast then? Values should be left untouched, only type of expression reattributed. :=20 : > * We had to rename %wildcard token to ANYTHING, since we needed : > token ANY for real life usage. : > : 5. Just a thought - why you cannot use 'ANYTHING' for field type ANY? : Or 'ANY_KW', how it was already done for INTEGER? As %wildcard token we should use separate lexem, not actually used. :=20 : > * As a byproduct, we fixed #6010 to make cast to unsigned behaving : reasonably : > : 6. I think this change is good enough to have its own patch. It's still part of implicit casts fixes, and affect some(same) set of = tests. [i.e. those tests will be modified multiple times along a patches flow = in The same patchset] But yes, in this case there was separate ticket, withc specific = test-case, Thus it's easy to extract. :=20 : > * To make sure that all consistency checks are systematic, we have : introduced : > special test for checking conversion rules - e_casts.test.lua. = This : > patch introduces explicit table part: : > : > * e_casts.test.lua is generating expressions of `CAST(input AS = output)` : > form. All combinations check whether we expectedly succeeded or : failed, : > given the explicit conversion table from RFC = 5910-consistent-sql-lua- : types.md; : > : > * At the moment we skip DECIMALs, ARRAYs and MAPs as not yet : > fully supported. Need to be revisited later; : > : > * NB! there is `-verbose` mode one may activate to enable more = detailed : > reporting during debugging. : > : 7. I used './test-run.py sql-tap/e_casts.test.lua --verbose -j1' and = saw : this: : [001] sql-tap/e_casts.test.lua memtx [001] TAP : version 13 : [001] 1..3 : [001] # e_casts - check consistency of implicit conversion table : [001] 1..169 : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [any,any] nil ~=3D nil ... : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,number] 2 ~=3D 1 : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,decimal] nil ~=3D nil : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,uuid] nil ~=3D nil : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,array] nil ~=3D nil : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,map] nil ~=3D nil : [001] ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245 : [unsigned,scalar] 2 ~=3D 1 : ... :=20 : What is it? Have you looked into code of this test? In this subtest we check that implicit conversion table is symmetric in their cells (i.e. if there is any sort of conversion from type A to B then there have to be some kind sort of conversion reverse conversion from type B to A) Agreed though, that 2 !=3D 1, and especially nil ~=3D nil, look = confusing without looking into sources, and will provide more human-readable output there. :=20 : > Relates to #5910, #6009 : > Part of #4470 : > Fixes #6010 : > : > +int : > +mem_to_uint(struct Mem *mem) : > +{ : > + assert(mem->type < MEM_TYPE_INVALID); : > + if (mem->type =3D=3D MEM_TYPE_UINT) : > + return 0; : > + if (mem->type =3D=3D MEM_TYPE_INT) { : > + mem_set_uint(mem, (uint64_t)mem->u.i); : 8. Could you explain to me, what it this? Since when -1 can be cast to : UNSIGNED? This is rather usual reinterpret_cast<> for conversion of=20 negative signed integer to unsigned.=20 : Where it is described? Why this is allowed? : tarantool> box.execute('select CAST(-1 as unsigned);') : --- : - metadata: : - name: COLUMN_1 : type: unsigned : rows: : - [18446744073709551615] : ... Now looking into RFC table for explicit casts I do see it's slightly extension of an agreed upon "conditional" conversion (i.e. if signed integer has positive value then it should be Convertible, and raise error otherwise).=20 So yes, thanks for catch! :=20 :=20 : > + return 0; : > + } : > + if ((mem->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) !=3D 0) : > + return bytes_to_uint(mem); : > + if (mem->type =3D=3D MEM_TYPE_DOUBLE) : > + return double_to_uint(mem); : > + return -1; : > +} : > + : > int : > mem_to_int(struct Mem *mem) : > { : > assert(mem->type < MEM_TYPE_INVALID); : > - if ((mem->type & (MEM_TYPE_INT | MEM_TYPE_UINT)) !=3D 0) : > + if (mem->type =3D=3D MEM_TYPE_INT) : > + return 0; : > + if (mem->type =3D=3D MEM_TYPE_UINT) { : > + mem_set_int(mem, (int64_t)mem->u.u, false); : 9. So, you want to set unsigned value as integer. Could you tell me = what : does : this change do? At least it will change type attribution (that's important Because of different allowed ranges of values). : > @@ -1017,13 +989,8 @@ mem_cast_explicit(struct Mem *mem, enum = field_type : type) : > switch (mem->type) { : 10. Just a thought. I see no harm to have this switch here, but it has : only two : options. Why not change it to 'if'? Wanted to say that I kept switch to look consistent with code above and=20 below, but then realized that more complicated code with switch cases has already been refactored to functions and this switch left alone,=20 and only if left around it.=20 Yep, will switch switch to if. That would look better. ... : > diff --git a/test/sql-tap/e_casts.test.lua = b/test/sql-tap/e_casts.test.lua : > new file mode 100755 : > index 000000000..32d7e8e0c : > --- /dev/null : > +++ b/test/sql-tap/e_casts.test.lua : > @@ -0,0 +1,340 @@ : > +#!/usr/bin/env tarantool : > +local tap =3D require("tap") : > +local test =3D tap.test("errno") : > + : > +test:plan(1) : > + : > +local yaml =3D require("yaml") : > +local ffi =3D require("ffi") : > + : > +local verbose =3D 0 : > + : > +if arg[1] =3D=3D '-v' or arg[1] =3D=3D '--verbose' then : > + verbose =3D 1 : > +end : > + : > +ffi.cdef [[ : > + enum field_type { : > + FIELD_TYPE_ANY =3D 0, : > + FIELD_TYPE_UNSIGNED, : > + FIELD_TYPE_STRING, : > + FIELD_TYPE_NUMBER, : > + FIELD_TYPE_DOUBLE, : > + FIELD_TYPE_INTEGER, : > + FIELD_TYPE_BOOLEAN, : > + FIELD_TYPE_VARBINARY, : > + FIELD_TYPE_SCALAR, : > + FIELD_TYPE_DECIMAL, : > + FIELD_TYPE_UUID, : > + FIELD_TYPE_ARRAY, : > + FIELD_TYPE_MAP, : > + field_type_MAX : > + }; : > +]] : 11. Since this cdef is only copy-paste from current actual enum, I = still see : not reason to keep it here. Or you could use one from module.h, if you = want : to keep it. Nope, we could not use module.h - it's been built much, much later in = the current build flow. Module_api and testing are currently independent = targets. and this unnecessary dependency looks redundant, copy-pastes are bad, = but sometimes they are excusable to avoid introduction of unnecessary = troubles (in already quite fragile build process) : > + : > +-- not all types implemented/enabled at the moment : > +-- but we do keep their projected status in the : > +-- spec table : > +local enabled_type =3D { : > + [t_any] =3D false, -- there is no way in SQL to = instantiate ANY : type expression : > + [t_unsigned] =3D true, : > + [t_string] =3D true, : > + [t_double] =3D true, : > + [t_integer] =3D true, : > + [t_boolean] =3D true, : > + [t_varbinary] =3D true, : > + [t_number] =3D true, : > + [t_decimal] =3D false, : > + [t_uuid] =3D true, : > + -- [t_date] =3D false, : > + -- [t_time] =3D false, : > + -- [t_timestamp]=3D false, : > + -- [t_interval] =3D False, : > + [t_array] =3D false, : > + [t_map] =3D false, : > + [t_scalar] =3D true, : > +} : > + : > +-- Enabled types which may be targets for explicit casts : > +local enabled_type_cast =3D table.deepcopy(enabled_type) : > +enabled_type_cast[t_any] =3D true : > + : > +-- table of _TSV_ (tab separated values) : > +-- copied from sql-lua-tables-v5.xls : > +local explicit_casts_table_spec =3D { : > + [t_any] =3D {"Y", "S", "Y", "S", "S", "S", "S", "S", "S", = "S", "S", : "S", "S"}, : > + [t_unsigned]=3D {"Y", "Y", "Y", "Y", "Y", "" , "" , "Y", "Y", = "" , "" , : "" , "Y"}, : > + [t_string] =3D {"Y", "S", "Y", "S", "S", "S", "Y", "S", "S", = "S", "S", : "S", "Y"}, : > + [t_double] =3D {"Y", "S", "Y", "Y", "S", "" , "" , "Y", "Y", = "" , "" , : "" , "Y"}, : > + [t_integer] =3D {"Y", "S", "Y", "Y", "Y", "" , "" , "Y", "Y", = "" , "" , : "" , "Y"}, : > + [t_boolean] =3D {"Y", "" , "Y", "" , "" , "Y", "" , "" , "" , = "" , "" , : "" , "Y"}, : > + [t_varbinary]=3D{"Y", "" , "Y", "N", "" , "" , "Y", "" , "" , = "S", "" , : "" , "Y"}, : > + [t_number] =3D {"Y", "S", "Y", "Y", "S", "" , "" , "Y", "Y", = "" , "" , : "" , "Y"}, : > + [t_decimal] =3D {"Y", "S", "Y", "S", "S", "" , "" , "Y", "Y", = "" , "" , : "" , "Y"}, : > + [t_uuid] =3D {"Y", "" , "Y", "" , "" , "" , "Y", "" , "" , = "Y", "" , : "" , "Y"}, : > + [t_array] =3D {"Y", "N", "Y", "N", "N", "N", "" , "" , "" , = "" , "Y", : "" , "N"}, : > + [t_map] =3D {"Y", "N", "Y", "N", "N", "N", "" , "" , "" , = "" , "" , : "Y", "N"}, : > + [t_scalar] =3D {"Y", "S", "Y", "S", "S", "S", "S", "S", "S", = "S", "" , : "" , "Y"}, : > +} : 12. Again, why there is 'N' and '' both in table? Could you show me = where in : RFC we have this table that contains both '' and 'N'? This is also explained with - because of RFC! ;) Kinda. In this case = that's the way it looked in frozen materials (excel) used for RFC generation which I've = published=20 as attachments to = https://github.com/tarantool/tarantool/wiki/SQL-Lua-Consistent-Type-Speci= fication wiki page. OTOH ' ' and 'N' are equivalent, and could be easily massaged = in the editor so to make it look less confusing for others I'll change them to always = be ' '. ... : > + : > + for _, from in ipairs(proper_order) do : > + local line =3D '' : > + for _, to in ipairs(proper_order) do : > + line =3D line .. string.format("%2s |", : human_cast(table[from][to])) : > + end : > + line =3D string.sub(line, 1, #line-1) : > + local s =3D string.format("%2d.%10s |%s|", from, = type_names[from], : line) : > + print(s) : > + end : > + print(string.format("%"..max_len.."s%s", "", banner)) : > +end : 13. Since you use '-verbose' mode only in your debug, can you move = these : functions out from here? I still do not see any use of this code. Out from here to where? I do print implicit and explicit tables content if ran with '--verbose' option. And this is great debugging helper while you modify those tables. Have you ever run this test outside of test-run infrastructure? Like=20 ``` =E2=9C=94 ~/tarantool/test 18:57 $ cat ~/bin/sql-tap-run.sh=20 #/usr/bin/bash root=3D$(git rev-parse --show-toplevel) rm -f *.snap *.xlog LUA_PATH=3D"$root/test/sql-tap/lua/?.lua;$root/test/sql/lua/?.lua;" \ $prefix $root/build/src/tarantool $* =E2=9C=94 ~/tarantool/test 18:57 $ ~/bin/sql-tap-run.sh sql-tap/e_casts.test.lua --verbose |& head = -40 TAP version 13 1..3 | 0 | 1 | 2 | 4 | 5 | 6 | 7 | 3 | 9 |10 |11 |12 | 8 | +---+---+---+---+---+---+---+---+---+---+---+---+---+ 0. any | | | | | | | | | | | | | | 1. unsigned | Y | Y | Y | Y | Y | | | Y | | | | | Y | 2. string | Y | S | Y | S | S | S | Y | S | | S | | | Y | 4. double | Y | S | Y | Y | S | | | Y | | | | | Y | 5. integer | Y | S | Y | Y | Y | | | Y | | | | | Y | 6. boolean | Y | | Y | | | Y | | | | | | | Y | 7. varbinary | Y | | Y | | | | Y | | | S | | | Y | 3. number | Y | S | Y | Y | S | | | Y | | | | | Y | 9. decimal | | | | | | | | | | | | | | 10. uuid | Y | | Y | | | | Y | | | Y | | | Y | 11. array | | | | | | | | | | | | | | 12. map | | | | | | | | | | | | | | 8. scalar | Y | S | Y | S | S | S | S | S | | S | | | Y | +---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | 2 | 4 | 5 | 6 | 7 | 3 | 9 |10 |11 |12 | 8 | +---+---+---+---+---+---+---+---+---+---+---+---+---+ 0. any | | | | | | | | | | | | | | 1. unsigned | | Y | Y | Y | Y | | | Y | | | | | Y | 2. string | | S | Y | S | S | | Y | S | | S | | | Y | 4. double | | S | Y | Y | S | | | Y | | | | | Y | 5. integer | | S | Y | Y | Y | | | Y | | | | | Y | 6. boolean | | | | | | Y | | | | | | | Y | 7. varbinary | | | Y | | | | Y | | | S | | | Y | 3. number | | S | Y | Y | S | | | Y | | | | | Y | 9. decimal | | | | | | | | | | | | | | 10. uuid | | | Y | | | | Y | | | Y | | | Y | 11. array | | | | | | | | | | | | | | 12. map | | | | | | | | | | | | | | 8. scalar | | S | S | S | S | S | S | S | | S | | | S | +---+---+---+---+---+---+---+---+---+---+---+---+---+ # e_casts - check consistency of implicit conversion table 1..169 ok - sql-tap/e_casts.test.lua:245 [any,any] nil ~=3D nil ok - sql-tap/e_casts.test.lua:245 [any,unsigned] nil ~=3D nil ok - sql-tap/e_casts.test.lua:245 [any,string] nil ~=3D nil ok - sql-tap/e_casts.test.lua:245 [any,double] nil ~=3D nil ``` Ain't them pretty? ;) : > + : > +local gen_type_samples =3D { : > + [t_unsigned] =3D {"0", "1", "2"}, : 14. I believe you once said something about testing values that are = close to : all limits of numeric types. Why I cannot see them here? This is very good point - I'll add some boundary values. : > +local function catch_query(query) : > + local result =3D {pcall(box.execute, query)} : > + : > + if not result[1] or result[3] ~=3D nil then : > + return false, result[3] : > + end : > + return true, result[2] : > +end : 15. Since you use all these functions and do not want to remove them, = I : suggest : to add comments to them. Yeah, these are much easier to use than those we have in sqltester.lua.=20 Will provide some comments. :=20 : > + : > +-- 1. Check explicit casts table : > +local function test_check_explicit_casts(test) : > + -- checking validity of all `CAST(from AS to)` combinations : > + test:plan(322) : > + for _, from in ipairs(proper_order) do : > + for _, to in ipairs(proper_order) do : > + -- skip ANY, DECIMAL, UUID, etc. : 16. Why UUID is skipped? Also, why ANY is skipped?=20 No, in this test we do not skip uuids, they already been integrated into test. That's rather stale/outdated comment. : You can get values of type : ANY by using CAST(values AS ANY), I believe. Or I am wrong? Yes and no. Given expression of a form `CAST(x as ANY)` we do have=20 expression attributed with type ANY, but there is still no direct=20 way to write literal of type ANY. Having said that we indeed could use more complicated expressions, not only literals. So yes, we may use such expressions. [But today I'm not actually certain we will not disable these kinds=20 of casts entirely, despite them agreed in the RFC. Along with all possible changes many want to introduce for scalars. So let see=20 where we will go in the nearest future. Sigh. ] :=20 : > + if enabled_type[from] and enabled_type_cast[to] then : > + local gen =3D gen_explicit_cast_from_to(from, to) : > + local failures =3D {} : > + local successes =3D {} : > + local castable =3D false : > + local expected =3D explicit_casts[from][to] : > + : > + if verbose > 0 then : > + print(expected, yaml.encode(gen)) : > + end : > + : > + : > + -- ok, we aggregated stats for c_maybe mode - check = it : now : > + if expected =3D=3D c_maybe then : > + local title =3D string.format("%s =3D> = %s", : > + #gen and : gen[1]..'...' or '', : > + = human_cast(expected)) : > + test:ok(castable, label_for(from, to, = title), : > + failures) : > + end : 16. I already said my expectations about these tests. Since you know : (and print) : all values used in the test, why cannot you determine if the cast = should : fail? : For example, this test is actually useless if `CAST(1.0 AS UNSIGNED)` : fails, since : this cast is marked as 'sometimes'. If you do so, you can just print = 'Y' : or 'N'. : Also, why your tests does not check unallowed casts? Or, at least, = they : are not : shown. It's actually testing entire table (with only exception of unsupported=20 today types). You see the line? local expected =3D explicit_casts[from][to] and then if expected =3D=3D c_yes then test:ok(true =3D=3D ok, label_for(from, to, title)) elseif expected =3D=3D c_no then test:ok(false =3D=3D ok, label_for(from, to, title)) else The problem is in TAP reporting - I did not find any way to have passing test but have expected failures. They all look identical now, all looks=20 castable. Will modify label_for() as promised above to clearly indicate that some expectedly failed. : > --- a/test/sql-tap/in1.test.lua : > +++ b/test/sql-tap/in1.test.lua : > @@ -100,7 +100,7 @@ test:do_execsql_test( : > test:do_execsql_test( : > "in-1.7", : > [[ : > - SELECT a+ 100*CAST((a BETWEEN 1 and 3) AS INTEGER) FROM t1 = ORDER : BY b : > + SELECT a+ 100*(CASE WHEN (a BETWEEN 1 and 3) THEN 1 ELSE 0 = END) : FROM t1 ORDER BY b : 17. Since you already change this line, add spaces before and after = all : operations with two operands. Hmm, ok :=20 : > ]], { : > -- : > 101, 102, 103, 4, 5, 6, 7, 8, 9, 10 : > @@ -157,7 +157,7 @@ test:do_execsql_test( : > test:do_execsql_test( : > "in-2.5", : > [[ : > - SELECT a+100*(CAST(b IN (8,16,24) AS INTEGER)) FROM t1 = ORDER BY b : > + SELECT a+100*(CASE WHEN b IN (8,16,24) THEN 1 ELSE 0 END) = FROM t1 : ORDER BY b : 18. Same. Ok :=20 : > ]], { : > -- : > 1, 2, 103, 104, 5, 6, 7, 8, 9, 10 : > @@ -207,7 +207,7 @@ test:do_execsql_test( : > test:do_execsql_test( : > "in-2.10", : > [[ : > - SELECT a FROM t1 WHERE LEAST(0, CAST(b IN (a,30) AS INT)) = <> 0 : > + SELECT a FROM t1 WHERE LEAST(0, CASE WHEN (b IN (a,30)) = THEN 1 : ELSE 0 END) <> 0 : 19. I think a space should be after ',' in '(a,30)'. Ok : > diff --git a/test/sql-tap/in4.test.lua b/test/sql-tap/in4.test.lua : > index 8442944b9..588daefec 100755 : > --- a/test/sql-tap/in4.test.lua : > +++ b/test/sql-tap/in4.test.lua : > @@ -133,7 +133,7 @@ test:do_execsql_test( : > SELECT b FROM t2 WHERE a IN (1.0, 2.1) : > ]], { : > -- : > - "one" : > + "one", "two" : 21. Why the result changed? Good question! You see I've added case when implicit cast from double to = integer worked expectedly and brought us 2 rows, but here, by some = reason=20 implicit cast from 2.1 didn't match integer 2. I need to investigate reasons, at the moment I do not recollect why it was ok for me. :=20 : > -- : > }) : > : > diff --git a/test/sql-tap/misc3.test.lua = b/test/sql-tap/misc3.test.lua : > index 313484b5d..c2dc67355 100755 : > --- a/test/sql-tap/misc3.test.lua : > +++ b/test/sql-tap/misc3.test.lua : > @@ -510,7 +510,7 @@ test:do_execsql_test( : > test:do_execsql_test( : > "misc-8.2", : > [[ : > - SELECT count(*) FROM t3 WHERE 1+CAST((b IN ('abc','xyz')) = AS : INTEGER)=3D=3D2 : > + SELECT count(*) FROM t3 WHERE b IN ('abc','xyz') : 22. What does this test checks now and what it checked before? That was regression test for SQLite bug #668 ``` -- Ticket #668: VDBE stack overflow occurs when the left-hand side -- of an IN expression is NULL and the result is used as an integer, = not -- as a jump. ``` :=20 : > ]], { : > -- : > 2 : > diff --git a/test/sql/boolean.result b/test/sql/boolean.result : > index 177a39fb9..b268eb2fe 100644 : > --- a/test/sql/boolean.result : > +++ b/test/sql/boolean.result : > @@ -502,23 +502,13 @@ INSERT INTO t3 VALUES (4, false) : > -- Check CAST from BOOLEAN to the other types. : > SELECT cast(true AS INTEGER), cast(false AS INTEGER); : > | --- : > - | - metadata: : > - | - name: COLUMN_1 : > - | type: integer : > - | - name: COLUMN_2 : > - | type: integer : > - | rows: : > - | - [1, 0] : > + | - null : > + | - 'Type mismatch: can not convert TRUE to integer' : 23. Since all these CAST are now fails, I think it is better to divide = this : query into three. Otherwise only the first cast is checked. :=20 : > | ... : > SELECT cast(true AS NUMBER), cast(false AS NUMBER); : > | --- : > - | - metadata: : > - | - name: COLUMN_1 : > - | type: number : > - | - name: COLUMN_2 : > - | type: number : > - | rows: : > - | - [1, 0] : > + | - null : > + | - 'Type mismatch: can not convert TRUE to number' : 24. Same. :=20 : > | ... : > -- gh-4462: ensure that text representation is uppercase. : > SELECT cast(true AS TEXT), cast(false AS TEXT); : > @@ -545,25 +535,13 @@ SELECT cast(true AS BOOLEAN), cast(false AS : BOOLEAN); : > -- Check CAST to BOOLEAN from the other types. : > SELECT cast(100 AS BOOLEAN), cast(1 AS BOOLEAN), cast(0 AS = BOOLEAN); : > | --- : > - | - metadata: : > - | - name: COLUMN_1 : > - | type: boolean : > - | - name: COLUMN_2 : > - | type: boolean : > - | - name: COLUMN_3 : > - | type: boolean : > - | rows: : > - | - [true, true, false] : > + | - null : > + | - 'Type mismatch: can not convert 100 to boolean' : > | ... : 25. Same. :=20 : > SELECT cast(0.123 AS BOOLEAN), cast(0.0 AS BOOLEAN); : > | --- : > - | - metadata: : > - | - name: COLUMN_1 : > - | type: boolean : > - | - name: COLUMN_2 : > - | type: boolean : > - | rows: : > - | - [true, false] : > + | - null : > + | - 'Type mismatch: can not convert 0.123 to boolean' : > | ... : 26. Same. :=20 : > SELECT cast('true' AS BOOLEAN), cast('false' AS BOOLEAN); : > | --- : > diff --git a/test/sql/types.result b/test/sql/types.result : > index 687ca3b15..90a8bc5ec 100644 : > --- a/test/sql/types.result : > +++ b/test/sql/types.result : > @@ -1035,11 +1035,8 @@ box.execute("SELECT CAST(18446744073709551615 = AS : SCALAR);") : > ... : > box.execute("SELECT CAST(18446744073709551615 AS BOOLEAN);") : > --- : > -- metadata: : > - - name: COLUMN_1 : > - type: boolean : > - rows: : > - - [true] : > +- null : > +- 'Type mismatch: can not convert 18446744073709551615 to boolean' : > ... : > box.execute("SELECT CAST('18446744073709551615' AS INTEGER);") : > --- : > @@ -1084,8 +1081,11 @@ box.execute("SELECT CAST(123 AS UNSIGNED);") : > ... : > box.execute("SELECT CAST(-123 AS UNSIGNED);") : > --- : > -- null : > -- 'Type mismatch: can not convert -123 to unsigned' : > +- metadata: : > + - name: COLUMN_1 : > + type: unsigned : > + rows: : > + - [18446744073709551493] : > ... : 27. Where does such behaviour is described? :=20 : > box.execute("SELECT CAST(1.5 AS UNSIGNED);") : > --- : > @@ -1097,19 +1097,13 @@ box.execute("SELECT CAST(1.5 AS UNSIGNED);") : > ... : > box.execute("SELECT CAST(-1.5 AS UNSIGNED);") : > --- : > -- metadata: : > - - name: COLUMN_1 : > - type: unsigned : > - rows: : > - - [-1] : > +- null : > +- 'Type mismatch: can not convert -1.5 to unsigned' : > ... : > box.execute("SELECT CAST(true AS UNSIGNED);") : > --- : > -- metadata: : > - - name: COLUMN_1 : > - type: unsigned : > - rows: : > - - [1] : > +- null : > +- 'Type mismatch: can not convert TRUE to unsigned' : > ... : > box.execute("SELECT CAST('123' AS UNSIGNED);") : > --- : > -- : > 2.29.2 : >