From 08439af29414dcf0aab6ae50a84bbda2114f07da Mon Sep 17 00:00:00 2001 From: Yanjie Xu Date: Fri, 25 Aug 2023 17:22:52 -0700 Subject: [PATCH] Revert "Support WAITFOR TIME/DELAY (#1495)" (#1784) This reverts commit e8a4cf99ba57ba0c9b84ef75e6dc907004e4dd47. Task: BABEL-122 Signed-off-by: Yanjie Xu --- .../babelfishpg_tsql/sql/sys_procedures.sql | 29 --- .../babelfishpg_tsql--3.2.0--3.3.0.sql | 29 --- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 22 +- .../src/tsqlUnsupportedFeatureHandler.cpp | 3 + test/JDBC/expected/BABEL-1591.out | 4 +- test/JDBC/expected/waitfor-vu-cleanup.out | 23 --- test/JDBC/expected/waitfor-vu-prepare.out | 57 ------ test/JDBC/expected/waitfor-vu-verify.out | 188 ------------------ test/JDBC/input/waitfor-vu-cleanup.sql | 23 --- test/JDBC/input/waitfor-vu-prepare.sql | 57 ------ test/JDBC/input/waitfor-vu-verify.sql | 134 ------------- test/JDBC/upgrade/latest/schedule | 3 +- 12 files changed, 7 insertions(+), 565 deletions(-) delete mode 100644 test/JDBC/expected/waitfor-vu-cleanup.out delete mode 100644 test/JDBC/expected/waitfor-vu-prepare.out delete mode 100644 test/JDBC/expected/waitfor-vu-verify.out delete mode 100644 test/JDBC/input/waitfor-vu-cleanup.sql delete mode 100644 test/JDBC/input/waitfor-vu-prepare.sql delete mode 100644 test/JDBC/input/waitfor-vu-verify.sql diff --git a/contrib/babelfishpg_tsql/sql/sys_procedures.sql b/contrib/babelfishpg_tsql/sql/sys_procedures.sql index b20b51ae10a..d0d3fcf8375 100644 --- a/contrib/babelfishpg_tsql/sql/sys_procedures.sql +++ b/contrib/babelfishpg_tsql/sql/sys_procedures.sql @@ -280,35 +280,6 @@ CREATE OR REPLACE PROCEDURE sys.sp_testlinkedserver(IN "@servername" sys.sysname AS 'babelfishpg_tsql', 'sp_testlinkedserver_internal' LANGUAGE C; GRANT EXECUTE on PROCEDURE sys.sp_testlinkedserver(IN sys.sysname) TO PUBLIC; -CREATE OR REPLACE PROCEDURE sys.bbf_sleep_for(IN sleep_time DATETIME) -AS $$ -DECLARE - v TIME; -BEGIN - v = CAST(sleep_time as TIME); - PERFORM pg_sleep(extract(epoch from clock_timestamp() + v) - - extract(epoch from clock_timestamp())); -END; -$$ LANGUAGE plpgsql; -GRANT EXECUTE ON PROCEDURE sys.bbf_sleep_for(IN sleep_time DATETIME) TO PUBLIC; - -CREATE OR REPLACE PROCEDURE sys.bbf_sleep_until(IN sleep_time DATETIME) -AS $$ -DECLARE - t TIME; - target_timestamp TIMESTAMPTZ; -BEGIN - t = CAST(sleep_time as TIME); - target_timestamp = current_date + t; - IF target_timestamp < current_timestamp THEN - target_timestamp = target_timestamp + '1 day'; - END IF; - PERFORM pg_sleep(extract(epoch from target_timestamp) - - extract(epoch from clock_timestamp())); -END -$$ LANGUAGE plpgsql; -GRANT EXECUTE ON PROCEDURE sys.bbf_sleep_until(IN sleep_time DATETIME) TO PUBLIC; - CREATE OR REPLACE PROCEDURE sys.sp_addextendedproperty ( "@name" sys.sysname, diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.2.0--3.3.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.2.0--3.3.0.sql index 540cd0e37e5..b4bd3e5dc19 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.2.0--3.3.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.2.0--3.3.0.sql @@ -406,35 +406,6 @@ CREATE OR REPLACE FUNCTION sys.getutcdate() RETURNS sys.datetime LANGUAGE SQL STABLE; GRANT EXECUTE ON FUNCTION sys.getutcdate() TO PUBLIC; -CREATE OR REPLACE PROCEDURE sys.bbf_sleep_for(IN sleep_time DATETIME) -AS $$ -DECLARE - v TIME; -BEGIN - v = CAST(sleep_time as TIME); - PERFORM pg_sleep(extract(epoch from clock_timestamp() + v) - - extract(epoch from clock_timestamp())); -END; -$$ LANGUAGE plpgsql; -GRANT EXECUTE ON PROCEDURE sys.bbf_sleep_for(IN sleep_time DATETIME) TO PUBLIC; - -CREATE OR REPLACE PROCEDURE sys.bbf_sleep_until(IN sleep_time DATETIME) -AS $$ -DECLARE - t TIME; - target_timestamp TIMESTAMPTZ; -BEGIN - t = CAST(sleep_time as TIME); - target_timestamp = current_date + t; - IF target_timestamp < current_timestamp THEN - target_timestamp = target_timestamp + '1 day'; - END IF; - PERFORM pg_sleep(extract(epoch from target_timestamp) - - extract(epoch from clock_timestamp())); -END -$$ LANGUAGE plpgsql; -GRANT EXECUTE ON PROCEDURE sys.bbf_sleep_until(IN sleep_time DATETIME) TO PUBLIC; - -- sp_babelfish_autoformat is a helper procedure which formats the contents of a table (or view) -- as narrowly as possible given its actual column contents. -- This proc is currently only used by sp_who but could be applied more generically. diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index b3b297ff23c..c31b5a0475a 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -4010,27 +4010,7 @@ makeTryCatchStmt(TSqlParser::Try_catch_statementContext *ctx) void * makeWaitForStmt(TSqlParser::Waitfor_statementContext *ctx) { - PLtsql_stmt_exec *result = (PLtsql_stmt_exec *) palloc0(sizeof(*result)); - std::string query; - - result->cmd_type = PLTSQL_STMT_EXEC; - result->lineno = getLineNo(ctx);; - result->is_call = true; - result->return_code_dno = -1; - result->paramno = 0; - result->params = NIL; - - query += "EXEC "; - if (ctx->DELAY()) - query += "bbf_sleep_for("; - else - query += "bbf_sleep_until("; - - query += getFullText(ctx->expression()); - query += ")"; - result->expr = makeTsqlExpr(query, false); - - return result; + return nullptr; } void * diff --git a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp index 2fbdef543db..70e6e294294 100644 --- a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp @@ -131,6 +131,9 @@ class TsqlUnsupportedFeatureHandlerImpl : public TsqlUnsupportedFeatureHandler antlrcpp::Any visitMerge_statement(TSqlParser::Merge_statementContext *ctx) override { handle(INSTR_UNSUPPORTED_TSQL_MERGE, "MERGE", getLineAndPos(ctx)); return visitChildren(ctx); } antlrcpp::Any visitBulk_insert_statement(TSqlParser::Bulk_insert_statementContext *ctx) override; + // CFL + antlrcpp::Any visitWaitfor_statement(TSqlParser::Waitfor_statementContext *ctx) override { handle(INSTR_UNSUPPORTED_TSQL_WAIT_FOR, "WAITFOR", getLineAndPos(ctx)); return visitChildren(ctx); } + // Another antlrcpp::Any visitSet_statement(TSqlParser::Set_statementContext *ctx) override; antlrcpp::Any visitCursor_statement(TSqlParser::Cursor_statementContext *ctx) override; diff --git a/test/JDBC/expected/BABEL-1591.out b/test/JDBC/expected/BABEL-1591.out index 67c89abb40e..c522c339990 100644 --- a/test/JDBC/expected/BABEL-1591.out +++ b/test/JDBC/expected/BABEL-1591.out @@ -68,14 +68,14 @@ CREATE FUNCTION fwaitfordelay(@p int) RETURNS int AS BEGIN WAITFOR DELAY '00:00: GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Invalid use of a side-effecting operator 'WAITFOR' within a function.)~~ +~~ERROR (Message: 'WAITFOR' is not currently supported in Babelfish)~~ CREATE FUNCTION fwaitfortime(@p int) RETURNS int AS BEGIN WAITFOR TIME '00:00:20' RETURN 0 END GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Invalid use of a side-effecting operator 'WAITFOR' within a function.)~~ +~~ERROR (Message: 'WAITFOR' is not currently supported in Babelfish)~~ CREATE FUNCTION fprinttest (@p int) RETURNS int AS BEGIN PRINT 'hello there' RETURN 0 END diff --git a/test/JDBC/expected/waitfor-vu-cleanup.out b/test/JDBC/expected/waitfor-vu-cleanup.out deleted file mode 100644 index 27c7467a02a..00000000000 --- a/test/JDBC/expected/waitfor-vu-cleanup.out +++ /dev/null @@ -1,23 +0,0 @@ -DROP TABLE Timecheck -GO - -DROP TABLE Timecheck1 -GO - -DROP TABLE Timecheck2 -GO - -DROP TABLE Timecheck3 -GO - -DROP TABLE Timecheck4 -GO - -DROP TABLE Timecheck5 -GO - -DROP PROCEDURE TimeDelay -GO - -DROP PROCEDURE Wait2seconds -GO diff --git a/test/JDBC/expected/waitfor-vu-prepare.out b/test/JDBC/expected/waitfor-vu-prepare.out deleted file mode 100644 index 133459ec465..00000000000 --- a/test/JDBC/expected/waitfor-vu-prepare.out +++ /dev/null @@ -1,57 +0,0 @@ -CREATE TABLE Timecheck( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck1( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck2( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck3( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck4( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck5( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - - -CREATE PROCEDURE TimeDelay - ( - @Delaytime char(8)= '00:00:00' - ) -AS -BEGIN - WAITFOR DELAY @Delaytime -END; -GO - - -CREATE PROCEDURE Wait2seconds - ( - @resumetime datetime - ) -AS -BEGIN - WAITFOR TIME @resumetime -END; -GO diff --git a/test/JDBC/expected/waitfor-vu-verify.out b/test/JDBC/expected/waitfor-vu-verify.out deleted file mode 100644 index 5d3fa0edfca..00000000000 --- a/test/JDBC/expected/waitfor-vu-verify.out +++ /dev/null @@ -1,188 +0,0 @@ --- test WAITFOR DELAY with second -INSERT INTO Timecheck (NAME) values('a') -GO -~~ROW COUNT: 1~~ - - -WAITFOR DELAY '00:00:02' -GO - -INSERT INTO Timecheck (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:02.900' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck -GO -~~START~~ -text -WAITFOR DELAY: Passed -~~END~~ - - --- test WAITFOR DELAY with millisecond -INSERT INTO Timecheck1 (NAME) values('a') -GO -~~ROW COUNT: 1~~ - - - -WAITFOR DELAY '00:00:00.050' -INSERT INTO Timecheck1 (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:01' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck1 -GO -~~START~~ -text -WAITFOR DELAY: Passed -~~END~~ - - --- test WAITFOR DELAY in variable -INSERT INTO Timecheck2 (NAME) values('a') -GO -~~ROW COUNT: 1~~ - - -DECLARE @v DATETIME -SET @v = '00:00:02.100' -WAITFOR DELAY @v -GO - -INSERT INTO Timecheck2 (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck2 -GO -~~START~~ -text -WAITFOR DELAY: Passed -~~END~~ - - - --- test WAITFOR DELAY in PROCEDURE -INSERT INTO Timecheck3 (NAME) values('a') -GO -~~ROW COUNT: 1~~ - - -EXEC TimeDelay '00:00:02' -GO - -INSERT INTO Timecheck3 (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck3 -GO -~~START~~ -text -WAITFOR DELAY: Passed -~~END~~ - - - --- test WAITFOR TIME -declare @pausetime datetime -declare @resumetime datetime -set @pausetime = current_timestamp -set @resumetime = @pausetime + '00:00:02' -INSERT INTO Timecheck4 values('a', @pausetime) -WAITFOR TIME @resumetime -GO -~~ROW COUNT: 1~~ - - -INSERT INTO Timecheck4 (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR TIME: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR Time: Failed' - ELSE 'WAITFOR TIME: Passed' - END AS CheckResult -FROM Timecheck4 -GO -~~START~~ -text -WAITFOR TIME: Passed -~~END~~ - - --- test WAITFOR TIME in Procedure -declare @pausetime datetime -declare @resumetime datetime -set @pausetime = current_timestamp -set @resumetime = @pausetime + '00:00:02' -INSERT INTO Timecheck5 values('a', @pausetime) -EXEC Wait2seconds @resumetime -GO -~~ROW COUNT: 1~~ - - -INSERT INTO Timecheck5 (NAME) values('b') -GO -~~ROW COUNT: 1~~ - - --- Expect WAITFOR TIME: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR Time: Failed' - ELSE 'WAITFOR TIME: Passed' - END AS CheckResult -FROM Timecheck5 -GO -~~START~~ -text -WAITFOR TIME: Passed -~~END~~ - - -EXEC sys.bbf_sleep_for '00:00:02' -GO - -declare @resumetime datetime -set @resumetime = current_timestamp + '00:00:02' -EXEC sys.bbf_sleep_until @resumetime -GO diff --git a/test/JDBC/input/waitfor-vu-cleanup.sql b/test/JDBC/input/waitfor-vu-cleanup.sql deleted file mode 100644 index cbd23b97343..00000000000 --- a/test/JDBC/input/waitfor-vu-cleanup.sql +++ /dev/null @@ -1,23 +0,0 @@ -DROP TABLE Timecheck -GO - -DROP TABLE Timecheck1 -GO - -DROP TABLE Timecheck2 -GO - -DROP TABLE Timecheck3 -GO - -DROP TABLE Timecheck4 -GO - -DROP TABLE Timecheck5 -GO - -DROP PROCEDURE TimeDelay -GO - -DROP PROCEDURE Wait2seconds -GO \ No newline at end of file diff --git a/test/JDBC/input/waitfor-vu-prepare.sql b/test/JDBC/input/waitfor-vu-prepare.sql deleted file mode 100644 index ec74087eb92..00000000000 --- a/test/JDBC/input/waitfor-vu-prepare.sql +++ /dev/null @@ -1,57 +0,0 @@ -CREATE TABLE Timecheck( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck1( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck2( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck3( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck4( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - -CREATE TABLE Timecheck5( - Name VARCHAR(50), - CheckTime DATETIME DEFAULT CURRENT_TIMESTAMP -) -GO - - -CREATE PROCEDURE TimeDelay - ( - @Delaytime char(8)= '00:00:00' - ) -AS -BEGIN - WAITFOR DELAY @Delaytime -END; -GO - - -CREATE PROCEDURE Wait2seconds - ( - @resumetime datetime - ) -AS -BEGIN - WAITFOR TIME @resumetime -END; -GO \ No newline at end of file diff --git a/test/JDBC/input/waitfor-vu-verify.sql b/test/JDBC/input/waitfor-vu-verify.sql deleted file mode 100644 index e206bf0666e..00000000000 --- a/test/JDBC/input/waitfor-vu-verify.sql +++ /dev/null @@ -1,134 +0,0 @@ --- test WAITFOR DELAY with second -INSERT INTO Timecheck (NAME) values('a') -GO - -WAITFOR DELAY '00:00:02' -GO - -INSERT INTO Timecheck (NAME) values('b') -GO - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:02.900' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck -GO - --- test WAITFOR DELAY with millisecond -INSERT INTO Timecheck1 (NAME) values('a') -GO - -WAITFOR DELAY '00:00:00.050' - -INSERT INTO Timecheck1 (NAME) values('b') -GO - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:01' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck1 -GO - --- test WAITFOR DELAY in variable -INSERT INTO Timecheck2 (NAME) values('a') -GO - -DECLARE @v DATETIME -SET @v = '00:00:02.100' -WAITFOR DELAY @v -GO - -INSERT INTO Timecheck2 (NAME) values('b') -GO - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck2 -GO - - --- test WAITFOR DELAY in PROCEDURE -INSERT INTO Timecheck3 (NAME) values('a') -GO - -EXEC TimeDelay '00:00:02' -GO - -INSERT INTO Timecheck3 (NAME) values('b') -GO - --- Expect WAITFOR DELAY: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR DELAY: Failed' - ELSE 'WAITFOR DELAY: Passed' - END AS CheckResult -FROM Timecheck3 -GO - - --- test WAITFOR TIME -declare @pausetime datetime -declare @resumetime datetime -set @pausetime = current_timestamp -set @resumetime = @pausetime + '00:00:02' -INSERT INTO Timecheck4 values('a', @pausetime) -WAITFOR TIME @resumetime -GO - -INSERT INTO Timecheck4 (NAME) values('b') -GO - --- Expect WAITFOR TIME: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR Time: Failed' - ELSE 'WAITFOR TIME: Passed' - END AS CheckResult -FROM Timecheck4 -GO - --- test WAITFOR TIME in Procedure -declare @pausetime datetime -declare @resumetime datetime -set @pausetime = current_timestamp -set @resumetime = @pausetime + '00:00:02' -INSERT INTO Timecheck5 values('a', @pausetime) -EXEC Wait2seconds @resumetime -GO - -INSERT INTO Timecheck5 (NAME) values('b') -GO - --- Expect WAITFOR TIME: Passed -SELECT - CASE - WHEN (max(CheckTime) - min(CheckTime)) > '1900-01-01 00:00:03' - THEN 'WAITFOR Time: Failed' - ELSE 'WAITFOR TIME: Passed' - END AS CheckResult -FROM Timecheck5 -GO - -EXEC sys.bbf_sleep_for '00:00:02' -GO - -declare @resumetime datetime -set @resumetime = current_timestamp + '00:00:02' -EXEC sys.bbf_sleep_until @resumetime -GO \ No newline at end of file diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index ee994fa5697..f0177bdc987 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -444,7 +444,6 @@ datetimeoffset-timezone BABEL-4046 host_id linked_srv_4229 -waitfor BABEL-4175 sp_who -BABEL_4330 +BABEL_4330 \ No newline at end of file