Skip to content

Commit

Permalink
Revert "Support WAITFOR TIME/DELAY (#1495)" (#1784)
Browse files Browse the repository at this point in the history
This reverts commit e8a4cf9.

Task: BABEL-122

Signed-off-by: Yanjie Xu <[email protected]>
  • Loading branch information
RIC06X committed Oct 17, 2023
1 parent ff4c47a commit 08439af
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 565 deletions.
29 changes: 0 additions & 29 deletions contrib/babelfishpg_tsql/sql/sys_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 1 addition & 21 deletions contrib/babelfishpg_tsql/src/tsqlIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-1591.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions test/JDBC/expected/waitfor-vu-cleanup.out

This file was deleted.

57 changes: 0 additions & 57 deletions test/JDBC/expected/waitfor-vu-prepare.out

This file was deleted.

188 changes: 0 additions & 188 deletions test/JDBC/expected/waitfor-vu-verify.out

This file was deleted.

Loading

0 comments on commit 08439af

Please sign in to comment.