From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org,
Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 6/9] sql: make comparison predicate return boolean
Date: Sun, 14 Apr 2019 18:04:04 +0300 [thread overview]
Message-ID: <68c506297763a91d8caaccfddd54a696331c000a.1555252410.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1555252410.git.korablev@tarantool.org>
In-Reply-To: <cover.1555252410.git.korablev@tarantool.org>
According to ANSI SQL result of comparison predicates must be BOOLEAN.
Before introduction of BOOLEAN type they returned 0 and 1. Now we can
change those values to false and true respectively.
Part of #3723
---
src/box/sql/expr.c | 1 +
src/box/sql/vdbe.c | 4 ++--
test/sql-tap/aggnested.test.lua | 10 +++++-----
test/sql-tap/identifier_case.test.lua | 10 +++++-----
test/sql-tap/tkt3346.test.lua | 2 +-
test/sql/types.result | 20 ++++++++++----------
6 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 09ebdba66..e4de472a8 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -102,6 +102,7 @@ sql_expr_type(struct Expr *pExpr)
case TK_EQ:
case TK_LE:
case TK_NE:
+ return FIELD_TYPE_BOOLEAN;
case TK_NOT:
case TK_AND:
case TK_OR:
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 10794b18e..43d4262e5 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2273,8 +2273,8 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
if ((pOp->opcode==OP_Eq)==res2) break;
}
memAboutToChange(p, pOut);
- MemSetTypeFlag(pOut, MEM_Int);
- pOut->u.i = res2;
+ MemSetTypeFlag(pOut, MEM_Bool);
+ pOut->u.b = res2;
REGISTER_TRACE(pOp->p2, pOut);
} else {
VdbeBranchTaken(res!=0, (pOp->p5 & SQL_NULLEQ)?2:3);
diff --git a/test/sql-tap/aggnested.test.lua b/test/sql-tap/aggnested.test.lua
index 656576b70..67a9ba891 100755
--- a/test/sql-tap/aggnested.test.lua
+++ b/test/sql-tap/aggnested.test.lua
@@ -180,7 +180,7 @@ test:do_execsql_test("aggnested-3.2",
);
INSERT INTO t2 VALUES(1);
SELECT
- (SELECT sum(value2==xyz) FROM t2)
+ (SELECT sum(xyz) FROM t2 where xyz = value2)
FROM
(SELECT value1 as xyz, max(x1) AS pqr
FROM t1
@@ -207,7 +207,7 @@ test:do_execsql_test("aggnested-3.2-2",
);
INSERT INTO t2 VALUES(1);
SELECT
- (SELECT sum(value2<>xyz) FROM t2)
+ (SELECT sum(xyz) FROM t2 where xyz <> value2)
FROM
(SELECT value1 as xyz, max(x1) AS pqr
FROM t1
@@ -215,7 +215,7 @@ test:do_execsql_test("aggnested-3.2-2",
]],
{
-- <aggnested-3.2>
- 0
+ ""
-- </aggnested-3.2>
})
@@ -227,13 +227,13 @@ test:do_execsql_test("aggnested-3.3",
INSERT INTO t1 VALUES(4469,2),(4469,1);
CREATE TABLE t2 (value2 INT PRIMARY KEY);
INSERT INTO t2 VALUES(1);
- SELECT (SELECT sum(value2=value1) FROM t2), max(value1)
+ SELECT (SELECT sum(value1) FROM t2 where value1=value2), max(value1)
FROM t1
GROUP BY id1;
]],
{
-- <aggnested-3.3>
- 0, 2
+ "", 2
-- </aggnested-3.3>
})
diff --git a/test/sql-tap/identifier_case.test.lua b/test/sql-tap/identifier_case.test.lua
index 9c800dd2c..06be7a3dd 100755
--- a/test/sql-tap/identifier_case.test.lua
+++ b/test/sql-tap/identifier_case.test.lua
@@ -239,14 +239,14 @@ test:do_catchsql_test(
data = {
{ 1, [[ 'a' < 'b' collate binary ]], {1, "Collation 'BINARY' does not exist"}},
- { 2, [[ 'a' < 'b' collate "binary" ]], {0, {1}}},
+ { 2, [[ 'a' < 'b' collate "binary" ]], {0, {true}}},
{ 3, [[ 'a' < 'b' collate 'binary' ]], {1, [[Syntax error near ''binary'']]}},
- { 4, [[ 'a' < 'b' collate "unicode" ]], {0, {1}}},
- { 5, [[ 5 < 'b' collate "unicode" ]], {0, {1}}},
+ { 4, [[ 'a' < 'b' collate "unicode" ]], {0, {true}}},
+ { 5, [[ 5 < 'b' collate "unicode" ]], {0, {true}}},
{ 6, [[ 5 < 'b' collate unicode ]], {1,"Collation 'UNICODE' does not exist"}},
- { 7, [[ 5 < 'b' collate "unicode_ci" ]], {0, {1}}},
+ { 7, [[ 5 < 'b' collate "unicode_ci" ]], {0, {true}}},
{ 8, [[ 5 < 'b' collate NONE ]], {1, "Collation 'NONE' does not exist"}},
- { 9, [[ 5 < 'b' collate "none" ]], {0, {1}}},
+ { 9, [[ 5 < 'b' collate "none" ]], {0, {true}}},
}
for _, row in ipairs(data) do
diff --git a/test/sql-tap/tkt3346.test.lua b/test/sql-tap/tkt3346.test.lua
index 269a34f69..ce57a2db0 100755
--- a/test/sql-tap/tkt3346.test.lua
+++ b/test/sql-tap/tkt3346.test.lua
@@ -42,7 +42,7 @@ test:do_test(
function()
return test:execsql [[
SELECT b FROM (SELECT a,b FROM t1) AS x
- WHERE (SELECT y FROM (SELECT x.b='alice' AS y))=0
+ WHERE (SELECT y FROM (SELECT x.b='alice' AS y))=false
]]
end, {
-- <tkt3346-1.2>
diff --git a/test/sql/types.result b/test/sql/types.result
index 6bccd39ef..d6c81bed1 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -277,39 +277,39 @@ box.execute("SELECT true = false;")
---
- metadata:
- name: true = false
- type: integer
+ type: boolean
rows:
- - [0]
+ - [false]
...
box.execute("SELECT true = true;")
---
- metadata:
- name: true = true
- type: integer
+ type: boolean
rows:
- - [1]
+ - [true]
...
box.execute("SELECT true > false;")
---
- metadata:
- name: true > false
- type: integer
+ type: boolean
rows:
- - [1]
+ - [true]
...
box.execute("SELECT true < false;")
---
- metadata:
- name: true < false
- type: integer
+ type: boolean
rows:
- - [0]
+ - [false]
...
box.execute("SELECT null = true;")
---
- metadata:
- name: null = true
- type: integer
+ type: boolean
rows:
- [null]
...
@@ -317,7 +317,7 @@ box.execute("SELECT unknown = true;")
---
- metadata:
- name: unknown = true
- type: integer
+ type: boolean
rows:
- [null]
...
--
2.15.1
next prev parent reply other threads:[~2019-04-14 15:04 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-14 15:03 [tarantool-patches] [PATCH 0/9] Introduce type BOOLEAN in SQL Nikita Pettik
2019-04-14 15:03 ` [tarantool-patches] [PATCH 1/9] sql: refactor mem_apply_numeric_type() Nikita Pettik
2019-04-14 15:04 ` [tarantool-patches] [PATCH 2/9] sql: disallow text values participate in sum() aggregate Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:54 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:58 ` n.pettik
2019-04-14 15:04 ` [tarantool-patches] [PATCH 3/9] sql: use msgpack types instead of custom ones Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:54 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:58 ` n.pettik
2019-04-14 15:04 ` [tarantool-patches] [PATCH 4/9] sql: introduce type boolean Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:54 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:58 ` n.pettik
2019-04-23 21:06 ` Vladislav Shpilevoy
2019-04-14 15:04 ` [tarantool-patches] [PATCH 5/9] sql: improve type determination for column meta Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:54 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:58 ` n.pettik
2019-04-14 15:04 ` Nikita Pettik [this message]
2019-04-16 14:12 ` [tarantool-patches] Re: [PATCH 6/9] sql: make comparison predicate return boolean Vladislav Shpilevoy
2019-04-18 17:54 ` n.pettik
2019-04-14 15:04 ` [tarantool-patches] [PATCH 7/9] sql: make predicates accept and " Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:55 ` n.pettik
2019-04-14 15:04 ` [tarantool-patches] [PATCH 9/9] sql: make <search condition> accept only boolean Nikita Pettik
2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 17:55 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:59 ` n.pettik
2019-04-23 21:06 ` Vladislav Shpilevoy
2019-04-23 22:01 ` n.pettik
[not found] ` <b2a84f129c2343d3da3311469cbb7b20488a21c2.1555252410.git.korablev@tarantool.org>
2019-04-16 14:12 ` [tarantool-patches] Re: [PATCH 8/9] sql: make LIKE predicate return boolean result Vladislav Shpilevoy
2019-04-18 17:55 ` n.pettik
2019-04-22 18:02 ` Vladislav Shpilevoy
2019-04-23 19:58 ` n.pettik
2019-04-24 10:28 ` [tarantool-patches] Re: [PATCH 0/9] Introduce type BOOLEAN in SQL Vladislav Shpilevoy
2019-04-25 8:46 ` Kirill Yukhin
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=68c506297763a91d8caaccfddd54a696331c000a.1555252410.git.korablev@tarantool.org \
--to=korablev@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [tarantool-patches] [PATCH 6/9] sql: make comparison predicate return boolean' \
/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