Skip to content

Commit 3caeb33

Browse files
Korablev77kyukhin
authored andcommitted
sql: remove support of DATE/TIME from parser
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
1 parent 03b9a6e commit 3caeb33

12 files changed

+69
-35
lines changed

extra/mkkeywordhash.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ static Keyword aKeywordTable[] = {
126126
{ "CONSTRAINT", "TK_CONSTRAINT", ALWAYS, true },
127127
{ "CREATE", "TK_CREATE", ALWAYS, true },
128128
{ "CROSS", "TK_JOIN_KW", ALWAYS, true },
129-
{ "CURRENT_DATE", "TK_CTIME_KW", ALWAYS, true },
130-
{ "CURRENT_TIME", "TK_CTIME_KW", ALWAYS, true },
131-
{ "CURRENT_TIMESTAMP", "TK_CTIME_KW", ALWAYS, true },
132129
{ "DEFAULT", "TK_DEFAULT", ALWAYS, true },
133130
{ "DEFERRED", "TK_DEFERRED", ALWAYS, false },
134131
{ "DEFERRABLE", "TK_DEFERRABLE", FKEY, false },
@@ -225,8 +222,11 @@ static Keyword aKeywordTable[] = {
225222
{ "CURRENT", "TK_STANDARD", RESERVED, true },
226223
{ "CURRENT_USER", "TK_STANDARD", RESERVED, true },
227224
{ "CURSOR", "TK_STANDARD", RESERVED, true },
228-
{ "DATE", "TK_DATE", RESERVED, true },
229-
{ "DATETIME", "TK_DATETIME", RESERVED, true },
225+
{ "CURRENT_DATE", "TK_STANDARD", RESERVED, true },
226+
{ "CURRENT_TIME", "TK_STANDARD", RESERVED, true },
227+
{ "CURRENT_TIMESTAMP", "TK_STANDARD", RESERVED, true },
228+
{ "DATE", "TK_STANDARD", RESERVED, true },
229+
{ "DATETIME", "TK_STANDARD", RESERVED, true },
230230
{ "DECIMAL", "TK_DECIMAL", RESERVED, true },
231231
{ "DECLARE", "TK_STANDARD", RESERVED, true },
232232
{ "DENSE_RANK", "TK_STANDARD", RESERVED, true },

src/box/sql/date.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969
#include <assert.h>
7070
#include <time.h>
7171

72-
#ifndef SQL_OMIT_DATETIME_FUNCS
72+
/*
73+
* Till time-like types are implemented as native Tarantool
74+
* types, built-in functions below make no sense.
75+
*/
76+
#if 0
7377

7478
/*
7579
* A structure for holding a single date and time.
@@ -1305,7 +1309,7 @@ void
13051309
sqlRegisterDateTimeFunctions(void)
13061310
{
13071311
static FuncDef aDateTimeFuncs[] = {
1308-
#ifndef SQL_OMIT_DATETIME_FUNCS
1312+
#if 0
13091313
DFUNCTION(julianday, -1, 0, 0, juliandayFunc, FIELD_TYPE_NUMBER),
13101314
DFUNCTION(date, -1, 0, 0, dateFunc, FIELD_TYPE_STRING),
13111315
DFUNCTION(time, -1, 0, 0, timeFunc, FIELD_TYPE_STRING),
@@ -1315,7 +1319,6 @@ sqlRegisterDateTimeFunctions(void)
13151319
DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc,
13161320
FIELD_TYPE_STRING),
13171321
DFUNCTION(current_date, 0, 0, 0, cdateFunc, FIELD_TYPE_STRING),
1318-
#else
13191322
STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
13201323
STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
13211324
STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0,

src/box/sql/parse.y

+18-9
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,10 @@ expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP(E). {
931931
}
932932
}
933933

934-
type_func(A) ::= DATE(A) .
935-
type_func(A) ::= DATETIME(A) .
934+
/*
935+
* type_func(A) ::= DATE(A) .
936+
* type_func(A) ::= DATETIME(A) .
937+
*/
936938
type_func(A) ::= CHAR(A) .
937939
expr(A) ::= type_func(X) LP distinct(D) exprlist(Y) RP(E). {
938940
if( Y && Y->nExpr>pParse->db->aLimit[SQL_LIMIT_FUNCTION_ARG] ){
@@ -949,10 +951,12 @@ expr(A) ::= id(X) LP STAR RP(E). {
949951
A.pExpr = sqlExprFunction(pParse, 0, &X);
950952
spanSet(&A,&X,&E);
951953
}
952-
term(A) ::= CTIME_KW(OP). {
953-
A.pExpr = sqlExprFunction(pParse, 0, &OP);
954-
spanSet(&A, &OP, &OP);
955-
}
954+
/*
955+
* term(A) ::= CTIME_KW(OP). {
956+
* A.pExpr = sqlExprFunction(pParse, 0, &OP);
957+
* spanSet(&A, &OP, &OP);
958+
* }
959+
*/
956960

957961
%include {
958962
/* 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. {
14741478
%type typedef {struct type_def}
14751479
typedef(A) ::= TEXT . { A.type = FIELD_TYPE_STRING; }
14761480
typedef(A) ::= BLOB_KW . { A.type = FIELD_TYPE_SCALAR; }
1477-
typedef(A) ::= DATE . { A.type = FIELD_TYPE_NUMBER; }
1478-
typedef(A) ::= TIME . { A.type = FIELD_TYPE_NUMBER; }
1479-
typedef(A) ::= DATETIME . { A.type = FIELD_TYPE_NUMBER; }
1481+
/**
1482+
* Time-like types are temporary disabled, until they are
1483+
* implemented as a native Tarantool types (gh-3694).
1484+
*
1485+
typedef(A) ::= DATE . { A.type = FIELD_TYPE_NUMBER; }
1486+
typedef(A) ::= TIME . { A.type = FIELD_TYPE_NUMBER; }
1487+
typedef(A) ::= DATETIME . { A.type = FIELD_TYPE_NUMBER; }
1488+
*/
14801489

14811490
%type char_len {int}
14821491
typedef(A) ::= CHAR . {

test/sql-tap/date.test.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env tarantool
22
test = require("sqltester")
3-
test:plan(1279)
3+
-- test:plan(1279)
4+
test:plan(0)
45

56
--!./tcltestrunner.lua
67
-- 2003 October 31
@@ -26,7 +27,9 @@ test:plan(1279)
2627
-- at compile-time
2728
--
2829

29-
30+
-- Disabled until #3694 is resolved.
31+
--
32+
if false then
3033
local function datetest(tnum, expr, result)
3134
test:do_test(
3235
"date-"..tnum,
@@ -478,7 +481,7 @@ test:do_test(
478481
1
479482
-- </date-15.2>
480483
})
481-
484+
end -- if false
482485

483486

484487
test:finish_test()

test/sql-tap/suite.ini

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ disabled = selectA.test.lua ;
55
like2.test.lua ;
66
types2.test.lua ;
77
e_expr.test.lua ;
8+
date.test.lua ;
9+
tkt-bd484a090c.test.lua ;
10+
tkt3791.test.lua ;
11+
812
lua_libs = lua/sqltester.lua ../sql/lua/sql_tokenizer.lua ../box/lua/identifier.lua
913
is_parallel = True
1014
release_disabled = debug_mode_only.test.lua

test/sql-tap/table.test.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env tarantool
22
test = require("sqltester")
3-
test:plan(78)
3+
test:plan(77)
44

55
--!./tcltestrunner.lua
66
-- 2001 September 15
@@ -945,6 +945,9 @@ test:do_execsql_test(
945945
-- Test the ability to have default values of CURRENT_TIME, CURRENT_DATE
946946
-- and CURRENT_TIMESTAMP.
947947
--
948+
-- Disabled until #3694 is resolved.
949+
--
950+
if false then
948951
test:do_execsql_test(
949952
"table-13.1",
950953
[[
@@ -960,6 +963,7 @@ test:do_execsql_test(
960963

961964
-- </table-13.1>
962965
})
966+
end
963967

964968
----------------------------------------------------------------------
965969
-- Test cases table-14.*

test/sql-tap/tkt-7bbfb7d442.test.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if (1 > 0)
9191
InventoryControlId INTEGER,
9292
SKU INTEGER NOT NULL PRIMARY KEY,
9393
Variant INTEGER NOT NULL DEFAULT 0,
94-
ControlDate DATE NOT NULL,
94+
ControlDate TEXT NOT NULL,
9595
ControlState INTEGER NOT NULL DEFAULT -1,
9696
DeliveredQty TEXT
9797
);
@@ -161,7 +161,7 @@ if (1 > 0)
161161
162162
163163
INSERT INTO InventoryControl(SKU, Variant, ControlDate) SELECT
164-
II.SKU AS SKU, II.Variant AS Variant, julianday('2011-08-30') AS ControlDate
164+
II.SKU AS SKU, II.Variant AS Variant, '2011-08-30' AS ControlDate
165165
FROM InventoryItem II;
166166
]])
167167

test/sql-tap/tkt-bd484a090c.test.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env tarantool
22
test = require("sqltester")
3-
test:plan(2)
3+
--test:plan(2)
4+
test:plan(0)
45

56
--!./tcltestrunner.lua
67
-- 2011 June 21
@@ -18,6 +19,10 @@ test:plan(2)
1819
-- ["set","testdir",[["file","dirname",["argv0"]]]]
1920
-- ["source",[["testdir"],"\/tester.tcl"]]
2021
testprefix = "tkt-bd484a090c"
22+
23+
-- Disabled until #3694 is resolved.
24+
--
25+
if false then
2126
test:do_test(
2227
1.1,
2328
function()
@@ -29,7 +34,7 @@ test:do_test(
2934
function()
3035
return test:catchsql(" SELECT datetime('now', 'utc') ")[1]
3136
end, 0)
32-
37+
end -- if false
3338
-- TBI to be implemented feature
3439
--sql_test_control("sql_TESTCTRL_LOCALTIME_FAULT", 1)
3540
--test:do_catchsql_test(

test/sql-tap/tkt2192.test.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env tarantool
22
test = require("sqltester")
3-
test:plan(6)
3+
-- test:plan(6)
4+
test:plan(4)
45

56
--!./tcltestrunner.lua
67
-- 2007 January 26
@@ -23,7 +24,9 @@ test:plan(6)
2324
-- ["set","testdir",[["file","dirname",["argv0"]]]]
2425
-- ["source",[["testdir"],"\/tester.tcl"]]
2526

26-
27+
-- Disabled until #3694 is resolved.
28+
--
29+
if false then
2730
test:do_execsql_test(
2831
"tkt2192-1.1",
2932
[[
@@ -105,6 +108,7 @@ test:do_test(
105108

106109
-- </tkt2192-1.2>
107110
})
111+
end -- if false
108112

109113
test:do_execsql_test(
110114
"tkt2192-2.1",

test/sql-tap/tkt3791.test.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env tarantool
22
test = require("sqltester")
3-
test:plan(1)
3+
--test:plan(1)
4+
test:plan(0)
45

56
--!./tcltestrunner.lua
67
-- 2009 April 2
@@ -21,9 +22,9 @@ test:plan(1)
2122
-- ["set","testdir",[["file","dirname",["argv0"]]]]
2223
-- ["source",[["testdir"],"\/tester.tcl"]]
2324
-- MUST_WORK_TEST
24-
if (0 > 0)
25-
then
26-
end
25+
-- Disabled until #3694 is resolved.
26+
--
27+
if (0 > 0) then
2728
test:do_test(
2829
"tkt3791-1.1",
2930
function()
@@ -37,6 +38,7 @@ test:do_test(
3738
1, 19
3839
-- </tkt3791-1.1>
3940
})
41+
end
4042

4143
test:finish_test()
4244

test/sql/triggers.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ box.sql.execute("PRAGMA sql_default_engine ('vinyl');")
256256
box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
257257
---
258258
...
259-
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
259+
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
260260
---
261261
...
262262
box.sql.execute("PRAGMA sql_default_engine('memtx');")
@@ -292,7 +292,7 @@ box.sql.execute("PRAGMA sql_default_engine ('memtx');")
292292
box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
293293
---
294294
...
295-
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
295+
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
296296
---
297297
...
298298
box.sql.execute("PRAGMA sql_default_engine('vinyl');")

test/sql/triggers.test.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ box.sql.execute("DROP TABLE T1;")
102102
-- Case 1: Src 'vinyl' table; Dst 'memtx' table
103103
box.sql.execute("PRAGMA sql_default_engine ('vinyl');")
104104
box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
105-
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
105+
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
106106
box.sql.execute("PRAGMA sql_default_engine('memtx');")
107107
box.sql.execute("CREATE TABLE n (s0 INT PRIMARY KEY, s1 TEXT UNIQUE, s2 REAL);")
108108
box.sql.execute("INSERT INTO m VALUES (0, '0');")
@@ -118,7 +118,7 @@ box.sql.execute("DROP TABLE n;")
118118
-- Case 2: Src 'memtx' table; Dst 'vinyl' table
119119
box.sql.execute("PRAGMA sql_default_engine ('memtx');")
120120
box.sql.execute("CREATE TABLE m (s0 INT PRIMARY KEY, s1 TEXT UNIQUE);")
121-
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = DATETIME('now'); END;")
121+
box.sql.execute("CREATE TRIGGER m1 BEFORE UPDATE ON m FOR EACH ROW BEGIN UPDATE n SET s2 = 'now'; END;")
122122
box.sql.execute("PRAGMA sql_default_engine('vinyl');")
123123
box.sql.execute("CREATE TABLE n (s0 INT PRIMARY KEY, s1 TEXT UNIQUE, s2 REAL);")
124124
box.sql.execute("INSERT INTO m VALUES (0, '0');")

0 commit comments

Comments
 (0)