[tarantool-patches] [PATCH 1/4] sql: remove support of DATE/TIME from parser

Nikita Pettik korablev at tarantool.org
Thu Mar 7 16:14:01 MSK 2019


Currently, there is no native (in Tarantool terms) types to represent
time-like types. So, until we add implementation of those types, it
makes no sense to allow to specify those types in table definition.
Note that previously they were mapped to NUMBER type. For the same
reason all built-in functions connected with DATE/TIME are disabled as
well.

Part of #4019
---
 extra/mkkeywordhash.c                | 10 +++++-----
 src/box/sql/date.c                   |  9 ++++++---
 src/box/sql/parse.y                  | 27 ++++++++++++++++++---------
 test/sql-tap/date.test.lua           |  9 ++++++---
 test/sql-tap/suite.ini               |  4 ++++
 test/sql-tap/table.test.lua          |  6 +++++-
 test/sql-tap/tkt-7bbfb7d442.test.lua |  4 ++--
 test/sql-tap/tkt-bd484a090c.test.lua |  9 +++++++--
 test/sql-tap/tkt2192.test.lua        |  8 ++++++--
 test/sql-tap/tkt3791.test.lua        | 10 ++++++----
 test/sql/triggers.result             |  4 ++--
 test/sql/triggers.test.lua           |  4 ++--
 12 files changed, 69 insertions(+), 35 deletions(-)

diff --git a/extra/mkkeywordhash.c b/extra/mkkeywordhash.c
index edc2ee3b7..491b81ddd 100644
--- a/extra/mkkeywordhash.c
+++ b/extra/mkkeywordhash.c
@@ -126,9 +126,6 @@ static Keyword aKeywordTable[] = {
   { "CONSTRAINT",             "TK_CONSTRAINT",  ALWAYS,           true  },
   { "CREATE",                 "TK_CREATE",      ALWAYS,           true  },
   { "CROSS",                  "TK_JOIN_KW",     ALWAYS,           true  },
-  { "CURRENT_DATE",           "TK_CTIME_KW",    ALWAYS,           true  },
-  { "CURRENT_TIME",           "TK_CTIME_KW",    ALWAYS,           true  },
-  { "CURRENT_TIMESTAMP",      "TK_CTIME_KW",    ALWAYS,           true  },
   { "DEFAULT",                "TK_DEFAULT",     ALWAYS,           true  },
   { "DEFERRED",               "TK_DEFERRED",    ALWAYS,           false },
   { "DEFERRABLE",             "TK_DEFERRABLE",  FKEY,             false },
@@ -225,8 +222,11 @@ static Keyword aKeywordTable[] = {
   { "CURRENT",                "TK_STANDARD",    RESERVED,         true  },
   { "CURRENT_USER",           "TK_STANDARD",    RESERVED,         true  },
   { "CURSOR",                 "TK_STANDARD",    RESERVED,         true  },
-  { "DATE",                   "TK_DATE",        RESERVED,         true  },
-  { "DATETIME",               "TK_DATETIME",    RESERVED,         true  },
+  { "CURRENT_DATE",           "TK_STANDARD",    RESERVED,         true  },
+  { "CURRENT_TIME",           "TK_STANDARD",    RESERVED,         true  },
+  { "CURRENT_TIMESTAMP",      "TK_STANDARD",    RESERVED,         true  },
+  { "DATE",                   "TK_STANDARD",    RESERVED,         true  },
+  { "DATETIME",               "TK_STANDARD",    RESERVED,         true  },
   { "DECIMAL",                "TK_DECIMAL",     RESERVED,         true  },
   { "DECLARE",                "TK_STANDARD",    RESERVED,         true  },
   { "DENSE_RANK",             "TK_STANDARD",    RESERVED,         true  },
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index f3b5b484c..5f5272ea3 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -69,7 +69,11 @@
 #include <assert.h>
 #include <time.h>
 
-#ifndef SQL_OMIT_DATETIME_FUNCS
+/*
+ * Till time-like types are implemented as native Tarantool
+ * types, built-in functions below make no sense.
+ */
+#if 0
 
 /*
  * A structure for holding a single date and time.
@@ -1305,7 +1309,7 @@ void
 sqlRegisterDateTimeFunctions(void)
 {
 	static FuncDef aDateTimeFuncs[] = {
-#ifndef SQL_OMIT_DATETIME_FUNCS
+#if 0
 		DFUNCTION(julianday, -1, 0, 0, juliandayFunc, FIELD_TYPE_NUMBER),
 		DFUNCTION(date, -1, 0, 0, dateFunc, FIELD_TYPE_STRING),
 		DFUNCTION(time, -1, 0, 0, timeFunc, FIELD_TYPE_STRING),
@@ -1315,7 +1319,6 @@ sqlRegisterDateTimeFunctions(void)
 		DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc,
 			  FIELD_TYPE_STRING),
 		DFUNCTION(current_date, 0, 0, 0, cdateFunc, FIELD_TYPE_STRING),
-#else
 		STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
 		STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
 		STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0,
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index e2504c4f1..fb3639f3f 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -931,8 +931,10 @@ expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP(E). {
   }
 }
 
-type_func(A) ::= DATE(A) .
-type_func(A) ::= DATETIME(A) .
+/*
+ * type_func(A) ::= DATE(A) .
+ * type_func(A) ::= DATETIME(A) .
+ */
 type_func(A) ::= CHAR(A) .
 expr(A) ::= type_func(X) LP distinct(D) exprlist(Y) RP(E). {
   if( Y && Y->nExpr>pParse->db->aLimit[SQL_LIMIT_FUNCTION_ARG] ){
@@ -949,10 +951,12 @@ expr(A) ::= id(X) LP STAR RP(E). {
   A.pExpr = sqlExprFunction(pParse, 0, &X);
   spanSet(&A,&X,&E);
 }
-term(A) ::= CTIME_KW(OP). {
-  A.pExpr = sqlExprFunction(pParse, 0, &OP);
-  spanSet(&A, &OP, &OP);
-}
+/*
+ * term(A) ::= CTIME_KW(OP). {
+ *   A.pExpr = sqlExprFunction(pParse, 0, &OP);
+ *   spanSet(&A, &OP, &OP);
+ * }
+ */
 
 %include {
   /* This routine constructs a binary expression node out of two ExprSpan
@@ -1474,9 +1478,14 @@ wqlist(A) ::= wqlist(A) COMMA nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
 %type typedef {struct type_def}
 typedef(A) ::= TEXT . { A.type = FIELD_TYPE_STRING; }
 typedef(A) ::= BLOB_KW . { A.type = FIELD_TYPE_SCALAR; }
-typedef(A) ::= DATE . { A.type = FIELD_TYPE_NUMBER; }
-typedef(A) ::= TIME . { A.type = FIELD_TYPE_NUMBER; }
-typedef(A) ::= DATETIME . { A.type = FIELD_TYPE_NUMBER; }
+/**
+ * Time-like types are temporary disabled, until they are
+ * implemented as a native Tarantool types (gh-3694).
+ *
+ typedef(A) ::= DATE . { A.type = FIELD_TYPE_NUMBER; }
+ typedef(A) ::= TIME . { A.type = FIELD_TYPE_NUMBER; }
+ typedef(A) ::= DATETIME . { A.type = FIELD_TYPE_NUMBER; }
+*/
 
 %type char_len {int}
 typedef(A) ::= CHAR . {
diff --git a/test/sql-tap/date.test.lua b/test/sql-tap/date.test.lua
index f66a4f02c..87fc80db0 100755
--- a/test/sql-tap/date.test.lua
+++ b/test/sql-tap/date.test.lua
@@ -1,6 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(1279)
+-- test:plan(1279)
+test:plan(0)
 
 --!./tcltestrunner.lua
 -- 2003 October 31
@@ -26,7 +27,9 @@ test:plan(1279)
 -- at compile-time
 --
 
-
+-- Disabled until #3694 is resolved.
+--
+if false then
 local function datetest(tnum, expr, result)
     test:do_test(
         "date-"..tnum,
@@ -478,7 +481,7 @@ test:do_test(
         1
         -- </date-15.2>
     })
-
+end -- if false
 
 
 test:finish_test()
diff --git a/test/sql-tap/suite.ini b/test/sql-tap/suite.ini
index faa56a999..bb492895e 100644
--- a/test/sql-tap/suite.ini
+++ b/test/sql-tap/suite.ini
@@ -5,6 +5,10 @@ disabled = selectA.test.lua ;
            like2.test.lua ;
            types2.test.lua ;
            e_expr.test.lua ;
+           date.test.lua ;
+           tkt-bd484a090c.test.lua ;
+           tkt3791.test.lua ;
+
 lua_libs = lua/sqltester.lua ../sql/lua/sql_tokenizer.lua ../box/lua/identifier.lua
 is_parallel = True
 release_disabled = debug_mode_only.test.lua
diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua
index 2bcc5aa48..b1ea27878 100755
--- a/test/sql-tap/table.test.lua
+++ b/test/sql-tap/table.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(78)
+test:plan(77)
 
 --!./tcltestrunner.lua
 -- 2001 September 15
@@ -945,6 +945,9 @@ test:do_execsql_test(
 -- Test the ability to have default values of CURRENT_TIME, CURRENT_DATE
 -- and CURRENT_TIMESTAMP.
 --
+--  Disabled until #3694 is resolved.
+--
+if false then
 test:do_execsql_test(
     "table-13.1",
     [[
@@ -960,6 +963,7 @@ test:do_execsql_test(
         
         -- </table-13.1>
     })
+end
 
 ----------------------------------------------------------------------
 -- Test cases table-14.*
diff --git a/test/sql-tap/tkt-7bbfb7d442.test.lua b/test/sql-tap/tkt-7bbfb7d442.test.lua
index 15478a77d..9469025cd 100755
--- a/test/sql-tap/tkt-7bbfb7d442.test.lua
+++ b/test/sql-tap/tkt-7bbfb7d442.test.lua
@@ -91,7 +91,7 @@ if (1 > 0)
               InventoryControlId INTEGER,
               SKU INTEGER NOT NULL PRIMARY KEY,
               Variant INTEGER NOT NULL DEFAULT 0,
-              ControlDate DATE NOT NULL,
+              ControlDate TEXT NOT NULL,
               ControlState INTEGER NOT NULL DEFAULT -1,
               DeliveredQty TEXT
             );
@@ -161,7 +161,7 @@ if (1 > 0)
 
 
             INSERT INTO InventoryControl(SKU, Variant, ControlDate) SELECT 
-                II.SKU AS SKU, II.Variant AS Variant, julianday('2011-08-30') AS ControlDate
+                II.SKU AS SKU, II.Variant AS Variant, '2011-08-30' AS ControlDate
                 FROM InventoryItem II;
         ]])
 
diff --git a/test/sql-tap/tkt-bd484a090c.test.lua b/test/sql-tap/tkt-bd484a090c.test.lua
index 974e22169..0347fd426 100755
--- a/test/sql-tap/tkt-bd484a090c.test.lua
+++ b/test/sql-tap/tkt-bd484a090c.test.lua
@@ -1,6 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(2)
+--test:plan(2)
+test:plan(0)
 
 --!./tcltestrunner.lua
 -- 2011 June 21
@@ -18,6 +19,10 @@ test:plan(2)
 -- ["set","testdir",[["file","dirname",["argv0"]]]]
 -- ["source",[["testdir"],"\/tester.tcl"]]
 testprefix = "tkt-bd484a090c"
+
+-- Disabled until #3694 is resolved.
+--
+if false then
 test:do_test(
     1.1,
     function()
@@ -29,7 +34,7 @@ test:do_test(
     function()
         return test:catchsql(" SELECT datetime('now', 'utc') ")[1]
     end, 0)
-
+end -- if false
 -- TBI to be implemented feature
 --sql_test_control("sql_TESTCTRL_LOCALTIME_FAULT", 1)
 --test:do_catchsql_test(
diff --git a/test/sql-tap/tkt2192.test.lua b/test/sql-tap/tkt2192.test.lua
index b118d6310..17b5d46d1 100755
--- a/test/sql-tap/tkt2192.test.lua
+++ b/test/sql-tap/tkt2192.test.lua
@@ -1,6 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(6)
+-- test:plan(6)
+test:plan(4)
 
 --!./tcltestrunner.lua
 -- 2007 January 26
@@ -23,7 +24,9 @@ test:plan(6)
 -- ["set","testdir",[["file","dirname",["argv0"]]]]
 -- ["source",[["testdir"],"\/tester.tcl"]]
 
-
+--  Disabled until #3694 is resolved.
+--
+if false then
 test:do_execsql_test(
     "tkt2192-1.1",
     [[
@@ -105,6 +108,7 @@ test:do_test(
 
         -- </tkt2192-1.2>
     })
+end -- if false
 
 test:do_execsql_test(
     "tkt2192-2.1",
diff --git a/test/sql-tap/tkt3791.test.lua b/test/sql-tap/tkt3791.test.lua
index 388670a4b..d39b6a2d5 100755
--- a/test/sql-tap/tkt3791.test.lua
+++ b/test/sql-tap/tkt3791.test.lua
@@ -1,6 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(1)
+--test:plan(1)
+test:plan(0)
 
 --!./tcltestrunner.lua
 -- 2009 April 2
@@ -21,9 +22,9 @@ test:plan(1)
 -- ["set","testdir",[["file","dirname",["argv0"]]]]
 -- ["source",[["testdir"],"\/tester.tcl"]]
 -- MUST_WORK_TEST
-if (0 > 0)
- then
-end
+-- Disabled until #3694 is resolved.
+--
+if (0 > 0) then
 test:do_test(
     "tkt3791-1.1",
     function()
@@ -37,6 +38,7 @@ test:do_test(
         1, 19
         -- </tkt3791-1.1>
     })
+end
 
 test:finish_test()
 
diff --git a/test/sql/triggers.result b/test/sql/triggers.result
index bbfff3302..2f5b14803 100644
--- a/test/sql/triggers.result
+++ b/test/sql/triggers.result
@@ -256,7 +256,7 @@ box.sql.execute("PRAGMA sql_default_engine ('vinyl');")
 box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
 ---
 ...
-box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
+box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
 ---
 ...
 box.sql.execute("PRAGMA sql_default_engine('memtx');")
@@ -292,7 +292,7 @@ box.sql.execute("PRAGMA sql_default_engine ('memtx');")
 box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
 ---
 ...
-box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
+box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
 ---
 ...
 box.sql.execute("PRAGMA sql_default_engine('vinyl');")
diff --git a/test/sql/triggers.test.lua b/test/sql/triggers.test.lua
index eb3f41ef5..b22b4f9ff 100644
--- a/test/sql/triggers.test.lua
+++ b/test/sql/triggers.test.lua
@@ -102,7 +102,7 @@ box.sql.execute("DROP TABLE T1;")
 -- Case 1: Src 'vinyl' table; Dst 'memtx' table
 box.sql.execute("PRAGMA sql_default_engine ('vinyl');")
 box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
-box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
+box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
 box.sql.execute("PRAGMA sql_default_engine('memtx');")
 box.sql.execute("CREATE TABLE n (s0 INT PRIMARY KEY, s1 TEXT UNIQUE, s2 REAL);")
 box.sql.execute("INSERT INTO m VALUES (0, '0');")
@@ -118,7 +118,7 @@ box.sql.execute("DROP TABLE n;")
 -- Case 2: Src 'memtx' table; Dst 'vinyl' table
 box.sql.execute("PRAGMA sql_default_engine ('memtx');")
 box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
-box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
+box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
 box.sql.execute("PRAGMA sql_default_engine('vinyl');")
 box.sql.execute("CREATE TABLE n (s0 INT PRIMARY KEY, s1 TEXT UNIQUE, s2 REAL);")
 box.sql.execute("INSERT INTO m VALUES (0, '0');")
-- 
2.15.1





More information about the Tarantool-patches mailing list