From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 CC8EE46970E for ; Mon, 30 Dec 2019 16:01:28 +0300 (MSK) From: imeevma@tarantool.org Date: Mon, 30 Dec 2019 16:01:27 +0300 Message-Id: <9e3af6144b07b76eabbd018d9cab75d47803062c.1577710381.git.imeevma@gmail.com> In-Reply-To: References: Subject: [Tarantool-patches] [PATCH v2 2/3] sql: fix typeof() for double values List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org Cc: tarantool-patches@dev.tarantool.org 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 --- 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.test.lua | 9 +++++++++ 6 files changed, 24 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)) ]], { -- - "number" + "double" -- }) @@ -320,7 +320,7 @@ test:do_execsql_test( SELECT typeof(123.456) ]], { -- - "number" + "double" -- }) @@ -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)) ]], { -- - "number" + "double" -- }) @@ -380,7 +380,7 @@ test:do_execsql_test( SELECT typeof(CAST(123.456 AS SCALAR)) ]], { -- - "number" + "double" -- }) 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)); ]], { -- - "number" + "double" -- }) @@ -528,7 +528,7 @@ test:do_execsql_test( SELECT typeof(round(5.1)); ]], { -- - "number" + "double" -- }) 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; ]], { -- - "number" + "double" -- }) @@ -394,7 +394,7 @@ test:do_execsql_test("select3-8.2", [[ SELECT typeof(sum(a3)) FROM a GROUP BY a1; ]], { -- - "number" + "double" -- }) diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua index 24bfa42..59d6709 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 typeof(1.0);") +box.execute("SELECT typeof(CAST(2 AS DOUBLE));") +box.execute("SELECT typeof(3e3);") + +box.execute("CREATE TABLE t5 (d DOUBLE PRIMARY KEY);") +box.execute("INSERT INTO t5 VALUES (4), (5.5), (6e6);") +box.execute("SELECT TYPEOF(d) FROM t5;") -- 2.7.4