Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 2/2] sql: make default type of NULL be boolean
Date: Sat, 27 Jul 2019 21:45:36 +0300	[thread overview]
Message-ID: <b37c067e25e094aef0065b1d0228bab2b440c929.1564247922.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1564247922.git.korablev@tarantool.org>
In-Reply-To: <cover.1564247922.git.korablev@tarantool.org>

It was decided that null value in SQL by default should be of type
boolean. Justification of such change is that according to ANSI boolean
type in fact has three different values: true, false and unknown. The
latter is basically an alias to null value.
---
 src/box/sql/func.c          |  3 ++-
 test/sql-tap/cast.test.lua  |  4 ++--
 test/sql-tap/func.test.lua  | 12 ++++++------
 test/sql-tap/table.test.lua |  2 +-
 test/sql/types.result       |  2 +-
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index f50df105d..06904e082 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -133,10 +133,11 @@ typeofFunc(sql_context * context, int NotUsed, sql_value ** argv)
 		z = "scalar";
 		break;
 	case MP_BOOL:
+	case MP_NIL:
 		z = "boolean";
 		break;
 	default:
-		z = "null";
+		unreachable();
 		break;
 	}
 	sql_result_text(context, z, -1, SQL_STATIC);
diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua
index f06cc81d6..96162639c 100755
--- a/test/sql-tap/cast.test.lua
+++ b/test/sql-tap/cast.test.lua
@@ -120,7 +120,7 @@ test:do_execsql_test(
         SELECT typeof(NULL)
     ]], {
         -- <cast-1.12>
-        "null"
+        "boolean"
         -- </cast-1.12>
     })
 
@@ -180,7 +180,7 @@ test:do_execsql_test(
         SELECT typeof(CAST(NULL AS SCALAR))
     ]], {
         -- <cast-1.18>
-        "null"
+        "boolean"
         -- </cast-1.18>
     })
 
diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua
index 961fd350a..09407d3fa 100755
--- a/test/sql-tap/func.test.lua
+++ b/test/sql-tap/func.test.lua
@@ -1802,7 +1802,7 @@ test:do_execsql_test(
         SELECT typeof(replace('This is the main test string', NULL, 'ALT'));
     ]], {
         -- <func-21.3>
-        "null"
+        "boolean"
         -- </func-21.3>
     })
 
@@ -1812,7 +1812,7 @@ test:do_execsql_test(
         SELECT typeof(replace(NULL, 'main', 'ALT'));
     ]], {
         -- <func-21.4>
-        "null"
+        "boolean"
         -- </func-21.4>
     })
 
@@ -1822,7 +1822,7 @@ test:do_execsql_test(
         SELECT typeof(replace('This is the main test string', 'main', NULL));
     ]], {
         -- <func-21.5>
-        "null"
+        "boolean"
         -- </func-21.5>
     })
 
@@ -2043,7 +2043,7 @@ test:do_execsql_test(
         SELECT typeof(trim(NULL));
     ]], {
         -- <func-22.20>
-        "null"
+        "boolean"
         -- </func-22.20>
     })
 
@@ -2053,7 +2053,7 @@ test:do_execsql_test(
         SELECT typeof(TRIM('xyz' FROM NULL));
     ]], {
         -- <func-22.21>
-        "null"
+        "boolean"
         -- </func-22.21>
     })
 
@@ -2063,7 +2063,7 @@ test:do_execsql_test(
         SELECT typeof(TRIM(NULL FROM 'hello'));
     ]], {
         -- <func-22.22>
-        "null"
+        "boolean"
         -- </func-22.22>
     })
 
diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua
index 7f4b15e72..18adf70a9 100755
--- a/test/sql-tap/table.test.lua
+++ b/test/sql-tap/table.test.lua
@@ -906,7 +906,7 @@ test:do_execsql_test(
         FROM t7 LIMIT 1;
     ]], {
         -- <table-11.1>
-        "integer", "number", "string", "string", "null", "null", "string", "string"
+        "integer", "number", "string", "string", "boolean", "boolean", "string", "string"
         -- </table-11.1>
     })
 
diff --git a/test/sql/types.result b/test/sql/types.result
index 6e7fffa42..3750ed2a3 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -1771,7 +1771,7 @@ box.execute("SELECT typeof(a), typeof(s) FROM t;")
     type: string
   rows:
   - ['integer', 'integer']
-  - ['integer', 'null']
+  - ['integer', 'boolean']
 ...
 box.execute("SELECT typeof(CAST(0 AS UNSIGNED));")
 ---
-- 
2.15.1

  parent reply	other threads:[~2019-07-27 18:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27 18:45 [tarantool-patches] [PATCH 0/2] Improve operability of typeof() function Nikita Pettik
2019-07-27 18:45 ` [tarantool-patches] [PATCH 1/2] sql: extend struct Mem with field_type member Nikita Pettik
2019-07-28 15:22   ` [tarantool-patches] " Vladislav Shpilevoy
2019-07-28 21:26     ` Konstantin Osipov
2019-07-31  9:14     ` n.pettik
2019-07-31 16:59       ` Vladislav Shpilevoy
2019-08-01 15:56         ` n.pettik
2019-08-01 23:11           ` Vladislav Shpilevoy
2019-08-02 10:02             ` n.pettik
2019-07-27 18:45 ` Nikita Pettik [this message]
2019-08-02 10:52 ` [tarantool-patches] Re: [PATCH 0/2] Improve operability of typeof() function 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=b37c067e25e094aef0065b1d0228bab2b440c929.1564247922.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 2/2] sql: make default type of NULL be 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