Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 committed Jan 13, 2025
1 parent 22d336b commit d64ba46
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 74 deletions.
11 changes: 5 additions & 6 deletions contrib/babelfishpg_tsql/src/iterative_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2198,14 +2198,13 @@ send_env_change_token_on_txn_abort(void)
static void
set_search_path_for_pltsql_stmt(PLtsql_stmt *stmt)
{
char *cur_dbname = get_cur_db_name();
char *cur_dbname;
char *new_search_path = NULL;

if (!IS_TDS_CONN())
{
pfree(cur_dbname);
if (!IS_TDS_CONN() || IsInParallelMode())
return;
}

cur_dbname = get_cur_db_name();

if(stmt->cmd_type == PLTSQL_STMT_EXECSQL)
{
Expand Down Expand Up @@ -2257,7 +2256,7 @@ set_search_path_for_pltsql_stmt(PLtsql_stmt *stmt)
else if (current_db_search_path)
SetConfigOption("search_path", current_db_search_path,
PGC_SUSET, PGC_S_SESSION);
}
}
PG_FINALLY();
{
pltsql_check_search_path = true;
Expand Down
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/pl_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ do_compile(FunctionCallInfo fcinfo,
function->fn_argvarnos[i] = in_arg_varnos[i];

/* store the logical db which contains this function */
if (IS_TDS_CONN() && procStruct->provolatile != PROVOLATILE_IMMUTABLE)
if (IS_TDS_CONN() && procStruct->provolatile != PROVOLATILE_IMMUTABLE && procStruct->proparallel == PROPARALLEL_UNSAFE)
{
function->fn_dbid = get_dbid_from_physical_schema_name(get_namespace_name(procStruct->pronamespace), true);
function->fn_search_path = get_local_schema_for_bbf_functions(procStruct->pronamespace, function->fn_dbid);
Expand Down Expand Up @@ -3277,7 +3277,7 @@ get_local_schema_for_bbf_functions(Oid proc_nsp_oid, int16 dbid)
*new_search_path = NULL;
char *func_dbo_schema;

if (!IS_TDS_CONN() || !DbidIsValid(dbid) || proc_nsp_oid == get_sys_namespace_oid())
if (!IS_TDS_CONN() || !DbidIsValid(dbid))
return NULL;

tuple = SearchSysCache1(NAMESPACEOID,
Expand Down
9 changes: 6 additions & 3 deletions contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5434,7 +5434,7 @@ pltsql_call_handler(PG_FUNCTION_ARGS)
int saved_dialect = sql_dialect;
int current_spi_stack_depth;
bool send_error = false;
char *saved_namespace_search_path = pstrdup(namespace_search_path);
char *saved_namespace_search_path = NULL;
char *saved_pltsql_search_path = pltsql_search_path;
int16 saved_dbid = get_cur_db_id();

Expand Down Expand Up @@ -5502,6 +5502,7 @@ pltsql_call_handler(PG_FUNCTION_ARGS)
if (pltsql_search_path)
{
pltsql_check_search_path = false;
saved_namespace_search_path = pstrdup(namespace_search_path);
SetConfigOption("search_path", pltsql_search_path,
PGC_SUSET, PGC_S_SESSION);
pltsql_check_search_path = true;
Expand Down Expand Up @@ -5558,10 +5559,12 @@ pltsql_call_handler(PG_FUNCTION_ARGS)

if (get_cur_db_id() != saved_dbid)
set_cur_user_db_and_path(get_db_name((saved_dbid)));
if (saved_namespace_search_path && strcmp(saved_namespace_search_path, namespace_search_path) != 0)
if (!IsInParallelMode() && saved_namespace_search_path && strcmp(saved_namespace_search_path, namespace_search_path) != 0)
{
SetConfigOption("search_path", saved_namespace_search_path,
PGC_SUSET, PGC_S_SESSION);
pfree(saved_namespace_search_path);
pfree(saved_namespace_search_path);
}
}
PG_FINALLY();
{
Expand Down
1 change: 0 additions & 1 deletion contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,6 @@ extern bool pltsql_createFunction(ParseState *pstate, PlannedStmt *pstmt, const
ParamListInfo params);
extern Oid get_sys_varcharoid(void);
extern Oid get_sysadmin_oid(void);
extern Oid get_sys_namespace_oid(void);
extern bool is_tsql_varchar_or_char_datatype(Oid oid); /* sys.char / sys.varchar */
extern bool is_tsql_nchar_or_nvarchar_datatype(Oid oid); /* sys.nchar / sys.nvarchar */
extern bool is_tsql_binary_or_varbinary_datatype(Oid oid); /* sys.binary / sys.varbinary */
Expand Down
9 changes: 0 additions & 9 deletions contrib/babelfishpg_tsql/src/pltsql_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ PG_FUNCTION_INFO_V1(split_identifier_internal);
/* To cache oid of sys.varchar */
static Oid sys_varcharoid = InvalidOid;
static Oid sysadmin_oid = InvalidOid;
static Oid sys_namespace_oid = InvalidOid;

/*
* Following the rule for locktag fields of advisory locks:
Expand Down Expand Up @@ -1909,14 +1908,6 @@ Oid get_sysadmin_oid(void)
return sysadmin_oid;
}

Oid get_sys_namespace_oid(void)
{
if (!OidIsValid(sys_namespace_oid))
sys_namespace_oid = get_namespace_oid("sys", false);

return sys_namespace_oid;
}

/*
* Generates the schema name for fulltext index statements
* depending on whether it's master schema or not
Expand Down
11 changes: 6 additions & 5 deletions contrib/babelfishpg_tsql/src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,10 @@ sp_execute_postgresql(PG_FUNCTION_ARGS)
PlannedStmt *wrapper;
const char *saved_dialect = GetConfigOption("babelfishpg_tsql.sql_dialect", true, true);
Oid current_user_id = GetUserId();
const char *saved_path = pstrdup(GetConfigOption("search_path", true, true));
const char *new_path = "public, \"$user\", sys, pg_catalog";
int save_nestlevel;

save_nestlevel = NewGUCNestLevel();
PG_TRY();
{
set_config_option("babelfishpg_tsql.sql_dialect", "postgres",
Expand Down Expand Up @@ -1953,8 +1954,9 @@ sp_execute_postgresql(PG_FUNCTION_ARGS)
}

SetCurrentRoleId(GetSessionUserId(), false);
SetConfigOption("search_path", new_path,
PGC_SUSET, PGC_S_SESSION);
set_config_option("search_path", new_path,
PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_SAVE, true, 0, false);

foreach(lc, crstmt->options)
{
Expand Down Expand Up @@ -2065,11 +2067,10 @@ sp_execute_postgresql(PG_FUNCTION_ARGS)
set_config_option("babelfishpg_tsql.sql_dialect", saved_dialect,
GUC_CONTEXT_CONFIG,
PGC_S_SESSION, GUC_ACTION_SAVE, true, 0, false);
SetConfigOption("search_path", saved_path,
PGC_SUSET, PGC_S_SESSION);
SetCurrentRoleId(current_user_id, false);

}
AtEOXact_GUC(false, save_nestlevel);
PG_END_TRY();
PG_RETURN_VOID();
}
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/BABEL-LOGIN-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SELECT current_setting('search_path');
go
~~START~~
text
master_babel_login_vu_prepare_sch, master_babel_login_vu_prepare_dbo, sys, pg_catalog
master_babel_login_vu_prepare_sch, master_dbo, sys, pg_catalog
~~END~~


Expand Down
58 changes: 29 additions & 29 deletions test/JDBC/expected/BABEL_4877.out
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ EXEC babel_4877_s1.babel_4877_p1
GO
~~START~~
varchar#!#text
before search path ====> #!#master_dbo, "$user", sys, pg_catalog
before search path ====> #!#master_babel_4877_s1, master_dbo, sys, pg_catalog
~~END~~

~~START~~
Expand All @@ -120,7 +120,7 @@ master_babel_4877_s1, sys, pg_catalog

~~START~~
varchar#!#text
after search path ====> #!#master_babel_4877_s1, sys, pg_catalog
after search path ====> #!#master_babel_4877_s1, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -144,26 +144,26 @@ EXEC babel_4877_s1.babel_4877_p1
GO
~~START~~
varchar#!#text
before search path ====> #!#master_dbo, "$user", sys, pg_catalog
before search path ====> #!#master_babel_4877_s1, master_dbo, sys, pg_catalog
~~END~~

~~START~~
varchar
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, "$user", sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
master_babel_4877_s1, master_dbo, sys, pg_catalog
~~END~~

~~START~~
varchar#!#text
after search path ====> #!#master_dbo, "$user", sys, pg_catalog
after search path ====> #!#master_babel_4877_s1, master_dbo, sys, pg_catalog
~~END~~


Expand Down Expand Up @@ -256,7 +256,7 @@ SELECT current_setting('search_path');
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -273,7 +273,7 @@ SELECT current_setting('search_path');
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -290,7 +290,7 @@ SELECT current_setting('search_path');
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -301,7 +301,7 @@ SELECT 'before search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
before search_path ----> #!#master_dbo, "$user", sys, pg_catalog
before search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

EXEC babel_4877_s.babel_4877_p
Expand All @@ -316,7 +316,7 @@ SELECT 'after error search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after error search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after error search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

COMMIT
Expand All @@ -325,7 +325,7 @@ SELECT 'after tran search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after tran search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after tran search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -335,7 +335,7 @@ SELECT 'before search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
before search_path ----> #!#master_dbo, "$user", sys, pg_catalog
before search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

SELECT babel_4877_s.babel_4877_f2();
Expand All @@ -350,7 +350,7 @@ SELECT 'after error search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after error search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after error search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

COMMIT
Expand All @@ -359,7 +359,7 @@ SELECT 'after tran search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after tran search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after tran search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -371,7 +371,7 @@ COMMIT
GO
~~START~~
varchar#!#text
before search_path ----> #!#master_dbo, "$user", sys, pg_catalog
before search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

~~START~~
Expand All @@ -382,7 +382,7 @@ varchar

~~START~~
varchar#!#text
after error search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after error search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand Down Expand Up @@ -415,7 +415,7 @@ SELECT 'before search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
before search_path ----> #!#master_dbo, "$user", sys, pg_catalog
before search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

EXEC babel_4877_s.babel_4877_p2
Expand All @@ -436,7 +436,7 @@ SELECT 'after tran search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after tran search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after tran search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand All @@ -446,7 +446,7 @@ SELECT 'before search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
before search_path ----> #!#master_dbo, "$user", sys, pg_catalog
before search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~

SELECT babel_4877_s.babel_4877_f3();
Expand All @@ -467,7 +467,7 @@ SELECT 'after tran search_path ----> ', current_setting('search_path');
GO
~~START~~
varchar#!#text
after tran search_path ----> #!#master_dbo, "$user", sys, pg_catalog
after tran search_path ----> #!#master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/expected/Test-sp_execute_postgresql.out
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ select current_setting('search_path')
go
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand Down Expand Up @@ -439,7 +439,7 @@ select current_setting('search_path')
go
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~


Expand Down
6 changes: 3 additions & 3 deletions test/JDBC/expected/Test-sp_reset_connection.out
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ Result (cost=0.00..0.01 rows=1 width=4)

~~START~~
text
Babelfish T-SQL Batch Parsing Time: 0.085 ms
Babelfish T-SQL Batch Parsing Time: 0.056 ms
~~END~~


Expand All @@ -680,7 +680,7 @@ SELECT CURRENT_SETTING('role', true)
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~

~~START~~
Expand Down Expand Up @@ -714,7 +714,7 @@ SELECT CURRENT_SETTING('role', true)
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
master_dbo, master_dbo, sys, pg_catalog
~~END~~

~~START~~
Expand Down
1 change: 1 addition & 0 deletions test/JDBC/expected/getdate-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ int#!#int#!#int#!#int


-- psql
SET search_path = master_dbo, sys, pg_catalog;
SET timezone = '+05:30';
select master_dbo.checkDatetimeDiff(sys.DATEDIFF('MINUTE', sys.SYSDATETIME(), sys.SYSDATETIME() AT TIME ZONE 'UTC'), 330, 1);
select master_dbo.checkDatetimeDiff(sys.DATEDIFF('MINUTE', sys.getdate(), sys.getdate() AT TIME ZONE 'UTC'), 330, 1);
Expand Down
Loading

0 comments on commit d64ba46

Please sign in to comment.