From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values Date: Tue, 31 Dec 2019 11:47:04 +0300 [thread overview] Message-ID: <b2cf9c7f893a76cada236c0cb87daccbaac92088.1577781940.git.imeevma@gmail.com> (raw) This patch corrects the result of typeof() for double values. Previously, it gave the type "number" in the case of a floating-point number. Now it gives "double". Follow-up #3812 --- https://github.com/tarantool/tarantool/issues/3812 https://github.com/tarantool/tarantool/tree/imeevma/gh-3812-fix-typeof-function src/box/sql/func.c | 2 +- test/sql-tap/cast.test.lua | 12 +++++----- test/sql-tap/check.test.lua | 4 ++-- test/sql-tap/func.test.lua | 4 ++-- test/sql-tap/select3.test.lua | 8 +++---- test/sql/types.result | 51 +++++++++++++++++++++++++++++++++++++++++++ test/sql/types.test.lua | 9 ++++++++ 7 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index deaae61..6e724c8 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -428,7 +428,7 @@ typeofFunc(sql_context * context, int NotUsed, sql_value ** argv) z = "string"; break; case MP_DOUBLE: - z = "number"; + z = "double"; break; case MP_BIN: z = "varbinary"; diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua index 23229db..9c937a0 100755 --- a/test/sql-tap/cast.test.lua +++ b/test/sql-tap/cast.test.lua @@ -257,10 +257,10 @@ test:do_execsql_test( test:do_execsql_test( "cast-1.26", [[ - SELECT typeof(CAST(123 AS NUMBER)) + SELECT typeof(CAST(123 AS DOUBLE)) ]], { -- <cast-1.26> - "number" + "double" -- </cast-1.26> }) @@ -320,7 +320,7 @@ test:do_execsql_test( SELECT typeof(123.456) ]], { -- <cast-1.32> - "number" + "double" -- </cast-1.32> }) @@ -357,10 +357,10 @@ test:do_execsql_test( test:do_execsql_test( "cast-1.36", [[ - SELECT typeof(CAST(123.456 AS NUMBER)) + SELECT typeof(CAST(123.456 AS DOUBLE)) ]], { -- <cast-1.36> - "number" + "double" -- </cast-1.36> }) @@ -380,7 +380,7 @@ test:do_execsql_test( SELECT typeof(CAST(123.456 AS SCALAR)) ]], { -- <cast-1.38> - "number" + "double" -- </cast-1.38> }) diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index 21ededa..3dc28cf 100755 --- a/test/sql-tap/check.test.lua +++ b/test/sql-tap/check.test.lua @@ -29,7 +29,7 @@ test:do_execsql_test( [[ CREATE TABLE t1( x INTEGER CHECK( x<5 ), - y NUMBER CHECK( y>x ), + y DOUBLE CHECK( y>x ), z INT primary key ); ]], { @@ -207,7 +207,7 @@ test:do_execsql_test( CREATE TABLE t2( id INT primary key, x SCALAR CONSTRAINT one CHECK( typeof(coalesce(x,0))=='integer'), - y NUMBER CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='number' ), + y DOUBLE CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='double' ), z SCALAR CONSTRAINT three CHECK( typeof(coalesce(z,''))=='string' ) ); ]], { diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index bd1941b..3c08892 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -518,7 +518,7 @@ test:do_execsql_test( SELECT typeof(round(5.1,1)); ]], { -- <func-4.14> - "number" + "double" -- </func-4.14> }) @@ -528,7 +528,7 @@ test:do_execsql_test( SELECT typeof(round(5.1)); ]], { -- <func-4.15> - "number" + "double" -- </func-4.15> }) diff --git a/test/sql-tap/select3.test.lua b/test/sql-tap/select3.test.lua index 92e7f8e..0b0b9cc 100755 --- a/test/sql-tap/select3.test.lua +++ b/test/sql-tap/select3.test.lua @@ -376,9 +376,9 @@ test:do_execsql_test("select3-7.2", [[ test:do_execsql_test("select3-8.1", [[ DROP TABLE IF EXISTS A; CREATE TABLE A ( - A1 NUMBER, + A1 DOUBLE, A2 TEXT, - A3 NUMBER, + A3 DOUBLE, id int primary key ); INSERT INTO A VALUES(39136,'ABC',1201900000, 1); @@ -386,7 +386,7 @@ test:do_execsql_test("select3-8.1", [[ SELECT typeof(sum(a3)) FROM a; ]], { -- <select3-8.1> - "number" + "double" -- </select3-8.1> }) @@ -394,7 +394,7 @@ test:do_execsql_test("select3-8.2", [[ SELECT typeof(sum(a3)) FROM a GROUP BY a1; ]], { -- <select3-8.2> - "number" + "double" -- </select3-8.2> }) diff --git a/test/sql/types.result b/test/sql/types.result index 6d0aefd..ac4c91e 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -2082,3 +2082,54 @@ box.execute("DROP TABLE t4;") --- - row_count: 1 ... +-- Make sure the typeof() function works correctly with DOUBLE. +box.execute("SELECT 1.0, typeof(1.0);") +--- +- metadata: + - name: '1.0' + type: double + - name: typeof(1.0) + type: string + rows: + - [1, 'double'] +... +box.execute("SELECT CAST(2 AS DOUBLE), typeof(CAST(2 AS DOUBLE));") +--- +- metadata: + - name: CAST(2 AS DOUBLE) + type: double + - name: typeof(CAST(2 AS DOUBLE)) + type: string + rows: + - [2, 'double'] +... +box.execute("SELECT 3e3, typeof(3e3);") +--- +- metadata: + - name: '3e3' + type: double + - name: typeof(3e3) + type: string + rows: + - [3000, 'double'] +... +box.execute("CREATE TABLE t5 (d DOUBLE PRIMARY KEY);") +--- +- row_count: 1 +... +box.execute("INSERT INTO t5 VALUES (4), (5.5), (6e6);") +--- +- row_count: 3 +... +box.execute("SELECT d, TYPEOF(d) FROM t5;") +--- +- metadata: + - name: D + type: double + - name: TYPEOF(d) + type: string + rows: + - [4, 'double'] + - [5.5, 'double'] + - [6000000, 'double'] +... diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua index 24bfa42..c677b27 100644 --- a/test/sql/types.test.lua +++ b/test/sql/types.test.lua @@ -465,3 +465,12 @@ box.execute("CREATE TABLE t4 (i INT PRIMARY KEY, d DOUBLE DEFAULT 1.2345);") box.execute("INSERT INTO t4(i) VALUES (1);") box.execute("SELECT * FROM t4;") box.execute("DROP TABLE t4;") + +-- Make sure the typeof() function works correctly with DOUBLE. +box.execute("SELECT 1.0, typeof(1.0);") +box.execute("SELECT CAST(2 AS DOUBLE), typeof(CAST(2 AS DOUBLE));") +box.execute("SELECT 3e3, typeof(3e3);") + +box.execute("CREATE TABLE t5 (d DOUBLE PRIMARY KEY);") +box.execute("INSERT INTO t5 VALUES (4), (5.5), (6e6);") +box.execute("SELECT d, TYPEOF(d) FROM t5;") -- 2.7.4
next reply other threads:[~2019-12-31 8:47 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-31 8:47 imeevma [this message] 2019-12-31 8:52 ` Nikita Pettik 2020-01-13 10:23 ` Nikita Pettik
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=b2cf9c7f893a76cada236c0cb87daccbaac92088.1577781940.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values' \ /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