Tarantool development patches archive
 help / color / mirror / Atom feed
From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: "'Mergen Imeev'" <imeevma@tarantool.org>
Cc: <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v2 2/3] sql: updated explicit conversion table
Date: Mon, 28 Jun 2021 02:46:27 +0300	[thread overview]
Message-ID: <!&!LgAAAAAAAACLoiZZUjW4TqEcPVFFu50TAQDDto4Q93URzrTNAKoAu7bmAAAAAAAOAABGAAAAAAAAAIuiJllSNbhOoRw9UUW7nRMHAMO2jhD3dRHOtM0AqgC7tuYAAAAAAA4AAEoIgjqI0vZFjeDtqD6wCkYAAAAADtwAAAAAAAAQAAAAzUZTmalrW0Oku6Tq/CZetToAAABSRTogW1BBVENIIHYyIDIvM10gc3FsOiB1cGRhdGVkIGV4cGxpY2l0IGNvbnZlcnNpb24gdGFibGUA@tarantool.org> (raw)
Message-ID: <20210627234627.Iz_ZPSXan7F0sz2_4sG5geodvrxIfG4lESYPce-Pl6k@z> (raw)
In-Reply-To: <3e0a06c9-5ac4-fe91-8125-f216bc0b9085@tarantool.org>


: From: Mergen Imeev <imeevma@tarantool.org>
: Subject: Re: [PATCH v2 2/3] sql: updated explicit conversion table
: 
: Thank you for the fixes you did. See my 27 comments below.
: 
: 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. 
And taking into account that changes in behavior should be at the same 
commit with modified tests those patches grew a bit. If we split 
code and test then commits are not passing build/test separately.

: 
: 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. 

It's matter of taste.

: Also, what about '.'?

They mark unchanged 'Y'/'S' cells (as I said before). Or I've not 
understood your clearly. 

: > * 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.

: 
: 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']
: ...
: 
: 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 
attributed as `scalar` also. (Because why this cast then? Values should
be left untouched, only type of expression reattributed.

: 
: > * 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, artificial lexem, not any 
of actually used.

: 
: > * 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, with specific test-case,
Thus it's easy to extract.

: 
: > * 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 ~= nil
...
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,number] 2 ~= 1
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,decimal] nil ~= nil
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,uuid] nil ~= nil
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,array] nil ~= nil
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,map] nil ~= nil
: [001]     ok - /home/mergen/work/dev/test/sql-tap/e_casts.test.lua:245
: [unsigned,scalar] 2 ~= 1
: ...
: 
: 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 reverse conversion from type B to A)

Agreed though, that 2 != 1, and especially nil ~= nil, look funny and 
Confusing without looking into sources, and I will provide more human-readable
output there.

: 
: > 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 == MEM_TYPE_UINT)
: > +		return 0;
: > +	if (mem->type == 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 
negative signed integer to unsigned. 

: 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, but raise error otherwise). 

So yes, thanks for catch!

: 
: 
: > +		return 0;
: > +	}
: > +	if ((mem->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) != 0)
: > +		return bytes_to_uint(mem);
: > +	if (mem->type == 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)) != 0)
: > +	if (mem->type == MEM_TYPE_INT)
: > +		return 0;
: > +	if (mem->type == 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 
below, but then realized that more complicated code with switch cases
has already been refactored to functions and this switch left alone, 
and only ifs lying around it. 

So, yep, will switch switch to ifs. That would fit better to the context.

...
: > 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 = require("tap")
: > +local test = tap.test("errno")
: > +
: > +test:plan(1)
: > +
: > +local yaml = require("yaml")
: > +local ffi = require("ffi")
: > +
: > +local verbose = 0
: > +
: > +if arg[1] == '-v' or arg[1] == '--verbose' then
: > +    verbose = 1
: > +end
: > +
: > +ffi.cdef [[
: > +    enum field_type {
: > +        FIELD_TYPE_ANY = 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 = {
: > +    [t_any]       = false, -- there is no way in SQL to instantiate ANY
: type expression
: > +    [t_unsigned]  = true,
: > +    [t_string]    = true,
: > +    [t_double]    = true,
: > +    [t_integer]   = true,
: > +    [t_boolean]   = true,
: > +    [t_varbinary] = true,
: > +    [t_number]    = true,
: > +    [t_decimal]   = false,
: > +    [t_uuid]      = true,
: > +    -- [t_date]     = false,
: > +    -- [t_time]     = false,
: > +    -- [t_timestamp]= false,
: > +    -- [t_interval] = False,
: > +    [t_array]     = false,
: > +    [t_map]       = false,
: > +    [t_scalar]    = true,
: > +}
: > +
: > +-- Enabled types which may be targets for explicit casts
: > +local enabled_type_cast = table.deepcopy(enabled_type)
: > +enabled_type_cast[t_any] = true
: > +
: > +-- table of _TSV_ (tab separated values)
: > +-- copied from sql-lua-tables-v5.xls
: > +local explicit_casts_table_spec = {
: > +    [t_any] =     {"Y", "S", "Y", "S", "S", "S", "S", "S", "S", "S", "S",
: "S", "S"},
: > +    [t_unsigned]= {"Y", "Y", "Y", "Y", "Y", "" , "" , "Y", "Y", "" , "" ,
: "" , "Y"},
: > +    [t_string] =  {"Y", "S", "Y", "S", "S", "S", "Y", "S", "S", "S", "S",
: "S", "Y"},
: > +    [t_double] =  {"Y", "S", "Y", "Y", "S", "" , "" , "Y", "Y", "" , "" ,
: "" , "Y"},
: > +    [t_integer] = {"Y", "S", "Y", "Y", "Y", "" , "" , "Y", "Y", "" , "" ,
: "" , "Y"},
: > +    [t_boolean] = {"Y", "" , "Y", "" , "" , "Y", "" , "" , "" , "" , "" ,
: "" , "Y"},
: > +    [t_varbinary]={"Y", "" , "Y", "N", "" , "" , "Y", "" , "" , "S", "" ,
: "" , "Y"},
: > +    [t_number] =  {"Y", "S", "Y", "Y", "S", "" , "" , "Y", "Y", "" , "" ,
: "" , "Y"},
: > +    [t_decimal] = {"Y", "S", "Y", "S", "S", "" , "" , "Y", "Y", "" , "" ,
: "" , "Y"},
: > +    [t_uuid] =    {"Y", "" , "Y", "" , "" , "" , "Y", "" , "" , "Y", "" ,
: "" , "Y"},
: > +    [t_array] =   {"Y", "N", "Y", "N", "N", "N", "" , "" , "" , "" , "Y",
: "" , "N"},
: > +    [t_map] =     {"Y", "N", "Y", "N", "N", "N", "" , "" , "" , "" , "" ,
: "Y", "N"},
: > +    [t_scalar] =  {"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 
as attachments to https://github.com/tarantool/tarantool/wiki/SQL-Lua-Consistent-Type-Specification
wiki page. OTOH ' ' and 'N' are surely interchangeable, and could be easily massaged 
in the editor, so I'll change them to always be ' ' (to make it less confusing for others).

...
: > +
: > +    for _, from in ipairs(proper_order) do
: > +        local line = ''
: > +        for _, to in ipairs(proper_order) do
: > +            line = line .. string.format("%2s |",
: human_cast(table[from][to]))
: > +        end
: > +        line = string.sub(line, 1, #line-1)
: > +        local s = 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 don't get it. 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 
```
✔ ~/tarantool/test
18:57 $ cat ~/bin/sql-tap-run.sh 
#/usr/bin/bash
root=$(git rev-parse --show-toplevel)
rm -f *.snap *.xlog
LUA_PATH="$root/test/sql-tap/lua/?.lua;$root/test/sql/lua/?.lua;" \
        $prefix $root/build/src/tarantool $*

✔ ~/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 ~= nil
    ok - sql-tap/e_casts.test.lua:245 [any,unsigned] nil ~= nil
    ok - sql-tap/e_casts.test.lua:245 [any,string] nil ~= nil
    ok - sql-tap/e_casts.test.lua:245 [any,double] nil ~= nil
```

Ain't them pretty? ;)

: > +
: > +local gen_type_samples = {
: > +        [t_unsigned]  = {"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 = {pcall(box.execute, query)}
: > +
: > +    if not result[1] or result[3] ~= 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. 
Will provide some comments.

: 
: > +
: > +-- 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? 

No, in this test we do not skip uuids, they already been integrated
into test. That's rather stale/outdated comment. Sorry for the confusion.

: 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 
expression attributed with type ANY, but there is still no direct 
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 
 of casts entirely, despite them agreed in the RFC. Along with all
 possible changes many want to introduce for scalars. So let see 
 where we will go in the nearest future. Sigh. ]

: 
: > +            if enabled_type[from] and enabled_type_cast[to] then
: > +                local gen = gen_explicit_cast_from_to(from, to)
: > +                local failures = {}
: > +                local successes = {}
: > +                local castable = false
: > +                local expected = 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 == c_maybe then
: > +                        local title  = string.format("%s => %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 
today types).

You see the line?
                local expected = explicit_casts[from][to]
and then
                if expected == c_yes then
                    test:ok(true == ok, label_for(from, to, title))
                elseif expected == c_no then
                    test:ok(false == ok, label_for(from, to, title))
                else

The problem is in TAP reporting - I did not find any way to have passing
test but displaying a number of expected failures. They all look identical 
now (as passes), and all looks as castable, even if they are not.

Will modify label_for() as promised above to clearly indicate that
some of them expected to fail.

: > --- 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

: 
: >      ]], {
: >          -- <in-1.7>
: >          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

: 
: >      ]], {
: >          -- <in-2.5>
: >          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)
: >      ]], {
: >          -- <in4-2.6>
: > -        "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 
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.

: 
: >          -- </in4-2.6>
: >      })
: >
: > 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)==2
: > +        SELECT count(*) FROM t3 WHERE b IN ('abc','xyz')

: 22. What does this test checks now and what it checked before?

That was actually a 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.
```

It makes no sense today for our conditions, and I believe it should 
be kept here just for not reducing coverage. [Though I'd delete 
subtests for #668 if we would care about logical system in our tests. :)]

: > 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.

Into 3? Have you actually meant 2 in this case?

: 
: >   | ...
: >  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.

The same confusion - we will receive 2 separate test, why 3?

: > @@ -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.

Division of this select into 3 separate selects makes no sense at all - 
they will receive the same result for the same condition, the only 
reasonable case now would be:

```
- SELECT cast(100 AS BOOLEAN), cast(1 AS BOOLEAN), cast(0 AS BOOLEAN);
+ SELECT cast(100 AS BOOLEAN);
```

: 
: >  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.

Similarly - only 1 expression is necessary

: > 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
: > @@ -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?

Ok, as a said above such reinterpret_cast<> was rather an extension
of RFC, and will return back conditional failure.

Thanks,
Timur


  parent reply	other threads:[~2021-06-27 23:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  7:48 [Tarantool-patches] [PATCH v2 0/3] sql: modify explicit and implicit conversion tables Timur Safin via Tarantool-patches
2021-06-11  7:48 ` [Tarantool-patches] [PATCH v2 1/3] test: corrected reported error lines Timur Safin via Tarantool-patches
2021-06-20 18:57   ` Igor Munkin via Tarantool-patches
2021-06-23 21:01     ` Alexander Turenko via Tarantool-patches
2021-06-27 23:16     ` Timur Safin via Tarantool-patches
2021-06-29 16:21       ` Igor Munkin via Tarantool-patches
2021-06-30  6:49         ` Timur Safin via Tarantool-patches
2021-07-21  7:24           ` Igor Munkin via Tarantool-patches
2021-06-11  7:48 ` [Tarantool-patches] [PATCH v2 2/3] sql: updated explicit conversion table Timur Safin via Tarantool-patches
2021-06-20 18:52   ` Mergen Imeev via Tarantool-patches
2021-06-25 21:26     ` Timur Safin via Tarantool-patches
2021-06-25 21:26     ` Timur Safin via Tarantool-patches [this message]
2021-06-27 23:46       ` Timur Safin via Tarantool-patches
2021-06-11  7:48 ` [Tarantool-patches] [PATCH v2 3/3] sql: updated implicit " Timur Safin via Tarantool-patches
2021-06-20 18:52   ` Mergen Imeev via Tarantool-patches
2021-06-28  0:06     ` Timur Safin via Tarantool-patches
2021-06-20 18:52 ` [Tarantool-patches] [PATCH v2 0/3] sql: modify explicit and implicit conversion tables Mergen Imeev via Tarantool-patches
2021-06-27 23:29   ` Timur Safin via Tarantool-patches

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=''\!'&'\!'LgAAAAAAAACLoiZZUjW4TqEcPVFFu50TAQDDto4Q93URzrTNAKoAu7bmAAAAAAAOAABGAAAAAAAAAIuiJllSNbhOoRw9UUW7nRMHAMO2jhD3dRHOtM0AqgC7tuYAAAAAAA4AAEoIgjqI0vZFjeDtqD6wCkYAAAAADtwAAAAAAAAQAAAAzUZTmalrW0Oku6Tq/CZetToAAABSRTogW1BBVENIIHYyIDIvM10gc3FsOiB1cGRhdGVkIGV4cGxpY2l0IGNvbnZlcnNpb24gdGFibGUA@tarantool.org' \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/3] sql: updated explicit conversion table' \
    /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