* [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values
@ 2019-12-31 8:47 imeevma
2019-12-31 8:52 ` Nikita Pettik
0 siblings, 1 reply; 3+ messages in thread
From: imeevma @ 2019-12-31 8:47 UTC (permalink / raw)
To: korablev; +Cc: tarantool-patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values
2019-12-31 8:47 [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values imeevma
@ 2019-12-31 8:52 ` Nikita Pettik
2020-01-13 10:23 ` Nikita Pettik
0 siblings, 1 reply; 3+ messages in thread
From: Nikita Pettik @ 2019-12-31 8:52 UTC (permalink / raw)
To: imeevma; +Cc: tarantool-patches
On 31 Dec 11:47, imeevma@tarantool.org wrote:
> 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
> ---
LGTM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values
2019-12-31 8:52 ` Nikita Pettik
@ 2020-01-13 10:23 ` Nikita Pettik
0 siblings, 0 replies; 3+ messages in thread
From: Nikita Pettik @ 2020-01-13 10:23 UTC (permalink / raw)
To: imeevma; +Cc: tarantool-patches
On 31 Dec 10:52, Nikita Pettik wrote:
> On 31 Dec 11:47, imeevma@tarantool.org wrote:
> > 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
> > ---
>
> LGTM
>
Pushed to master.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-13 10:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-31 8:47 [Tarantool-patches] [PATCH 1/1] sql: fix typeof() for double values imeevma
2019-12-31 8:52 ` Nikita Pettik
2020-01-13 10:23 ` Nikita Pettik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox