From 2c673b75fe467c701a21587cad954f1411f19739 Mon Sep 17 00:00:00 2001 From: Sharu Goel <30777678+thephantomthief@users.noreply.github.com> Date: Wed, 23 Oct 2024 18:46:47 +0530 Subject: [PATCH 01/15] [OSS-ONLY] Finalize BABEL_4_4_STABLE (#3047) This commit includes the following changes: - Disable TDS fault injection flag and tests - Update DEFAULT_BRANCH to point to stable branch - Update workflows to point to stable branch Signed-off-by: Sharu Goel --- .github/scripts/clone_engine_repo.conf | 2 +- .github/template/version-branch-template.yml | 8 ++++---- .github/workflows/major-version-upgrade.yml | 4 ++-- .github/workflows/singledb-version-upgrade.yml | 4 ++-- contrib/babelfishpg_tds/Makefile | 2 +- test/JDBC/jdbc_schedule | 4 ++++ 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/scripts/clone_engine_repo.conf b/.github/scripts/clone_engine_repo.conf index 024af54df9..f79ce46838 100644 --- a/.github/scripts/clone_engine_repo.conf +++ b/.github/scripts/clone_engine_repo.conf @@ -1 +1 @@ -DEFAULT_BRANCH=BABEL_4_X_DEV__PG_16_X +DEFAULT_BRANCH=BABEL_4_4_STABLE__PG_16_5 diff --git a/.github/template/version-branch-template.yml b/.github/template/version-branch-template.yml index 66033b31f6..676cf1d105 100644 --- a/.github/template/version-branch-template.yml +++ b/.github/template/version-branch-template.yml @@ -47,8 +47,8 @@ engine_branch: BABEL_2_10_STABLE__PG_14_13 extension_branch: BABEL_2_10_STABLE '14.14': - engine_branch: BABEL_2_X_DEV__PG_14_X - extension_branch: BABEL_2_X_DEV + engine_branch: BABEL_2_11_STABLE__PG_14_14 + extension_branch: BABEL_2_11_STABLE '15.2': engine_branch: BABEL_3_1_STABLE__PG_15_2 extension_branch: BABEL_3_1_STABLE @@ -71,8 +71,8 @@ engine_branch: BABEL_3_7_STABLE__PG_15_8 extension_branch: BABEL_3_7_STABLE '15.9': - engine_branch: BABEL_3_X_DEV__PG_15_X - extension_branch: BABEL_3_X_DEV + engine_branch: BABEL_3_8_STABLE__PG_15_9 + extension_branch: BABEL_3_8_STABLE '16.1': engine_branch: BABEL_4_0_STABLE__PG_16_1 extension_branch: BABEL_4_0_STABLE diff --git a/.github/workflows/major-version-upgrade.yml b/.github/workflows/major-version-upgrade.yml index 98aa5f27f8..5c50d66b0c 100644 --- a/.github/workflows/major-version-upgrade.yml +++ b/.github/workflows/major-version-upgrade.yml @@ -6,8 +6,8 @@ jobs: env: OLD_INSTALL_DIR: psql_source NEW_INSTALL_DIR: psql_target - ENGINE_BRANCH_FROM: BABEL_2_X_DEV__PG_14_X - EXTENSION_BRANCH_FROM: BABEL_2_X_DEV + ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_14 + EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE runs-on: ubuntu-20.04 steps: diff --git a/.github/workflows/singledb-version-upgrade.yml b/.github/workflows/singledb-version-upgrade.yml index a35d90dc18..eebc7a4a64 100644 --- a/.github/workflows/singledb-version-upgrade.yml +++ b/.github/workflows/singledb-version-upgrade.yml @@ -7,8 +7,8 @@ jobs: env: OLD_INSTALL_DIR: psql_source NEW_INSTALL_DIR: psql_target - ENGINE_BRANCH_FROM: BABEL_2_X_DEV__PG_14_X - EXTENSION_BRANCH_FROM: BABEL_2_X_DEV + ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_14 + EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE runs-on: ubuntu-20.04 steps: diff --git a/contrib/babelfishpg_tds/Makefile b/contrib/babelfishpg_tds/Makefile index d734bfd296..53dc10099a 100644 --- a/contrib/babelfishpg_tds/Makefile +++ b/contrib/babelfishpg_tds/Makefile @@ -11,7 +11,7 @@ TSQL_SRC = ../babelfishpg_tsql PG_CFLAGS += -Werror -Wfloat-conversion PG_CFLAGS += -fstack-protector-strong -PG_CPPFLAGS += -I$(TSQL_SRC) -I$(PG_SRC) -I$(tds_top_dir) -DFAULT_INJECTOR +PG_CPPFLAGS += -I$(TSQL_SRC) -I$(PG_SRC) -I$(tds_top_dir) # Exclude the following files from the build (sometimes these # files are included in another c file) diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index 6630488bd1..c98455fce3 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -16,6 +16,10 @@ all ignore#!#insertbulk ignore#!#BABEL-SQLvariant +# TDS fault injection framework is meant for internal testing only. So, ignore tds_faultinjection tests in stable branch +ignore#!#tds_faultinjection +ignore#!#babel_tds_fault_injection + # Ignore upgrade tests in normal JDBC run. These are tests that cannot be run in non-upgrade contexts due # to changing the behavior between pre- and post-commit. ignore#!#BABEL-2934-vu-prepare From 2c7f3bdb9525fcd30a7dd48264b94844fe29b99f Mon Sep 17 00:00:00 2001 From: Rahul Parande <78637928+R4hul04@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:56:05 -0700 Subject: [PATCH 02/15] Updated schedule file for 15_9 to BABEL-2736 (#3053) This pull request updates the schedule file in the BABEL_4_X_DEV branch for version 15_9. The change involves replacing the schedule file "BABEL-2736-before-16_5" with "BABEL-2736" to align with the latest version in the 3x DEV branch. Changes made: In file: /babelfish_extensions/test/JDBC/upgrade/15_9/schedule Changed "BABEL-2736-before-16_5" to "BABEL-2736" Reason for change: To maintain consistency with the latest version in the 3x DEV branch, which uses "BABEL-2736". Reference PR: #3044 Signed-off-by: Rahul Parande --- test/JDBC/upgrade/15_9/schedule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/JDBC/upgrade/15_9/schedule b/test/JDBC/upgrade/15_9/schedule index d92fd1bbcf..0bd29ab197 100644 --- a/test/JDBC/upgrade/15_9/schedule +++ b/test/JDBC/upgrade/15_9/schedule @@ -549,5 +549,5 @@ xml_exist-before-16_5 BABEL-5119_before_16_5 BABEL-CASE_EXPR BABEL-5186 -BABEL-2736-before-16_5 +BABEL-2736 From 9603fe71f3c8f28091ddaf3fff86b4eac525ccc8 Mon Sep 17 00:00:00 2001 From: Shameem Ahmed <54461265+ahmed-shameem@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:56:46 +0530 Subject: [PATCH 03/15] Update database collation related tests (#3066) To obtain the collation related metadata information of a table returning function we were using sp_describe_first_result_set till now. This procedure also returns the system_type_id (oid) of the datatype, which can change (but not an actual issue). As we only aim to obtain the collation related info, updated the test in such a way to obtain expected columns. ###Issues Resolved test_db_collation Signed-off-by: Shameem Ahmed shmeeh@amazon.com --- .../test_db_collation-vu-cleanup.out | 6 +++ .../test_db_collation-vu-prepare.out | 46 +++++++++++++++---- .../expected/test_db_collation-vu-cleanup.out | 6 +++ .../expected/test_db_collation-vu-prepare.out | 46 +++++++++++++++---- .../input/test_db_collation-vu-cleanup.mix | 6 +++ .../input/test_db_collation-vu-prepare.mix | 34 ++++++++++++-- 6 files changed, 123 insertions(+), 21 deletions(-) diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-cleanup.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-cleanup.out index 9c9d9e7225..53b666ee81 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-cleanup.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-cleanup.out @@ -39,6 +39,12 @@ GO DROP INDEX test_db_idx8 on test_db_collation_vu_prepare_db121_columns; GO +DROP VIEW func_output1; +GO + +DROP VIEW func_output2; +GO + DROP VIEW test_db_collation_vu_prepare_db121_v1; GO diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-prepare.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-prepare.out index 04250c445e..53931f4d79 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-prepare.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/test_db_collation-vu-prepare.out @@ -344,21 +344,34 @@ RETURNS TABLE AS RETURN ( - SELECT t1.nv + SELECT t1.nv as col FROM test_db_collation_vu_prepare_db121_t1 t1 INNER JOIN test_db_collation_vu_prepare_db121_t2 t2 ON t1.nv = t2.nv ORDER BY t1.nv ); GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f1()'; +-- Create view to hold the function's output +CREATE VIEW func_output1 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f1(); +GO + +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output1'; GO ~~START~~ -bit#!#int#!#varchar#!#bit#!#int#!#nvarchar#!#smallint#!#tinyint#!#tinyint#!#varchar#!#int#!#varchar#!#varchar#!#varchar#!#nvarchar#!#int#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#varchar#!#varchar#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#bit#!#bit#!#smallint#!#smallint#!#smallint#!#int#!#int#!#int#!#tinyint -0#!#1#!#nv#!#1#!#17084#!#nvarchar#!#-1#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#231#!#-1#!#15729673#!#54 +nvarchar#!#nvarchar +col#!#bbf_unicode_cp1_ci_ai ~~END~~ - CREATE FUNCTION test_db_collation_vu_prepare_db121_f2() RETURNS @res_tab TABLE ( @@ -375,15 +388,30 @@ BEGIN END; GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f2()'; +-- Create view to hold the function's output +CREATE VIEW func_output2 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f2(); +GO + +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output2'; GO ~~START~~ -bit#!#int#!#varchar#!#bit#!#int#!#nvarchar#!#smallint#!#tinyint#!#tinyint#!#varchar#!#int#!#varchar#!#varchar#!#varchar#!#nvarchar#!#int#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#varchar#!#varchar#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#bit#!#bit#!#smallint#!#smallint#!#smallint#!#int#!#int#!#int#!#tinyint -0#!#1#!#col1#!#1#!#17028#!#varchar#!#50#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#167#!#50#!#15729673#!#54 -0#!#2#!#col2#!#1#!#17084#!#nvarchar#!#100#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#231#!#100#!#15729673#!#54 +nvarchar#!#nvarchar +col1#!#bbf_unicode_cp1_ci_ai +col2#!#bbf_unicode_cp1_ci_ai ~~END~~ + CREATE VIEW test_db_collation_vu_prepare_db121_v1 AS SELECT nv FROM test_db_collation_vu_prepare_db121_t1 ORDER BY nv; GO diff --git a/test/JDBC/expected/test_db_collation-vu-cleanup.out b/test/JDBC/expected/test_db_collation-vu-cleanup.out index 3a685dc6ed..60fc00e8c7 100644 --- a/test/JDBC/expected/test_db_collation-vu-cleanup.out +++ b/test/JDBC/expected/test_db_collation-vu-cleanup.out @@ -39,6 +39,12 @@ GO DROP INDEX test_db_idx8 on test_db_collation_vu_prepare_db121_columns; GO +DROP VIEW func_output1; +GO + +DROP VIEW func_output2; +GO + DROP VIEW test_db_collation_vu_prepare_db121_v1; GO diff --git a/test/JDBC/expected/test_db_collation-vu-prepare.out b/test/JDBC/expected/test_db_collation-vu-prepare.out index 335b469666..2d14f41467 100644 --- a/test/JDBC/expected/test_db_collation-vu-prepare.out +++ b/test/JDBC/expected/test_db_collation-vu-prepare.out @@ -348,21 +348,34 @@ RETURNS TABLE AS RETURN ( - SELECT t1.nv + SELECT t1.nv as col FROM test_db_collation_vu_prepare_db121_t1 t1 INNER JOIN test_db_collation_vu_prepare_db121_t2 t2 ON t1.nv = t2.nv ORDER BY t1.nv ); GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f1()'; +-- Create view to hold the function's output +CREATE VIEW func_output1 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f1(); +GO + +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output1'; GO ~~START~~ -bit#!#int#!#varchar#!#bit#!#int#!#nvarchar#!#smallint#!#tinyint#!#tinyint#!#varchar#!#int#!#varchar#!#varchar#!#varchar#!#nvarchar#!#int#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#varchar#!#varchar#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#bit#!#bit#!#smallint#!#smallint#!#smallint#!#int#!#int#!#int#!#tinyint -0#!#1#!#nv#!#1#!#17084#!#nvarchar#!#-1#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#231#!#-1#!#15729673#!#54 +nvarchar#!#nvarchar +col#!#bbf_unicode_cp1_ci_ai ~~END~~ - CREATE FUNCTION test_db_collation_vu_prepare_db121_f2() RETURNS @res_tab TABLE ( @@ -379,15 +392,30 @@ BEGIN END; GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f2()'; +-- Create view to hold the function's output +CREATE VIEW func_output2 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f2(); +GO + +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output2'; GO ~~START~~ -bit#!#int#!#varchar#!#bit#!#int#!#nvarchar#!#smallint#!#tinyint#!#tinyint#!#varchar#!#int#!#varchar#!#varchar#!#varchar#!#nvarchar#!#int#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#varchar#!#varchar#!#varchar#!#varchar#!#varchar#!#bit#!#bit#!#bit#!#bit#!#bit#!#smallint#!#smallint#!#smallint#!#int#!#int#!#int#!#tinyint -0#!#1#!#col1#!#1#!#17028#!#varchar#!#50#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#167#!#50#!#15729673#!#54 -0#!#2#!#col2#!#1#!#17084#!#nvarchar#!#100#!#0#!#0#!#bbf_unicode_cp1_ci_ai#!##!##!##!##!##!##!##!##!##!#0#!#0#!#0#!##!##!##!##!##!#0#!##!#0#!#0#!#0#!##!##!##!#231#!#100#!#15729673#!#54 +nvarchar#!#nvarchar +col1#!#bbf_unicode_cp1_ci_ai +col2#!#bbf_unicode_cp1_ci_ai ~~END~~ + CREATE VIEW test_db_collation_vu_prepare_db121_v1 AS SELECT nv FROM test_db_collation_vu_prepare_db121_t1 ORDER BY nv; GO diff --git a/test/JDBC/input/test_db_collation-vu-cleanup.mix b/test/JDBC/input/test_db_collation-vu-cleanup.mix index 9c9d9e7225..53b666ee81 100644 --- a/test/JDBC/input/test_db_collation-vu-cleanup.mix +++ b/test/JDBC/input/test_db_collation-vu-cleanup.mix @@ -39,6 +39,12 @@ GO DROP INDEX test_db_idx8 on test_db_collation_vu_prepare_db121_columns; GO +DROP VIEW func_output1; +GO + +DROP VIEW func_output2; +GO + DROP VIEW test_db_collation_vu_prepare_db121_v1; GO diff --git a/test/JDBC/input/test_db_collation-vu-prepare.mix b/test/JDBC/input/test_db_collation-vu-prepare.mix index b3139aca47..08d2860fe2 100644 --- a/test/JDBC/input/test_db_collation-vu-prepare.mix +++ b/test/JDBC/input/test_db_collation-vu-prepare.mix @@ -248,15 +248,28 @@ RETURNS TABLE AS RETURN ( - SELECT t1.nv + SELECT t1.nv as col FROM test_db_collation_vu_prepare_db121_t1 t1 INNER JOIN test_db_collation_vu_prepare_db121_t2 t2 ON t1.nv = t2.nv ORDER BY t1.nv ); GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f1()'; +-- Create view to hold the function's output +CREATE VIEW func_output1 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f1(); GO +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output1'; +GO CREATE FUNCTION test_db_collation_vu_prepare_db121_f2() RETURNS @res_tab TABLE @@ -274,9 +287,24 @@ BEGIN END; GO -EXEC sp_describe_first_result_set @tsql = N'SELECT * FROM test_db_collation_vu_prepare_db121_f2()'; +-- Create view to hold the function's output +CREATE VIEW func_output2 AS +SELECT * FROM test_db_collation_vu_prepare_db121_f2(); +GO + +-- Query INFORMATION_SCHEMA to get column information +SELECT + c.COLUMN_NAME, + c.COLLATION_NAME +FROM + INFORMATION_SCHEMA.COLUMNS c +JOIN + INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME +WHERE + v.TABLE_NAME = 'func_output2'; GO + CREATE VIEW test_db_collation_vu_prepare_db121_v1 AS SELECT nv FROM test_db_collation_vu_prepare_db121_t1 ORDER BY nv; GO From e5784b3e9395deb6a2a4e2eef524dd8de192727e Mon Sep 17 00:00:00 2001 From: Yvinayak07 <100944709+Yvinayak07@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:15:46 +0530 Subject: [PATCH 04/15] Changing time difference for non daylight saving period in getdate test file. (#3074) (#3087) As daylight saving period ends minute difference between 'UTC' and 'US/Pacific' is changed from 420 to 480. So changed the time zone from 'US/Pacific' to 'Asia/Kolkata' making it independent from daylight saving period. Issues Resolved getdate tests were failing because of this issue. Task: No-JIRA Signed-off-by: yashneet vinayak --- test/JDBC/expected/getdate-vu-prepare.out | 26 ++++----- test/JDBC/expected/getdate-vu-verify.out | 68 +++++++++++------------ test/JDBC/input/getdate-vu-prepare.sql | 24 ++++---- test/JDBC/input/getdate-vu-verify.mix | 42 +++++++------- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/test/JDBC/expected/getdate-vu-prepare.out b/test/JDBC/expected/getdate-vu-prepare.out index 11e951cc74..561d6391b5 100644 --- a/test/JDBC/expected/getdate-vu-prepare.out +++ b/test/JDBC/expected/getdate-vu-prepare.out @@ -142,11 +142,11 @@ CREATE PROCEDURE dbo.GetSysDatetimeDiff AS BEGIN DECLARE @x datetime2 = SYSDATETIME(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = SYSDATETIME() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -157,11 +157,11 @@ CREATE PROCEDURE dbo.GetSysDatetimeOffsetDiff AS BEGIN DECLARE @x datetime2 = sysdatetimeoffset(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = sysdatetimeoffset() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -172,11 +172,11 @@ CREATE PROCEDURE dbo.GetDateDiff AS BEGIN DECLARE @x datetime2 = getdate(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = getdate() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -187,11 +187,11 @@ CREATE PROCEDURE dbo.GetCurrTimestampDiff AS BEGIN DECLARE @x datetime2 = CURRENT_TIMESTAMP; - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = CURRENT_TIMESTAMP select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -216,14 +216,14 @@ GO DECLARE @sysdatetime1 datetime2, @sysdatetimeoffset1 datetime2, @getdate1 datetime2, @currtimestamp1 datetime2; DECLARE @sysdatetime2 datetime2, @sysdatetimeoffset2 datetime2, @getdate2 datetime2, @currtimestamp2 datetime2; SELECT @sysdatetime1 = SYSDATETIME(), @sysdatetimeoffset1 = sysdatetimeoffset(), @getdate1 = getdate(), @currtimestamp1 = CURRENT_TIMESTAMP; -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); SELECT @sysdatetime2 = SYSDATETIME(), @sysdatetimeoffset2 = sysdatetimeoffset(), @getdate2 = getdate(), @currtimestamp2 = CURRENT_TIMESTAMP; select set_config('timezone', 'UTC', false); -INSERT INTO datetimediffTable values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), 420, -1)) +INSERT INTO datetimediffTable values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), -330, -1)) GO ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -284,9 +284,9 @@ BEGIN DECLARE @sysdatetime1 datetime2, @sysdatetimeoffset1 datetime2, @getdate1 datetime2, @currtimestamp1 datetime2; DECLARE @sysdatetime2 datetime2, @sysdatetimeoffset2 datetime2, @getdate2 datetime2, @currtimestamp2 datetime2; SELECT @sysdatetime1 = SYSDATETIME(), @sysdatetimeoffset1 = sysdatetimeoffset(), @getdate1 = getdate(), @currtimestamp1 = CURRENT_TIMESTAMP; - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); SELECT @sysdatetime2 = SYSDATETIME(), @sysdatetimeoffset2 = sysdatetimeoffset(), @getdate2 = getdate(), @currtimestamp2 = CURRENT_TIMESTAMP; select set_config('timezone', 'UTC', false); - INSERT INTO trgdatetimediffTestTab values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), 420, -1)) + INSERT INTO trgdatetimediffTestTab values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), -330, -1)) END; GO diff --git a/test/JDBC/expected/getdate-vu-verify.out b/test/JDBC/expected/getdate-vu-verify.out index 700ce4d82c..20e1edde9f 100644 --- a/test/JDBC/expected/getdate-vu-verify.out +++ b/test/JDBC/expected/getdate-vu-verify.out @@ -80,18 +80,18 @@ int -- all the tests have datetime difference spillover correction to avoid flakiness. declare @x datetime2 = sysdatetime() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = sysdatetime() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -106,18 +106,18 @@ int declare @x datetime2 = sysdatetimeoffset() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = sysdatetimeoffset() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -132,18 +132,18 @@ int declare @x datetime2 = getdate() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = getdate() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -158,18 +158,18 @@ int declare @x datetime2 = CURRENT_TIMESTAMP -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = CURRENT_TIMESTAMP select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -183,7 +183,7 @@ int ~~END~~ -declare @x datetime2 = sysdatetime() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = sysdatetime() AT TIME ZONE 'India Standard Time' declare @y datetime2 = sysdatetime() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -197,10 +197,10 @@ int ~~END~~ -declare @x datetime2 = sysdatetimeoffset() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = sysdatetimeoffset() AT TIME ZONE 'India Standard Time' declare @y datetime2 = sysdatetimeoffset() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = -420 or @diff = -421 +IF @diff = 330 or @diff = 329 SELECT 1; ELSE SELECT 0; @@ -211,7 +211,7 @@ int ~~END~~ -declare @x datetime2 = getdate() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = getdate() AT TIME ZONE 'India Standard Time' declare @y datetime2 = getdate() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -225,7 +225,7 @@ int ~~END~~ -declare @x datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'India Standard Time' declare @y datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -243,7 +243,7 @@ EXEC dbo.GetSysDatetimeDiff; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -261,7 +261,7 @@ EXEC dbo.GetSysDatetimeOffsetDiff; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -279,7 +279,7 @@ EXEC dbo.GetDateDiff; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -297,7 +297,7 @@ EXEC dbo.GetCurrTimestampDiff; go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -320,13 +320,13 @@ int#!#int#!#int#!#int declare @x datetime2 = SYSDATETIME(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetSysDatetimeDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetSysDatetimeDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -341,13 +341,13 @@ UTC declare @x datetime2 = sysdatetimeoffset(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetSysDatetimeOffsetDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetSysDatetimeOffsetDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -362,13 +362,13 @@ UTC declare @x datetime2 = getdate(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetDateDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetDateDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -383,13 +383,13 @@ UTC declare @x datetime2 = CURRENT_TIMESTAMP; -select set_config('timezone', 'US/Pacific', false); -select dbo.GetCurrTimestampDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetCurrTimestampDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ @@ -407,7 +407,7 @@ INSERT INTO datetimediffTable values (0, 0, 0, 0) go ~~START~~ text -US/Pacific +Asia/Kolkata ~~END~~ ~~START~~ diff --git a/test/JDBC/input/getdate-vu-prepare.sql b/test/JDBC/input/getdate-vu-prepare.sql index 800c7cf795..fcaa8ec1db 100644 --- a/test/JDBC/input/getdate-vu-prepare.sql +++ b/test/JDBC/input/getdate-vu-prepare.sql @@ -142,11 +142,11 @@ CREATE PROCEDURE dbo.GetSysDatetimeDiff AS BEGIN DECLARE @x datetime2 = SYSDATETIME(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = SYSDATETIME() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -157,11 +157,11 @@ CREATE PROCEDURE dbo.GetSysDatetimeOffsetDiff AS BEGIN DECLARE @x datetime2 = sysdatetimeoffset(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = sysdatetimeoffset() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -172,11 +172,11 @@ CREATE PROCEDURE dbo.GetDateDiff AS BEGIN DECLARE @x datetime2 = getdate(); - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = getdate() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -187,11 +187,11 @@ CREATE PROCEDURE dbo.GetCurrTimestampDiff AS BEGIN DECLARE @x datetime2 = CURRENT_TIMESTAMP; - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); DECLARE @y datetime2 = CURRENT_TIMESTAMP select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); - IF @diff = 420 or @diff = 419 + IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; @@ -216,10 +216,10 @@ GO DECLARE @sysdatetime1 datetime2, @sysdatetimeoffset1 datetime2, @getdate1 datetime2, @currtimestamp1 datetime2; DECLARE @sysdatetime2 datetime2, @sysdatetimeoffset2 datetime2, @getdate2 datetime2, @currtimestamp2 datetime2; SELECT @sysdatetime1 = SYSDATETIME(), @sysdatetimeoffset1 = sysdatetimeoffset(), @getdate1 = getdate(), @currtimestamp1 = CURRENT_TIMESTAMP; -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); SELECT @sysdatetime2 = SYSDATETIME(), @sysdatetimeoffset2 = sysdatetimeoffset(), @getdate2 = getdate(), @currtimestamp2 = CURRENT_TIMESTAMP; select set_config('timezone', 'UTC', false); -INSERT INTO datetimediffTable values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), 420, -1)) +INSERT INTO datetimediffTable values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), -330, -1)) GO CREATE VIEW dbo.datetimediffView AS SELECT * FROM datetimediffTable; @@ -272,9 +272,9 @@ BEGIN DECLARE @sysdatetime1 datetime2, @sysdatetimeoffset1 datetime2, @getdate1 datetime2, @currtimestamp1 datetime2; DECLARE @sysdatetime2 datetime2, @sysdatetimeoffset2 datetime2, @getdate2 datetime2, @currtimestamp2 datetime2; SELECT @sysdatetime1 = SYSDATETIME(), @sysdatetimeoffset1 = sysdatetimeoffset(), @getdate1 = getdate(), @currtimestamp1 = CURRENT_TIMESTAMP; - select set_config('timezone', 'US/Pacific', false); + select set_config('timezone', 'Asia/Kolkata', false); SELECT @sysdatetime2 = SYSDATETIME(), @sysdatetimeoffset2 = sysdatetimeoffset(), @getdate2 = getdate(), @currtimestamp2 = CURRENT_TIMESTAMP; select set_config('timezone', 'UTC', false); - INSERT INTO trgdatetimediffTestTab values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), 420, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), 420, -1)) + INSERT INTO trgdatetimediffTestTab values (dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetime2, @sysdatetime1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @sysdatetimeoffset2, @sysdatetimeoffset1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @getdate2, @getdate1), -330, -1), dbo.checkDatetimeDiff(DATEDIFF(MINUTE, @currtimestamp2, @currtimestamp1), -330, -1)) END; GO diff --git a/test/JDBC/input/getdate-vu-verify.mix b/test/JDBC/input/getdate-vu-verify.mix index 871dd77054..9fa3af9a19 100644 --- a/test/JDBC/input/getdate-vu-verify.mix +++ b/test/JDBC/input/getdate-vu-verify.mix @@ -30,50 +30,50 @@ go -- all the tests have datetime difference spillover correction to avoid flakiness. declare @x datetime2 = sysdatetime() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = sysdatetime() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go declare @x datetime2 = sysdatetimeoffset() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = sysdatetimeoffset() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go declare @x datetime2 = getdate() -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = getdate() select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go declare @x datetime2 = CURRENT_TIMESTAMP -select set_config('timezone', 'US/Pacific', false); +select set_config('timezone', 'Asia/Kolkata', false); declare @y datetime2 = CURRENT_TIMESTAMP select set_config('timezone', 'UTC', false); DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = 420 or @diff = 419 +IF @diff = -330 or @diff = -331 SELECT 1; ELSE SELECT 0; go -declare @x datetime2 = sysdatetime() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = sysdatetime() AT TIME ZONE 'India Standard Time' declare @y datetime2 = sysdatetime() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -82,16 +82,16 @@ ELSE SELECT 0; go -declare @x datetime2 = sysdatetimeoffset() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = sysdatetimeoffset() AT TIME ZONE 'India Standard Time' declare @y datetime2 = sysdatetimeoffset() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); -IF @diff = -420 or @diff = -421 +IF @diff = 330 or @diff = 329 SELECT 1; ELSE SELECT 0; go -declare @x datetime2 = getdate() AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = getdate() AT TIME ZONE 'India Standard Time' declare @y datetime2 = getdate() AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -100,7 +100,7 @@ ELSE SELECT 0; go -declare @x datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'Pacific Standard Time' +declare @x datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'India Standard Time' declare @y datetime2 = CURRENT_TIMESTAMP AT TIME ZONE 'UTC' DECLARE @diff int = DATEDIFF(MINUTE, @y, @x); IF @diff = 0 or @diff = -1 @@ -125,26 +125,26 @@ SELECT * from dbo.datetimediffView; go declare @x datetime2 = SYSDATETIME(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetSysDatetimeDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetSysDatetimeDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go declare @x datetime2 = sysdatetimeoffset(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetSysDatetimeOffsetDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetSysDatetimeOffsetDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go declare @x datetime2 = getdate(); -select set_config('timezone', 'US/Pacific', false); -select dbo.GetDateDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetDateDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go declare @x datetime2 = CURRENT_TIMESTAMP; -select set_config('timezone', 'US/Pacific', false); -select dbo.GetCurrTimestampDiffFunc(@x, -420, 1) +select set_config('timezone', 'Asia/Kolkata', false); +select dbo.GetCurrTimestampDiffFunc(@x, 330, 1) select set_config('timezone', 'UTC', false); go From 679063273b80c955174919a301a54e6cebb96df2 Mon Sep 17 00:00:00 2001 From: Rohit bhagat <65351720+rohit01010@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:22:23 +0530 Subject: [PATCH 05/15] use PG_CATALOG.RIGHT in upgrade scripts to mVU issues (#3084) * use PG_CATALOG.RIGHT in upgrade scripts to mVU issues (#3079) use PG_CATALOG.RIGHT in upgrade scripts to fix mVU issues Signed-off-by: Anikait Agrawal Signed-off-by: Rohit Bhagat Co-authored-by: Rohit Bhagat --- contrib/babelfishpg_tsql/sql/information_schema_tsql.sql | 6 +++--- .../sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/information_schema_tsql.sql b/contrib/babelfishpg_tsql/sql/information_schema_tsql.sql index 1a8b76be87..8546f50e23 100644 --- a/contrib/babelfishpg_tsql/sql/information_schema_tsql.sql +++ b/contrib/babelfishpg_tsql/sql/information_schema_tsql.sql @@ -850,7 +850,7 @@ GRANT SELECT ON information_schema_tsql.key_column_usage TO PUBLIC; */ CREATE OR REPLACE VIEW information_schema_tsql.schemata AS SELECT CAST(sys.db_name() AS sys.sysname) AS "CATALOG_NAME", - CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1) + CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN PG_CATALOG.RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1) ELSE np.nspname END AS sys.nvarchar(128)) AS "SCHEMA_NAME", -- For system-defined schemas, schema-owner name will be same as schema_name -- For user-defined schemas having default owner, schema-owner will be dbo @@ -858,8 +858,8 @@ CREATE OR REPLACE VIEW information_schema_tsql.schemata AS -- by owner name, so need to extract the owner name from rolname always. CAST(CASE WHEN sys.bbf_is_shared_schema(np.nspname) = TRUE THEN np.nspname WHEN r.rolname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN - CASE WHEN RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo' - ELSE RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END + CASE WHEN PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo' + ELSE PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END AS sys.nvarchar(128)) AS "SCHEMA_OWNER", CAST(null AS sys.varchar(6)) AS "DEFAULT_CHARACTER_SET_CATALOG", CAST(null AS sys.varchar(3)) AS "DEFAULT_CHARACTER_SET_SCHEMA", diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql index 51b0202cdc..503dabe185 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql @@ -4406,7 +4406,7 @@ GRANT EXECUTE ON PROCEDURE sys.sp_procedure_params_100_managed TO PUBLIC; CREATE OR REPLACE VIEW information_schema_tsql.schemata AS SELECT CAST(sys.db_name() AS sys.sysname) AS "CATALOG_NAME", - CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1) + CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN PG_CATALOG.RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1) ELSE np.nspname END AS sys.nvarchar(128)) AS "SCHEMA_NAME", -- For system-defined schemas, schema-owner name will be same as schema_name -- For user-defined schemas having default owner, schema-owner will be dbo @@ -4414,8 +4414,8 @@ CREATE OR REPLACE VIEW information_schema_tsql.schemata AS -- by owner name, so need to extract the owner name from rolname always. CAST(CASE WHEN sys.bbf_is_shared_schema(np.nspname) = TRUE THEN np.nspname WHEN r.rolname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN - CASE WHEN RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo' - ELSE RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END + CASE WHEN PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo' + ELSE PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END AS sys.nvarchar(128)) AS "SCHEMA_OWNER", CAST(null AS sys.varchar(6)) AS "DEFAULT_CHARACTER_SET_CATALOG", CAST(null AS sys.varchar(3)) AS "DEFAULT_CHARACTER_SET_SCHEMA", From 000d0d9966aa82ae3e674d0b34749b1419f76307 Mon Sep 17 00:00:00 2001 From: Anju Bharti <66729219+anju15bharti@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:13:48 +0530 Subject: [PATCH 06/15] Fix Individual AD crash in TdsSetDbContext (#3101) Earlier we were not assigning value for loginInfo->username in case of AD session. This commit assigns value for loginInfo->username when GSS enabled. Task: BABEL-5380 Signed-off-by: ANJU BHARTI --- contrib/babelfishpg_tds/src/backend/tds/tdslogin.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c b/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c index 089eb1b20c..fc2cbf375c 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c @@ -1614,6 +1614,9 @@ CheckGSSAuth(Port *port) oldContext = MemoryContextSwitchTo(TopMemoryContext); pfree(port->user_name); port->user_name = convertUsernameToCanonicalform(gbuf.value); + + /* Assign canonical form username to loginInfo->username. */ + loginInfo->username = pstrdup(port->user_name); if ((at_pos = strchr(gbuf.value, '@')) != NULL && loginInfo) { /* skip '@' */ From 8a5decd04c5225b451352289d66058aad0d96496 Mon Sep 17 00:00:00 2001 From: Anju Bharti <66729219+anju15bharti@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:45:28 +0530 Subject: [PATCH 07/15] Revert "Block cross-db 'SELECT ... INTO table FROM ...' statement (#2744)" (#3112) This reverts commit 1570cc67db8f76d87d6ac04f9c7340ed2cb899b8. Task: BABEL-4934 Co-authored-by: ANJU BHARTI --- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 16 - test/JDBC/expected/BABEL-CROSS-DB.out | 408 --------------------- test/JDBC/input/BABEL-CROSS-DB.mix | 280 -------------- 3 files changed, 704 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index 7d0c778409..a5e2b2cd10 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -1920,22 +1920,6 @@ class tsqlBuilder : public tsqlCommonMutator if (is_schema_specified) stmt->is_schema_specified = true; - if (is_cross_db) - { - if (ctx->select_statement_standalone() && - ctx->select_statement_standalone()->select_statement() && - ctx->select_statement_standalone()->select_statement()->query_expression() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->INTO() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->table_name()) - { - throw PGErrorWrapperException(ERROR, - ERRCODE_FEATURE_NOT_SUPPORTED, - "cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.", - getLineAndPos(ctx->select_statement_standalone())); - } - } - if (is_compiling_create_function()) { /* select without destination should be blocked. We can use already information about desitnation, which is already processed. */ diff --git a/test/JDBC/expected/BABEL-CROSS-DB.out b/test/JDBC/expected/BABEL-CROSS-DB.out index c57fb1821d..39e9e14917 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/BABEL-CROSS-DB.out @@ -1003,411 +1003,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - --- Repeating tests with AI collated database --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -CREATE DATABASE db_4934_2 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - diff --git a/test/JDBC/input/BABEL-CROSS-DB.mix b/test/JDBC/input/BABEL-CROSS-DB.mix index 65519d0547..05ebc64454 100644 --- a/test/JDBC/input/BABEL-CROSS-DB.mix +++ b/test/JDBC/input/BABEL-CROSS-DB.mix @@ -632,283 +632,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO - -SELECT * INTO t222 FROM master..t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1; -GO - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO master..t222 FROM master..t1; -GO - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - --- Repeating tests with AI collated database --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -CREATE DATABASE db_4934_2 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO - -SELECT * INTO t222 FROM master..t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1; -GO - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO master..t222 FROM master..t1; -GO - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - From d0aa61c0a00a90c8f4ed30911b4c5d913caf4939 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal <54075285+sumitj824@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:16:55 +0530 Subject: [PATCH 08/15] Fix syntax error issue while using [primary] column name in DML/DDL statements (#3131) (#3132) This commit resolves the syntax error issue that occurs when using '[primary]' as a column name in DML and DDL statements. Task: BABEL-5422 Issue: #3127 Signed-off-by: Sumit Jaiswal sumiji@amazon.com --- contrib/babelfishpg_tsql/antlr/TSqlParser.g4 | 1 + test/JDBC/expected/BABEL-5422.out | 205 +++++++++++++++++++ test/JDBC/input/BABEL-5422.sql | 138 +++++++++++++ 3 files changed, 344 insertions(+) create mode 100644 test/JDBC/expected/BABEL-5422.out create mode 100644 test/JDBC/input/BABEL-5422.sql diff --git a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 index 50a974d5d5..79f7f30160 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 @@ -4831,6 +4831,7 @@ keyword | PREDICATE | PREDICT | PRIMARY_ROLE + | PRIMARY_SQBRACKET | PRIOR | PRIORITY | PRIORITY_LEVEL diff --git a/test/JDBC/expected/BABEL-5422.out b/test/JDBC/expected/BABEL-5422.out new file mode 100644 index 0000000000..7762b02e6b --- /dev/null +++ b/test/JDBC/expected/BABEL-5422.out @@ -0,0 +1,205 @@ +-- Create tables +CREATE TABLE babel_5422_table ( + [primary] INT PRIMARY KEY, + Name VARCHAR(50) +); +GO + +CREATE TABLE babel_5422_table2 ( + [PRIMARY] INT, + Age INT +); +GO + +CREATE TABLE #babel_5422_table3 ( + [primary_column] INT, + Age INT +); +GO + +-- Insert sample data +INSERT INTO babel_5422_table ([primary], Name) +VALUES (1, 'John'), (2, 'Jane'), (3, 'Bob'); +GO +~~ROW COUNT: 3~~ + + +INSERT INTO babel_5422_table2 ([primary], Age) +VALUES (1, 25), (3, 30); +GO +~~ROW COUNT: 2~~ + + +INSERT INTO #babel_5422_table3 ([primary_column], Age) +VALUES (1, 30), (3, 40); +GO +~~ROW COUNT: 2~~ + + +-- Aliasing +SELECT [primary] AS PrimaryKey, Name +FROM babel_5422_table; +GO +~~START~~ +int#!#varchar +1#!#John +2#!#Jane +3#!#Bob +~~END~~ + + +SELECT [primary_column] AS [Primary], Age +FROM #babel_5422_table3; +GO +~~START~~ +int#!#int +1#!#30 +3#!#40 +~~END~~ + + +-- Joining Tables +SELECT t1.[primary], t1.Name, t2.Age +FROM babel_5422_table t1 +JOIN babel_5422_table2 t2 ON t1.[primary] = t2.[primary]; +GO +~~START~~ +int#!#varchar#!#int +1#!#John#!#25 +3#!#Bob#!#30 +~~END~~ + + +-- Aggregation +SELECT COUNT([primary]) AS TotalRows +FROM babel_5422_table; +GO +~~START~~ +int +3 +~~END~~ + + +-- Ordering +SELECT * +FROM babel_5422_table +ORDER BY [primary] DESC; +GO +~~START~~ +int#!#varchar +3#!#Bob +2#!#Jane +1#!#John +~~END~~ + + +-- Checking for Existence +IF EXISTS (SELECT 1 FROM babel_5422_table WHERE [primary] = 3) + PRINT 'Row with [primary] = 3 exists'; +ELSE + PRINT 'Row with [primary] = 3 does not exist'; +GO + +-- Using in a CASE Statement +SELECT [primary], + CASE + WHEN [primary] = 1 THEN 'One' + WHEN [primary] = 2 THEN 'Two' + ELSE 'Other' + END AS PrimaryDescription +FROM babel_5422_table; +GO +~~START~~ +int#!#varchar +1#!#One +2#!#Two +3#!#Other +~~END~~ + + +-- Using in a Subquery +SELECT Name +FROM babel_5422_table +WHERE [primary] IN (SELECT [primary] FROM babel_5422_table2); +GO +~~START~~ +varchar +John +Bob +~~END~~ + + +-- Using in a View +CREATE VIEW babel_5422_view +AS +SELECT [primary], Name +FROM babel_5422_table; +GO + +SELECT * FROM babel_5422_view; +GO +~~START~~ +int#!#varchar +1#!#John +2#!#Jane +3#!#Bob +~~END~~ + + +-- Using in a Stored Procedure +CREATE PROCEDURE babel_5422_proc + @PrimaryKey INT +AS +BEGIN + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey; +END +GO + +EXEC babel_5422_proc 2; +GO +~~START~~ +int#!#varchar +2#!#Jane +~~END~~ + + +-- Using in a User-Defined Function +CREATE FUNCTION babel_5422_func + (@PrimaryKey INT) +RETURNS TABLE +AS +RETURN( + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey +) +GO + +SELECT babel_5422_func(3); +GO +~~START~~ +varchar +(3,Bob) +~~END~~ + + +-- Cleanup +DROP FUNCTION babel_5422_func; +GO + +DROP PROCEDURE babel_5422_proc; +GO + +DROP VIEW babel_5422_view; +GO + +DROP TABLE #babel_5422_table3 +GO + +DROP TABLE babel_5422_table2; +GO + +DROP TABLE babel_5422_table; +GO diff --git a/test/JDBC/input/BABEL-5422.sql b/test/JDBC/input/BABEL-5422.sql new file mode 100644 index 0000000000..563106433b --- /dev/null +++ b/test/JDBC/input/BABEL-5422.sql @@ -0,0 +1,138 @@ +-- Create tables +CREATE TABLE babel_5422_table ( + [primary] INT PRIMARY KEY, + Name VARCHAR(50) +); +GO + +CREATE TABLE babel_5422_table2 ( + [PRIMARY] INT, + Age INT +); +GO + +CREATE TABLE #babel_5422_table3 ( + [primary_column] INT, + Age INT +); +GO + +-- Insert sample data +INSERT INTO babel_5422_table ([primary], Name) +VALUES (1, 'John'), (2, 'Jane'), (3, 'Bob'); +GO + +INSERT INTO babel_5422_table2 ([primary], Age) +VALUES (1, 25), (3, 30); +GO + +INSERT INTO #babel_5422_table3 ([primary_column], Age) +VALUES (1, 30), (3, 40); +GO + +-- Aliasing +SELECT [primary] AS PrimaryKey, Name +FROM babel_5422_table; +GO + +SELECT [primary_column] AS [Primary], Age +FROM #babel_5422_table3; +GO + +-- Joining Tables +SELECT t1.[primary], t1.Name, t2.Age +FROM babel_5422_table t1 +JOIN babel_5422_table2 t2 ON t1.[primary] = t2.[primary]; +GO + +-- Aggregation +SELECT COUNT([primary]) AS TotalRows +FROM babel_5422_table; +GO + +-- Ordering +SELECT * +FROM babel_5422_table +ORDER BY [primary] DESC; +GO + +-- Checking for Existence +IF EXISTS (SELECT 1 FROM babel_5422_table WHERE [primary] = 3) + PRINT 'Row with [primary] = 3 exists'; +ELSE + PRINT 'Row with [primary] = 3 does not exist'; +GO + +-- Using in a CASE Statement +SELECT [primary], + CASE + WHEN [primary] = 1 THEN 'One' + WHEN [primary] = 2 THEN 'Two' + ELSE 'Other' + END AS PrimaryDescription +FROM babel_5422_table; +GO + +-- Using in a Subquery +SELECT Name +FROM babel_5422_table +WHERE [primary] IN (SELECT [primary] FROM babel_5422_table2); +GO + +-- Using in a View +CREATE VIEW babel_5422_view +AS +SELECT [primary], Name +FROM babel_5422_table; +GO + +SELECT * FROM babel_5422_view; +GO + +-- Using in a Stored Procedure +CREATE PROCEDURE babel_5422_proc + @PrimaryKey INT +AS +BEGIN + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey; +END +GO + +EXEC babel_5422_proc 2; +GO + +-- Using in a User-Defined Function +CREATE FUNCTION babel_5422_func + (@PrimaryKey INT) +RETURNS TABLE +AS +RETURN( + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey +) +GO + +SELECT babel_5422_func(3); +GO + +-- Cleanup +DROP FUNCTION babel_5422_func; +GO + +DROP PROCEDURE babel_5422_proc; +GO + +DROP VIEW babel_5422_view; +GO + +DROP TABLE #babel_5422_table3 +GO + +DROP TABLE babel_5422_table2; +GO + +DROP TABLE babel_5422_table; +GO \ No newline at end of file From 10febb9fa37eeaac973e71dcb76284e7ea001ada Mon Sep 17 00:00:00 2001 From: RUI Date: Fri, 22 Nov 2024 08:02:13 -0800 Subject: [PATCH 09/15] [OSS-ONLY] Update default branch and upgrade-test-configuration (#3145) * Update default branch from BABEL_4_4_STABLE__PG_16_5 to BABEL_4_4_STABLE__PG_16_6. * Update versions from 14.14, 15.9 and 16.5 to 14.15, 15.10 and 16.6 respectively in upgrade-test-configuration. * Rename 14_14/schedule file to 14_15/schedule and 15_9/schedule file to 15_10/schedule. * Bump Babelfish internal version from 16.5 to 16.6. Task: OSS-ONLY Signed-off-by: Rishabh Tanwar Co-authored-by: RUI LUO --- .../install-dependencies/action.yml | 2 +- .../configuration/upgrade-test-configuration.yml | 14 +++++++------- .github/scripts/clone_engine_repo.conf | 2 +- .github/template/version-branch-template.yml | 8 ++++---- .github/workflows/major-version-upgrade.yml | 2 +- .github/workflows/singledb-version-upgrade.yml | 2 +- contrib/babelfishpg_tsql/src/babelfish_version.h | 2 +- test/JDBC/upgrade/{14_14 => 14_15}/schedule | 0 test/JDBC/upgrade/{15_9 => 15_10}/schedule | 0 9 files changed, 16 insertions(+), 16 deletions(-) rename test/JDBC/upgrade/{14_14 => 14_15}/schedule (100%) rename test/JDBC/upgrade/{15_9 => 15_10}/schedule (100%) diff --git a/.github/composite-actions/install-dependencies/action.yml b/.github/composite-actions/install-dependencies/action.yml index c63c54e031..e531d9f8db 100644 --- a/.github/composite-actions/install-dependencies/action.yml +++ b/.github/composite-actions/install-dependencies/action.yml @@ -9,7 +9,7 @@ runs: curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list sudo apt-get update --fix-missing -y - sudo apt-get install uuid-dev openjdk-8-jre libicu-dev libxml2-dev openssl libssl-dev python3-dev libossp-uuid-dev libpq-dev cmake pkg-config g++ build-essential bison mssql-tools unixodbc-dev libsybdb5 freetds-dev freetds-common gdal-bin libgdal-dev libgeos-dev gdb + sudo apt-get install uuid-dev openjdk-8-jre libicu-dev libxml2-dev openssl libssl-dev python3-dev libossp-uuid-dev libpq-dev cmake pkg-config g++ build-essential bison mssql-tools unixodbc-dev libsybdb5 freetds-dev freetds-common gdal-bin libgdal-dev libgeos-dev gdb libkrb5-dev sudo apt install -y ccache sudo apt-get install lcov sudo /usr/sbin/update-ccache-symlinks diff --git a/.github/configuration/upgrade-test-configuration.yml b/.github/configuration/upgrade-test-configuration.yml index 0578fa3f22..8a1e1740bf 100644 --- a/.github/configuration/upgrade-test-configuration.yml +++ b/.github/configuration/upgrade-test-configuration.yml @@ -101,7 +101,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: '14.14', + version: '14.15', upgrade-type: null }, { @@ -125,7 +125,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: 15.9, + version: '15.10', upgrade-type: null }, { @@ -177,11 +177,11 @@ upgrade-version: [{ upgrade-type: null }, { - version: '14.14', + version: '14.15', upgrade-type: major }, { - version: 15.9, + version: '15.10', upgrade-type: major }, { @@ -207,7 +207,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: 15.9, + version: '15.10', upgrade-type: null }, { @@ -220,7 +220,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: 15.9, + version: '15.10', upgrade-type: null }, { @@ -237,7 +237,7 @@ upgrade-version: [{ upgrade-type: null }, { - version: 15.9, + version: '15.10', upgrade-type: minor }, { diff --git a/.github/scripts/clone_engine_repo.conf b/.github/scripts/clone_engine_repo.conf index f79ce46838..836ab9f15e 100644 --- a/.github/scripts/clone_engine_repo.conf +++ b/.github/scripts/clone_engine_repo.conf @@ -1 +1 @@ -DEFAULT_BRANCH=BABEL_4_4_STABLE__PG_16_5 +DEFAULT_BRANCH=BABEL_4_4_STABLE__PG_16_6 diff --git a/.github/template/version-branch-template.yml b/.github/template/version-branch-template.yml index 676cf1d105..a7c65585a7 100644 --- a/.github/template/version-branch-template.yml +++ b/.github/template/version-branch-template.yml @@ -46,8 +46,8 @@ '14.13': engine_branch: BABEL_2_10_STABLE__PG_14_13 extension_branch: BABEL_2_10_STABLE -'14.14': - engine_branch: BABEL_2_11_STABLE__PG_14_14 +'14.15': + engine_branch: BABEL_2_11_STABLE__PG_14_15 extension_branch: BABEL_2_11_STABLE '15.2': engine_branch: BABEL_3_1_STABLE__PG_15_2 @@ -70,8 +70,8 @@ '15.8': engine_branch: BABEL_3_7_STABLE__PG_15_8 extension_branch: BABEL_3_7_STABLE -'15.9': - engine_branch: BABEL_3_8_STABLE__PG_15_9 +'15.10': + engine_branch: BABEL_3_8_STABLE__PG_15_10 extension_branch: BABEL_3_8_STABLE '16.1': engine_branch: BABEL_4_0_STABLE__PG_16_1 diff --git a/.github/workflows/major-version-upgrade.yml b/.github/workflows/major-version-upgrade.yml index 5c50d66b0c..bb3e63eece 100644 --- a/.github/workflows/major-version-upgrade.yml +++ b/.github/workflows/major-version-upgrade.yml @@ -6,7 +6,7 @@ jobs: env: OLD_INSTALL_DIR: psql_source NEW_INSTALL_DIR: psql_target - ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_14 + ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_15 EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE runs-on: ubuntu-20.04 diff --git a/.github/workflows/singledb-version-upgrade.yml b/.github/workflows/singledb-version-upgrade.yml index eebc7a4a64..a298dca264 100644 --- a/.github/workflows/singledb-version-upgrade.yml +++ b/.github/workflows/singledb-version-upgrade.yml @@ -7,7 +7,7 @@ jobs: env: OLD_INSTALL_DIR: psql_source NEW_INSTALL_DIR: psql_target - ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_14 + ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_15 EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE runs-on: ubuntu-20.04 diff --git a/contrib/babelfishpg_tsql/src/babelfish_version.h b/contrib/babelfishpg_tsql/src/babelfish_version.h index 25179b91c6..4f7878179a 100644 --- a/contrib/babelfishpg_tsql/src/babelfish_version.h +++ b/contrib/babelfishpg_tsql/src/babelfish_version.h @@ -9,6 +9,6 @@ */ #define BABELFISH_VERSION_STR "4.4.0" -#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 16.5.0.0" +#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 16.6.0.0" #define BABEL_COMPATIBILITY_VERSION "12.0.2000.8" #define BABEL_COMPATIBILITY_MAJOR_VERSION "12" diff --git a/test/JDBC/upgrade/14_14/schedule b/test/JDBC/upgrade/14_15/schedule similarity index 100% rename from test/JDBC/upgrade/14_14/schedule rename to test/JDBC/upgrade/14_15/schedule diff --git a/test/JDBC/upgrade/15_9/schedule b/test/JDBC/upgrade/15_10/schedule similarity index 100% rename from test/JDBC/upgrade/15_9/schedule rename to test/JDBC/upgrade/15_10/schedule From 4b2a4386e909979a936cded6f0268c11b9132f9f Mon Sep 17 00:00:00 2001 From: Rishabh Tanwar <33982749+rishabhtanwar29@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:16:29 +0530 Subject: [PATCH 10/15] [OSS-ONLY] Login with mapped user should not use guest user privileges (#3088) (#3156) Previously, a guest users always remain member of a login even if login has a mapped user in a particular database. Due to this any database user is able to access the objects which are accessible to guest user which is undesirable. Fixed this issue by only keeping one user member of a login at a time, which means, guest will be a member of login only if there is no mapped user to that login otherwise only that mapped user will be a member of login. Task: BABEL-5389 Co-authored-by: Rishabh Tanwar Signed-off-by: Shalini Lohia --- .../babelfishpg_tsql--4.3.0--4.4.0.sql | 11 ++ contrib/babelfishpg_tsql/src/catalog.c | 49 +++-- contrib/babelfishpg_tsql/src/dbcmds.c | 4 +- contrib/babelfishpg_tsql/src/pl_exec-2.c | 4 +- contrib/babelfishpg_tsql/src/pltsql.h | 2 +- contrib/babelfishpg_tsql/src/pltsql_utils.c | 7 +- contrib/babelfishpg_tsql/src/rolecmds.c | 167 ++++++++++++++++-- contrib/babelfishpg_tsql/src/rolecmds.h | 2 +- .../expected/BABEL-CROSS-DB-vu-cleanup.out | 6 + .../expected/BABEL-CROSS-DB-vu-prepare.out | 16 ++ .../expected/BABEL-CROSS-DB-vu-verify.out | 79 +++++++++ test/JDBC/expected/BABEL-USER-vu-cleanup.out | 3 + test/JDBC/expected/BABEL-USER-vu-prepare.out | 3 + test/JDBC/expected/BABEL-USER-vu-verify.out | 43 +++++ .../BABEL_GRANT_CONNECT-vu-cleanup.out | 2 +- .../BABEL_GRANT_CONNECT-vu-prepare.out | 1 - .../BABEL_GRANT_CONNECT-vu-verify.out | 20 ++- .../input/BABEL_GRANT_CONNECT-vu-cleanup.mix | 2 +- .../input/BABEL_GRANT_CONNECT-vu-prepare.sql | 1 - .../input/BABEL_GRANT_CONNECT-vu-verify.mix | 8 + .../ownership/BABEL-CROSS-DB-vu-cleanup.mix | 6 + .../ownership/BABEL-CROSS-DB-vu-prepare.mix | 16 ++ .../ownership/BABEL-CROSS-DB-vu-verify.mix | 57 ++++++ .../input/ownership/BABEL-USER-vu-cleanup.sql | 3 + .../input/ownership/BABEL-USER-vu-prepare.sql | 3 + .../input/ownership/BABEL-USER-vu-verify.mix | 27 +++ .../expected_drop.out | 1 + 27 files changed, 502 insertions(+), 41 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql index 503dabe185..8c7f527939 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.3.0--4.4.0.sql @@ -37,6 +37,17 @@ LANGUAGE plpgsql; * So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting * final behaviour. */ + +-- This is a temporary procedure which is only meant to be called during upgrade +CREATE OR REPLACE PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins() +LANGUAGE C +AS 'babelfishpg_tsql', 'revoke_guest_from_mapped_logins'; + +CALL sys.babelfish_revoke_guest_from_mapped_logins(); + +-- Drop this procedure after it gets executed once. +DROP PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins(); + DO $$ DECLARE exception_message text; diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 6501c09b61..6ff59753fb 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -943,10 +943,10 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login) { Relation bbf_authid_user_ext_rel; HeapTuple tuple_user_ext; - ScanKeyData key[3]; TableScanDesc scan; char *user_name = NULL; NameData *login_name; + ScanKeyData key[2]; if (!db_name || !login) return NULL; @@ -956,20 +956,16 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login) login_name = (NameData *) palloc0(NAMEDATALEN); snprintf(login_name->data, NAMEDATALEN, "%s", login); + ScanKeyInit(&key[0], - Anum_bbf_authid_user_ext_login_name, - BTEqualStrategyNumber, F_NAMEEQ, - NameGetDatum(login_name)); + Anum_bbf_authid_user_ext_login_name, + BTEqualStrategyNumber, F_NAMEEQ, + NameGetDatum(login_name)); ScanKeyInit(&key[1], - Anum_bbf_authid_user_ext_database_name, - BTEqualStrategyNumber, F_TEXTEQ, - CStringGetTextDatum(db_name)); - ScanKeyInit(&key[2], - Anum_bbf_authid_user_ext_user_can_connect, - BTEqualStrategyNumber, F_INT4EQ, - Int32GetDatum(1)); - - scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 3, key); + Anum_bbf_authid_user_ext_database_name, + BTEqualStrategyNumber, F_TEXTEQ, + CStringGetTextDatum(db_name)); + scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 2, key); tuple_user_ext = heap_getnext(scan, ForwardScanDirection); if (HeapTupleIsValid(tuple_user_ext)) @@ -1074,6 +1070,28 @@ get_authid_user_ext_db_users(const char *db_name) return db_users_list; } +/* Checks if the user is enabled on a given database. */ +static bool +user_has_dbaccess(const char *user) +{ + HeapTuple tuple; + bool has_access = false; + tuple = SearchSysCache1(AUTHIDUSEREXTROLENAME, CStringGetDatum(user)); + + if (HeapTupleIsValid(tuple)) + { + bool isnull = true; + int user_can_connect = 0; + Datum datum = SysCacheGetAttr(AUTHIDUSEREXTROLENAME, tuple, Anum_bbf_authid_user_ext_user_can_connect, &isnull); + Assert(!isnull); + user_can_connect = DatumGetInt32(datum); + if (user_can_connect == 1) + has_access = true; + ReleaseSysCache(tuple); + } + return has_access; +} + /* * Checks if there exists any user for respective database and login, * if there is not any then use dbo or guest user. @@ -1091,6 +1109,9 @@ get_user_for_database(const char *db_name) user = get_authid_user_ext_physical_name(db_name, login); login_is_db_owner = 0 == strncmp(login, get_owner_of_db(db_name), NAMEDATALEN); + if (user && !user_has_dbaccess(user) && !guest_has_dbaccess((char *) db_name)) + user = NULL; + if (!user) { Oid datdba; @@ -3139,7 +3160,7 @@ create_guest_role_for_db(const char *dbname) if (list_length(logins) > 0) { stmt = parsetree_nth_stmt(res, i++); - update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins); + update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL); } GetUserIdAndSecContext(&save_userid, &save_sec_context); diff --git a/contrib/babelfishpg_tsql/src/dbcmds.c b/contrib/babelfishpg_tsql/src/dbcmds.c index 4a8f39637e..4c1cbf12f9 100644 --- a/contrib/babelfishpg_tsql/src/dbcmds.c +++ b/contrib/babelfishpg_tsql/src/dbcmds.c @@ -167,7 +167,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner) /* Grant dbo role to owner */ stmt = parsetree_nth_stmt(res, i++); update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(dbo)), - list_make1(make_rolespec_node(owner))); + list_make1(make_rolespec_node(owner)), NULL); } if (guest) @@ -178,7 +178,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner) if (list_length(logins) > 0) { stmt = parsetree_nth_stmt(res, i++); - update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins); + update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL); } } diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 7e0750eef3..e8ba8f3c74 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -3908,10 +3908,10 @@ exec_stmt_change_dbowner(PLtsql_execstate *estate, PLtsql_stmt_change_dbowner *s SetUserIdAndSecContext(get_bbf_role_admin_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); /* Revoke dbo role from the previous owner */ - grant_revoke_dbo_to_login(get_owner_of_db(stmt->db_name), stmt->db_name, false); + grant_revoke_role_to_login(get_owner_of_db(stmt->db_name), get_dbo_role_name(stmt->db_name), NULL, false); /* Grant dbo role to the new owner */ - grant_revoke_dbo_to_login(stmt->new_owner_name, stmt->db_name, true); + grant_revoke_role_to_login(stmt->new_owner_name, get_dbo_role_name(stmt->db_name), NULL, true); update_db_owner(stmt->new_owner_name, stmt->db_name); } PG_FINALLY(); diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index f5453319c4..2bfbc07766 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -2168,7 +2168,7 @@ extern void update_CreateSchemaStmt(Node *n, const char *schemaname, const char extern void update_DropOwnedStmt(Node *n, List *role_list); extern void update_DropRoleStmt(Node *n, const char *role); extern void update_DropStmt(Node *n, const char *object); -extern void update_GrantRoleStmt(Node *n, List *privs, List *roles); +extern void update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor); extern void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv); extern void update_RenameStmt(Node *n, const char *old_name, const char *new_name); extern void update_ViewStmt(Node *n, const char *view_schema); diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index d168593ac1..5265477e72 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1082,7 +1082,7 @@ update_DropStmt(Node *n, const char *object) } void -update_GrantRoleStmt(Node *n, List *privs, List *roles) +update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor) { GrantRoleStmt *stmt = (GrantRoleStmt *) n; @@ -1091,6 +1091,11 @@ update_GrantRoleStmt(Node *n, List *privs, List *roles) stmt->granted_roles = privs; stmt->grantee_roles = roles; + + if (grantor && stmt->grantor) + { + stmt->grantor->rolename = pstrdup(grantor); + } } void diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index 136a97b1a4..1a8ba4d4c7 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -439,8 +439,24 @@ drop_bbf_authid_user_ext(ObjectAccessType access, tuple = systable_getnext(scan); if (HeapTupleIsValid(tuple)) + { + bool is_null; + + Datum datum = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + if (!is_null) + { + char *login = NameStr(*DatumGetName(datum)); + + /* Grant guest user to login if it's mapped user is being dropped. */ + if (strlen(login) > 0) + grant_revoke_role_to_login(login, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", true); + } CatalogTupleDelete(bbf_authid_user_ext_rel, &tuple->t_self); + } systable_endscan(scan); table_close(bbf_authid_user_ext_rel, RowExclusiveLock); @@ -550,7 +566,7 @@ grant_guests_to_login(const char *login) /* Update the dummy statement with real values */ stmt = parsetree_nth_stmt(parsetree_list, 0); - update_GrantRoleStmt(stmt, guests, list_make1(make_rolespec_node(login))); + update_GrantRoleStmt(stmt, guests, list_make1(make_rolespec_node(login)), NULL); /* Run the built query */ /* need to make a wrapper PlannedStmt */ @@ -578,20 +594,19 @@ grant_guests_to_login(const char *login) } /* - * Grant/revoke dbo role from the login. + * Grant/revoke given role from the login. + * If grantor is provided then only GRANT/REVOKE specific to it will be affected. * The 'is_grant' flag determines if the action is grant/revoke. */ void -grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) +grant_revoke_role_to_login(const char* login, const char *role_name, const char *grantor, bool is_grant) { StringInfoData query; List *parsetree_list; - List *dbo = NIL; + List *rolelist = NIL; Node *stmt; PlannedStmt *wrapper; - char *dbo_role_name = get_dbo_role_name(db_name); - /* * If login i.e old_owner/new_owner is master user * then skip grant/revoke dbo to login @@ -602,18 +617,22 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) initStringInfo(&query); - dbo = lappend(dbo, make_accesspriv_node(dbo_role_name)); + rolelist = lappend(rolelist, make_accesspriv_node(role_name)); if (is_grant) { /* Build dummy GRANT statement to grant membership to login */ - appendStringInfo(&query, "GRANT dummy TO dummy; "); + appendStringInfo(&query, "GRANT dummy TO dummy"); } else { /* Build dummy REVOKE statement to revoke membership from login */ - appendStringInfo(&query, "REVOKE dummy FROM dummy; "); + appendStringInfo(&query, "REVOKE dummy FROM dummy"); } + if (grantor) + appendStringInfo(&query, " GRANTED BY dummy; "); + else + appendStringInfo(&query, "; "); parsetree_list = raw_parser(query.data, RAW_PARSE_DEFAULT); @@ -625,7 +644,7 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) /* Update the dummy statement with real values */ stmt = parsetree_nth_stmt(parsetree_list, 0); - update_GrantRoleStmt(stmt, dbo, list_make1(make_rolespec_node(login))); + update_GrantRoleStmt(stmt, rolelist, list_make1(make_rolespec_node(login)), grantor); /* Run the built query */ /* need to make a wrapper PlannedStmt */ @@ -638,7 +657,7 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) /* do this step */ ProcessUtility(wrapper, - "(ALTER DATABASE OWNER )", + "GRANT/REVOKE ROLE TO LOGIN", false, PROCESS_UTILITY_SUBCOMMAND, NULL, @@ -650,7 +669,6 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) CommandCounterIncrement(); pfree(query.data); - pfree(dbo_role_name); } static List * @@ -801,7 +819,7 @@ user_name(PG_FUNCTION_ARGS) datum = heap_getattr(tuple, Anum_bbf_authid_user_ext_orig_username, - bbf_authid_user_ext_rel->rd_att, + RelationGetDescr(bbf_authid_user_ext_rel), &is_null); user = pstrdup(TextDatumGetCString(datum)); @@ -1286,8 +1304,32 @@ create_bbf_authid_user_ext(CreateRoleStmt *stmt, bool has_schema, bool has_login if (has_login) { + char *db_name = get_cur_db_name(); + int save_sec_context; + Oid save_userid; + verify_login_for_bbf_authid_user_ext(login); login_name_str = login->rolename; + /* Revoke guest user from login as login now has a mapped user in current database. */ + GetUserIdAndSecContext(&save_userid, &save_sec_context); + PG_TRY(); + { + /* + * Older version before APG16 did not store grantor information. + * After MVU to APG16, the grantor for these GRANTs on older roles + * becomes BOOTSTRAP_SUPERUSER. We need SA privilege to revoke the guest + * membership from these roles. + */ + SetUserIdAndSecContext(get_sa_role_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(db_name), NULL, false); + } + PG_FINALLY(); + { + SetUserIdAndSecContext(save_userid, save_sec_context); + } + PG_END_TRY(); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(db_name), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + pfree(db_name); } /* Add to the catalog table. Adds current database name by default */ @@ -1442,6 +1484,58 @@ add_existing_users_to_catalog(PG_FUNCTION_ARGS) PG_RETURN_INT32(0); } +PG_FUNCTION_INFO_V1(revoke_guest_from_mapped_logins); +Datum +revoke_guest_from_mapped_logins(PG_FUNCTION_ARGS) +{ + Relation bbf_authid_user_ext_rel; + TableScanDesc scan; + HeapTuple tuple; + bool is_null; + + /* We only allow this to be called from an extension's SQL script. */ + if (!creating_extension) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("%s can only be called from an SQL script executed by CREATE/ALTER EXTENSION", + "add_existing_users_to_catalog()"))); + + bbf_authid_user_ext_rel = table_open(get_authid_user_ext_oid(), AccessShareLock); + scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 0, NULL); + tuple = heap_getnext(scan, ForwardScanDirection); + + while (HeapTupleIsValid(tuple)) + { + Datum datum = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + if (!is_null) + { + char *login = NameStr(*DatumGetName(datum)); + + /* Revoke guest user from login as login already has a mapped database user. */ + if (strlen(login) > 0) + { + Datum name = heap_getattr(tuple, + Anum_bbf_authid_user_ext_database_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + + char *db_name = TextDatumGetCString(name); + grant_revoke_role_to_login(login, get_guest_role_name(db_name), NULL, false); + grant_revoke_role_to_login(login, get_guest_role_name(db_name), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + pfree(db_name); + } + } + tuple = heap_getnext(scan, ForwardScanDirection); + } + + table_endscan(scan); + table_close(bbf_authid_user_ext_rel, AccessShareLock); + PG_RETURN_INT32(0); +} + void alter_bbf_authid_user_ext(AlterRoleStmt *stmt) { @@ -1463,6 +1557,7 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) char *new_user_name = NULL; char *physical_name = NULL; char *login_name_str = NULL; + char *old_login_name = NULL; if (sql_dialect != SQL_DIALECT_TSQL) return; @@ -1558,8 +1653,16 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) if (login_name_str) { - namestrcpy(&login_name_str_namedata, login_name_str); + bool is_null; + Datum old_login = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + bbf_authid_user_ext_dsc, + &is_null); + /* Fetch the login name which was previously mapped to this user. */ + if (!is_null) + old_login_name = pstrdup(NameStr(*DatumGetName(old_login))); + namestrcpy(&login_name_str_namedata, login_name_str); new_record_user_ext[USER_EXT_LOGIN_NAME] = NameGetDatum(&login_name_str_namedata); new_record_repl_user_ext[USER_EXT_LOGIN_NAME] = true; } @@ -1580,6 +1683,40 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) table_close(bbf_authid_user_ext_rel, RowExclusiveLock); + if (login_name_str) + { + int save_sec_context; + Oid save_userid; + if (old_login_name && strlen(old_login_name) > 0) + { + /* First revoke this user from old login as the user is being mapped to a new login. */ + grant_revoke_role_to_login(old_login_name, stmt->role->rolename, NULL, false); + grant_revoke_role_to_login(old_login_name, stmt->role->rolename, "bbf_role_admin", false); + /* Now grant guest user to old login as it's mapped user is being removed. */ + grant_revoke_role_to_login(old_login_name, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", true); + } + + /* Revoke guest user from new login as login now has a mapped user in current database. */ + GetUserIdAndSecContext(&save_userid, &save_sec_context); + PG_TRY(); + { + /* + * Older version before APG16 did not store grantor information. + * After MVU to APG16, the grantor for these GRANTs on older roles + * becomes BOOTSTRAP_SUPERUSER. We need SA privilege to revoke the guest + * membership from these roles. + */ + SetUserIdAndSecContext(get_sa_role_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(get_cur_db_name()), NULL, false); + } + PG_FINALLY(); + { + SetUserIdAndSecContext(save_userid, save_sec_context); + } + PG_END_TRY(); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + } + if (new_user_name) { StringInfoData query; @@ -2036,7 +2173,7 @@ has_user_in_db(const char *login, char **db_name) { Datum name = heap_getattr(tuple_user_ext, Anum_bbf_authid_user_ext_database_name, - bbf_authid_user_ext_rel->rd_att, &is_null); + RelationGetDescr(bbf_authid_user_ext_rel), &is_null); *db_name = pstrdup(TextDatumGetCString(name)); diff --git a/contrib/babelfishpg_tsql/src/rolecmds.h b/contrib/babelfishpg_tsql/src/rolecmds.h index e5f9f9db5b..bafe8be680 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.h +++ b/contrib/babelfishpg_tsql/src/rolecmds.h @@ -83,6 +83,6 @@ extern bool windows_domain_contains_invalid_chars(char *input); extern bool check_windows_logon_length(char *input); extern char* get_windows_domain_name(char* input); extern bool windows_domain_is_not_supported(char* domain_name); -extern void grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant); +extern void grant_revoke_role_to_login(const char* login, const char *role_name, const char *grantor, bool is_grant); #endif diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out index 8cd04100a6..867c5cdcf8 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out @@ -39,6 +39,12 @@ GO DROP TABLE babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; GO +DROP TABLE babel_cross_db_vu_prepare_t4; +GO + +DROP LOGIN babel_cross_db_vu_prepare_l3; +GO + DROP FUNCTION babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_f1; GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out index de4fe280eb..5a9cf7047e 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out @@ -263,3 +263,19 @@ GO GRANT EXECUTE ON FUNCTION master_dbo.babel_cross_db_vu_prepare_pg_func to master_babel_cross_db_vu_prepare_u1; GO + +-- tsql +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_prepare_l3 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_prepare_u3 FOR LOGIN babel_cross_db_vu_prepare_l3; +GO + +CREATE TABLE babel_cross_db_vu_prepare_t4 (a INT); +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_t4 TO guest; +GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out index e31bc1dfd8..2e11a0a057 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out @@ -417,6 +417,9 @@ GO ALTER LOGIN babel_cross_db_vu_prepare_l2 with password = '12345678'; GO +ALTER LOGIN babel_cross_db_vu_prepare_l3 with password = '12345678'; +GO + -- tsql user=babel_cross_db_vu_prepare_l1 password=12345678 USE master; GO @@ -673,9 +676,58 @@ int ~~END~~ +create user user_cannot_connect for login babel_cross_db_vu_prepare_l2; +go + +revoke connect from user_cannot_connect; +go + GRANT CONNECT TO guest; GO +grant select on babel_cross_db_vu_prepare_db1_t1 to guest; +go + +-- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 +USE my_babel_cross_db_vu_prepare_db1 +GO + +select current_user +go +~~START~~ +varchar +user_cannot_connect +~~END~~ + + +select has_dbaccess('my_babel_cross_db_vu_prepare_db1'); +go +~~START~~ +int +1 +~~END~~ + + +select * from dbo.babel_cross_db_vu_prepare_db1_t1; -- should not use guest privilege +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_cross_db_vu_prepare_db1_t1)~~ + + +USE master +GO + +-- tsql +USE my_babel_cross_db_vu_prepare_db1 +GO + +revoke select on babel_cross_db_vu_prepare_db1_t1 from guest; +go + +drop user user_cannot_connect; +go + -- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 -- cross-db tests for guest user USE master @@ -714,6 +766,33 @@ int ~~END~~ +-- tsql user=babel_cross_db_vu_prepare_l3 password=12345678 +USE master +GO + +-- login babel_cross_db_vu_prepare_l3 has mapped user in master +-- database so following SELECT should fail. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_cross_db_vu_prepare_t4)~~ + + +-- tsql +-- now moreve mapped user from login babel_cross_db_vu_prepare_l3 in master database +DROP USER babel_cross_db_vu_prepare_u3; +GO + +-- now that login babel_cross_db_vu_prepare_l3 does not have a mapped user in master +-- database so following SELECT should succeed as guest was granted SELECT privilege. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO +~~START~~ +int +~~END~~ + + -- tsql USE master GO diff --git a/test/JDBC/expected/BABEL-USER-vu-cleanup.out b/test/JDBC/expected/BABEL-USER-vu-cleanup.out index 0c17026b74..8a3c125629 100644 --- a/test/JDBC/expected/BABEL-USER-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-USER-vu-cleanup.out @@ -22,5 +22,8 @@ GO DROP LOGIN babel_user_vu_prepare_test5 GO +DROP LOGIN babel_user_vu_prepare_test6 +GO + DROP LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA GO diff --git a/test/JDBC/expected/BABEL-USER-vu-prepare.out b/test/JDBC/expected/BABEL-USER-vu-prepare.out index 0bd1b6d37d..e95650c174 100644 --- a/test/JDBC/expected/BABEL-USER-vu-prepare.out +++ b/test/JDBC/expected/BABEL-USER-vu-prepare.out @@ -13,6 +13,9 @@ GO CREATE LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +CREATE LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + CREATE LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA WITH PASSWORD = 'abc'; GO diff --git a/test/JDBC/expected/BABEL-USER-vu-verify.out b/test/JDBC/expected/BABEL-USER-vu-verify.out index fac3e3f2af..e0b61e3eda 100644 --- a/test/JDBC/expected/BABEL-USER-vu-verify.out +++ b/test/JDBC/expected/BABEL-USER-vu-verify.out @@ -239,6 +239,9 @@ babel_user_vu_prepare_test3#!#babel_user_vu_prepare_sch ALTER LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +ALTER LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + -- tsql user=babel_user_vu_prepare_test5 password=abc SELECT CURRENT_USER; go @@ -258,6 +261,45 @@ t ~~END~~ +-- tsql +-- Now map user babel_user_vu_prepare_test3 to a different login babel_user_vu_prepare_test6 +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test6; +GO + +-- psql +-- Login babel_user_vu_prepare_test5 should no longer be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') +GO +~~START~~ +bool +f +~~END~~ + + +-- Login babel_user_vu_prepare_test6 should be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test6', 'master_babel_user_vu_prepare_test3', 'member') +GO +~~START~~ +bool +t +~~END~~ + + +-- tsql +-- Again map user babel_user_vu_prepare_test3 to login babel_user_vu_prepare_test5 +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test5; +GO + +-- tsql user=babel_user_vu_prepare_test6 password=abc +-- Login babel_user_vu_prepare_test6 should now be mapped to guest user +SELECT CURRENT_USER; +go +~~START~~ +varchar +guest +~~END~~ + + -- tsql -- both of the commands below should fail ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test1; @@ -284,6 +326,7 @@ babel_user_vu_prepare_test2 babel_user_vu_prepare_test3 babel_user_vu_prepare_test4 babel_user_vu_prepare_test5 +babel_user_vu_prepare_test6 master_babel_user_vu_prepare_aacb2aa14e22b38c44e8614f1eae6949f8 master_babel_user_vu_prepare_test1_new master_babel_user_vu_prepare_test2 diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out index 5fcd152d2d..90adad9212 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out @@ -2,7 +2,7 @@ use grant_connect_db1; go -drop user grant_connect_abc +drop user grant_connect_abc_new go drop table grant_connect_t1; diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out index 941da73d0f..672acdf923 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out @@ -9,4 +9,3 @@ go create login grant_connect_abc with password = 'Babel123' go - diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out index 7a9e3c3624..013bbe1c2e 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out @@ -92,6 +92,14 @@ go use grant_connect_db1; go +select has_dbaccess('grant_connect_db1'); +go +~~START~~ +int +1 +~~END~~ + + select user_name(); go ~~START~~ @@ -182,6 +190,9 @@ go grant connect to grant_connect_abc go +ALTER USER grant_connect_abc WITH NAME = grant_connect_abc_new; +go + -- tsql user=grant_connect_abc password=Babel123 -- should succeed because login has a user for grant_connect_db1 and it is enabled use grant_connect_db1 @@ -191,7 +202,14 @@ select user_name(); go ~~START~~ nvarchar -grant_connect_abc +grant_connect_abc_new ~~END~~ +select has_dbaccess('grant_connect_db1'); +go +~~START~~ +int +1 +~~END~~ + diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix index 0bfdbcfd07..68ba8b00e8 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix @@ -2,7 +2,7 @@ use grant_connect_db1; go -drop user grant_connect_abc +drop user grant_connect_abc_new go drop table grant_connect_t1; diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql index 941da73d0f..672acdf923 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql @@ -9,4 +9,3 @@ go create login grant_connect_abc with password = 'Babel123' go - diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix index cf20153912..35441082fc 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix @@ -64,6 +64,9 @@ go use grant_connect_db1; go +select has_dbaccess('grant_connect_db1'); +go + select user_name(); go @@ -128,6 +131,9 @@ go grant connect to grant_connect_abc go +ALTER USER grant_connect_abc WITH NAME = grant_connect_abc_new; +go + -- tsql user=grant_connect_abc password=Babel123 -- should succeed because login has a user for grant_connect_db1 and it is enabled use grant_connect_db1 @@ -136,3 +142,5 @@ go select user_name(); go +select has_dbaccess('grant_connect_db1'); +go diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix index 8cd04100a6..867c5cdcf8 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix @@ -39,6 +39,12 @@ GO DROP TABLE babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; GO +DROP TABLE babel_cross_db_vu_prepare_t4; +GO + +DROP LOGIN babel_cross_db_vu_prepare_l3; +GO + DROP FUNCTION babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_f1; GO diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix index 296e33909e..425e73d24f 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix @@ -259,3 +259,19 @@ GO GRANT EXECUTE ON FUNCTION master_dbo.babel_cross_db_vu_prepare_pg_func to master_babel_cross_db_vu_prepare_u1; GO + +-- tsql +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_prepare_l3 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_prepare_u3 FOR LOGIN babel_cross_db_vu_prepare_l3; +GO + +CREATE TABLE babel_cross_db_vu_prepare_t4 (a INT); +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_t4 TO guest; +GO diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix index 104676e420..19daa84a3b 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix @@ -254,6 +254,9 @@ GO ALTER LOGIN babel_cross_db_vu_prepare_l2 with password = '12345678'; GO +ALTER LOGIN babel_cross_db_vu_prepare_l3 with password = '12345678'; +GO + -- tsql user=babel_cross_db_vu_prepare_l1 password=12345678 USE master; GO @@ -347,9 +350,44 @@ GO SELECT * FROM master.dbo.babel_cross_db_vu_prepare_v1 ORDER BY id; GO +create user user_cannot_connect for login babel_cross_db_vu_prepare_l2; +go + +revoke connect from user_cannot_connect; +go + GRANT CONNECT TO guest; GO +grant select on babel_cross_db_vu_prepare_db1_t1 to guest; +go + +-- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 +USE my_babel_cross_db_vu_prepare_db1 +GO + +select current_user +go + +select has_dbaccess('my_babel_cross_db_vu_prepare_db1'); +go + +select * from dbo.babel_cross_db_vu_prepare_db1_t1; -- should not use guest privilege +go + +USE master +GO + +-- tsql +USE my_babel_cross_db_vu_prepare_db1 +GO + +revoke select on babel_cross_db_vu_prepare_db1_t1 from guest; +go + +drop user user_cannot_connect; +go + -- cross-db tests for guest user -- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 USE master @@ -374,6 +412,25 @@ GO SELECT * FROM dbo.babel_cross_db_vu_prepare_v1 ORDER BY id; GO +-- tsql user=babel_cross_db_vu_prepare_l3 password=12345678 +USE master +GO + +-- login babel_cross_db_vu_prepare_l3 has mapped user in master +-- database so following SELECT should fail. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO + +-- now moreve mapped user from login babel_cross_db_vu_prepare_l3 in master database +-- tsql +DROP USER babel_cross_db_vu_prepare_u3; +GO + +-- now that login babel_cross_db_vu_prepare_l3 does not have a mapped user in master +-- database so following SELECT should succeed as guest was granted SELECT privilege. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO + -- tsql USE master GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql b/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql index 0c17026b74..8a3c125629 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql +++ b/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql @@ -22,5 +22,8 @@ GO DROP LOGIN babel_user_vu_prepare_test5 GO +DROP LOGIN babel_user_vu_prepare_test6 +GO + DROP LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql b/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql index 0bd1b6d37d..e95650c174 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql +++ b/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql @@ -13,6 +13,9 @@ GO CREATE LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +CREATE LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + CREATE LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA WITH PASSWORD = 'abc'; GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix b/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix index c285861236..5503c2306b 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix @@ -102,6 +102,9 @@ GO ALTER LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +ALTER LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + -- tsql user=babel_user_vu_prepare_test5 password=abc SELECT CURRENT_USER; go @@ -111,6 +114,30 @@ go SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') GO +-- Now map user babel_user_vu_prepare_test3 to a different login babel_user_vu_prepare_test6 +-- tsql +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test6; +GO + +-- Login babel_user_vu_prepare_test5 should no longer be a member of user babel_user_vu_prepare_test3 +-- psql +SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') +GO + +-- Login babel_user_vu_prepare_test6 should be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test6', 'master_babel_user_vu_prepare_test3', 'member') +GO + +-- Again map user babel_user_vu_prepare_test3 to login babel_user_vu_prepare_test5 +-- tsql +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test5; +GO + +-- Login babel_user_vu_prepare_test6 should now be mapped to guest user +-- tsql user=babel_user_vu_prepare_test6 password=abc +SELECT CURRENT_USER; +go + -- tsql -- both of the commands below should fail ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test1; diff --git a/test/python/expected/sql_validation_framework/expected_drop.out b/test/python/expected/sql_validation_framework/expected_drop.out index 2bf119eb05..4927d8fc9d 100644 --- a/test/python/expected/sql_validation_framework/expected_drop.out +++ b/test/python/expected/sql_validation_framework/expected_drop.out @@ -72,6 +72,7 @@ Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file b Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_remove_object_from_extension in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_remove_object_from_extension in file babelfishpg_tsql--3.0.0--3.1.0.sql +Unexpected drop found for procedure sys.babelfish_revoke_guest_from_mapped_logins in file babelfishpg_tsql--4.3.0--4.4.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_common--2.2.0--2.3.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_tsql--2.2.0--2.3.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_tsql--2.3.0--3.0.0.sql From 8cafcad9d4ad31ba4ea5964a8fdf203a3b5726a1 Mon Sep 17 00:00:00 2001 From: Sharu Goel <30777678+thephantomthief@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:25:55 +0530 Subject: [PATCH 11/15] Use AccessExclusiveLock for truncating Babelfish catalogs (#3178) When truncating certain Babelfish catalogs, we use the heap_truncate_one_rel function which expects the caller to hold the AccessExclusiveLock on the catalog. This commit updates the lock used for opening/closing the catalog from RowExclusiveLock to AccessExclusiveLock. Task: BABEL-5439 Signed-off-by: Sharu Goel (cherry picked from commit 4ad36c564311be8d2d3be9b43642c643ad16c993) --- contrib/babelfishpg_tsql/src/catalog.c | 4 ++-- contrib/babelfishpg_tsql/src/rolecmds.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 6ff59753fb..3ec187de4e 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -1347,10 +1347,10 @@ void clean_up_bbf_server_def() { /* Fetch the relation */ - Relation bbf_servers_def_rel = table_open(get_bbf_servers_def_oid(), RowExclusiveLock); + Relation bbf_servers_def_rel = table_open(get_bbf_servers_def_oid(), AccessExclusiveLock); /* Truncate the relation */ heap_truncate_one_rel(bbf_servers_def_rel); - table_close(bbf_servers_def_rel, RowExclusiveLock); + table_close(bbf_servers_def_rel, AccessExclusiveLock); } /***************************************** diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index 1a8ba4d4c7..7b57c1058d 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -2525,12 +2525,12 @@ babelfish_truncate_domain_mapping_table_internal(PG_FUNCTION_ARGS) errmsg("Current login %s does not have permission to remove domain mapping entry", GetUserNameFromId(GetSessionUserId(), true)))); - bbf_domain_mapping_rel = table_open(get_bbf_domain_mapping_oid(), RowExclusiveLock); + bbf_domain_mapping_rel = table_open(get_bbf_domain_mapping_oid(), AccessExclusiveLock); /* Truncate the relation */ heap_truncate_one_rel(bbf_domain_mapping_rel); - table_close(bbf_domain_mapping_rel, RowExclusiveLock); + table_close(bbf_domain_mapping_rel, AccessExclusiveLock); return (Datum) 0; } From 194367db9e811e9ca31003d7245676b282ec72fd Mon Sep 17 00:00:00 2001 From: Tanzeel Khan Date: Wed, 23 Oct 2024 13:23:06 +0000 Subject: [PATCH 12/15] add tests for engine changes for BABEL-5335 Signed-off-by: Tanzeel Khan (cherry picked from commit 28e5e7610f09cc008f69be21d60f63e9518765bc) (cherry picked from commit 834f91f0bae175f500ef8e7a5934ba77d35304d1) --- test/JDBC/expected/TestInteropProcedures.out | 129 ++++++++++++++++++ .../TestInteropProcedures.mix | 111 +++++++++++++++ 2 files changed, 240 insertions(+) diff --git a/test/JDBC/expected/TestInteropProcedures.out b/test/JDBC/expected/TestInteropProcedures.out index 240c431590..64302d3c4f 100644 --- a/test/JDBC/expected/TestInteropProcedures.out +++ b/test/JDBC/expected/TestInteropProcedures.out @@ -251,3 +251,132 @@ GO -- psql currentSchema=master_dbo,public DROP PROCEDURE psql_interop_proc GO + + +-- psql currentSchema=master_dbo,public +CREATE FUNCTION pg_stable_func() +RETURNS INT +AS $$ +BEGIN + RETURN (SELECT id FROM t); END; +$$ LANGUAGE plpgsql STABLE; +GO + +CREATE PROCEDURE pg_proc_inner(i INT) +AS $$ +BEGIN + INSERT INTO TEMP VALUES (i); +END; +$$ LANGUAGE plpgsql; +GO + +CREATE OR REPLACE PROCEDURE pg_proc_outer() +AS $$ +BEGIN + BEGIN + UPDATE t SET id = 2; + CALL pg_proc_inner(pg_stable_func()); + EXCEPTION WHEN DIVISION_BY_ZERO THEN + RAISE NOTICE '%', SQLERRM; + END; +END; +$$ LANGUAGE plpgsql; +GO + +-- tsql +CREATE TABLE t(id INT) +GO +CREATE TABLE temp(id INT) +GO +INSERT INTO t VALUES (1) +GO +~~ROW COUNT: 1~~ + + +CREATE PROC ptsql_proc AS EXEC pg_proc_outer; UPDATE t SET id = 1; +GO + + +-- BEGIN TRAN -> tsql proc -> pg_proc_outer -> pg_proc_inner with a plpgsql stable function in argument +BEGIN TRAN +GO +EXEC ptsql_proc +GO +~~ROW COUNT: 1~~ + +COMMIT +GO + +-- tsql proc -> pg_proc_outer -> pg_proc_inner with a plpgsql stable function in argument +-- same test as above but no explicit transaction block +EXEC ptsql_proc +GO +~~ROW COUNT: 1~~ + + + +-- psql currentSchema=master_dbo,public +CREATE FUNCTION pltsql_stable_func() +RETURNS INT +AS $$ +BEGIN + RETURN (SELECT id FROM t); +END; +$$ LANGUAGE PLTSQL STABLE; +GO + +CREATE OR REPLACE PROCEDURE pg_proc_outer() +AS $$ +BEGIN + BEGIN + UPDATE t SET id = 2; + CALL pg_proc_inner(pltsql_stable_func()); + EXCEPTION WHEN DIVISION_BY_ZERO THEN + RAISE NOTICE '%', SQLERRM; + END; +END; +$$ LANGUAGE plpgsql; +GO + +-- tsql +-- BEGIN TRAN -> tsql proc -> pg_proc_outer -> pg_proc_inner with a pltsql stable function in argument +BEGIN TRAN +GO +EXEC ptsql_proc +GO +~~ROW COUNT: 1~~ + +COMMIT +GO + +-- tsql proc -> pg_proc_outer -> pg_proc_inner with a pltsql stable function in argument +-- same test as above but no explicit transaction block +EXEC ptsql_proc +GO +~~ROW COUNT: 1~~ + + +-- we should only see "2" since we always update value before inserting +SELECT * FROM temp +GO +~~START~~ +int +2 +2 +2 +2 +~~END~~ + + +DROP PROCEDURE ptsql_proc +GO + +DROP TABLE t, temp +GO + +-- psql currentSchema=master_dbo,public +DROP PROCEDURE IF EXISTS pg_proc_inner, pg_proc_outer; +GO + +DROP FUNCTION IF EXISTS pg_stable_func, pltsql_stable_func; +GO diff --git a/test/JDBC/input/interoperability/TestInteropProcedures.mix b/test/JDBC/input/interoperability/TestInteropProcedures.mix index 3323d1e960..24363f91f5 100644 --- a/test/JDBC/input/interoperability/TestInteropProcedures.mix +++ b/test/JDBC/input/interoperability/TestInteropProcedures.mix @@ -192,3 +192,114 @@ GO -- psql currentSchema=master_dbo,public DROP PROCEDURE psql_interop_proc GO + + +-- psql currentSchema=master_dbo,public +CREATE FUNCTION pg_stable_func() +RETURNS INT +AS $$ +BEGIN + RETURN (SELECT id FROM t); END; +$$ LANGUAGE plpgsql STABLE; +GO + +CREATE PROCEDURE pg_proc_inner(i INT) +AS $$ +BEGIN + INSERT INTO TEMP VALUES (i); +END; +$$ LANGUAGE plpgsql; +GO + +CREATE OR REPLACE PROCEDURE pg_proc_outer() +AS $$ +BEGIN + BEGIN + UPDATE t SET id = 2; + CALL pg_proc_inner(pg_stable_func()); + EXCEPTION WHEN DIVISION_BY_ZERO THEN + RAISE NOTICE '%', SQLERRM; + END; +END; +$$ LANGUAGE plpgsql; +GO + +-- tsql +CREATE TABLE t(id INT) +GO +CREATE TABLE temp(id INT) +GO +INSERT INTO t VALUES (1) +GO + +CREATE PROC ptsql_proc AS EXEC pg_proc_outer; UPDATE t SET id = 1; +GO + + +-- BEGIN TRAN -> tsql proc -> pg_proc_outer -> pg_proc_inner with a plpgsql stable function in argument +BEGIN TRAN +GO +EXEC ptsql_proc +GO +COMMIT +GO + +-- same test as above but no explicit transaction block +-- tsql proc -> pg_proc_outer -> pg_proc_inner with a plpgsql stable function in argument +EXEC ptsql_proc +GO + + +-- psql currentSchema=master_dbo,public +CREATE FUNCTION pltsql_stable_func() +RETURNS INT +AS $$ +BEGIN + RETURN (SELECT id FROM t); +END; +$$ LANGUAGE PLTSQL STABLE; +GO + +CREATE OR REPLACE PROCEDURE pg_proc_outer() +AS $$ +BEGIN + BEGIN + UPDATE t SET id = 2; + CALL pg_proc_inner(pltsql_stable_func()); + EXCEPTION WHEN DIVISION_BY_ZERO THEN + RAISE NOTICE '%', SQLERRM; + END; +END; +$$ LANGUAGE plpgsql; +GO + +-- tsql +-- BEGIN TRAN -> tsql proc -> pg_proc_outer -> pg_proc_inner with a pltsql stable function in argument +BEGIN TRAN +GO +EXEC ptsql_proc +GO +COMMIT +GO + +-- same test as above but no explicit transaction block +-- tsql proc -> pg_proc_outer -> pg_proc_inner with a pltsql stable function in argument +EXEC ptsql_proc +GO + +-- we should only see "2" since we always update value before inserting +SELECT * FROM temp +GO + +DROP PROCEDURE ptsql_proc +GO + +DROP TABLE t, temp +GO + +-- psql currentSchema=master_dbo,public +DROP PROCEDURE IF EXISTS pg_proc_inner, pg_proc_outer; +GO + +DROP FUNCTION IF EXISTS pg_stable_func, pltsql_stable_func; +GO From 4efeb4b341c3b5be0ad4729e71d0a06ac2844dd7 Mon Sep 17 00:00:00 2001 From: Roshan Kanwar Date: Wed, 4 Dec 2024 19:59:20 +0000 Subject: [PATCH 13/15] Fix test failure for bbf_role_admin_restrictions Signed-off-by: Roshan Kanwar (cherry picked from commit 7c8ac53c6b45f98bc083705457f9ae290dc9a639) --- test/JDBC/expected/bbf_role_admin_restrictions.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/JDBC/expected/bbf_role_admin_restrictions.out b/test/JDBC/expected/bbf_role_admin_restrictions.out index ae3eef5526..78522cd83d 100644 --- a/test/JDBC/expected/bbf_role_admin_restrictions.out +++ b/test/JDBC/expected/bbf_role_admin_restrictions.out @@ -118,7 +118,7 @@ SET SESSION AUTHORIZATION bbf_role_admin; GO ~~ERROR (Code: 0)~~ -~~ERROR (Message: ERROR: permission denied to set session authorization +~~ERROR (Message: ERROR: permission denied to set session authorization "bbf_role_admin" Server SQLState: 42501)~~ @@ -208,7 +208,7 @@ SET SESSION AUTHORIZATION bbf_role_admin; GO ~~ERROR (Code: 0)~~ -~~ERROR (Message: ERROR: permission denied to set session authorization +~~ERROR (Message: ERROR: permission denied to set session authorization "bbf_role_admin" Server SQLState: 42501)~~ From 129f2a39be03ae2fdbec773f60498d78a33ca9e3 Mon Sep 17 00:00:00 2001 From: HarshLunagariya <40052763+HarshLunagariya@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:08:28 +0530 Subject: [PATCH 14/15] Update BABEL-1444 expected files (#3190) After recent engine fixes, setting of role started giving expected output in case of parallel query enabled environment. This commit updates those test files expected output in case of parallel query enabled run. Issues Resolved Task: BABEL-5425 Authored-by: Harsh Lunagariya lunharsh@amazon.com (cherry picked from commit 8b26542a71fbda6d9b0aa7e1008a2fca33fdfd98) --- .../expected/parallel_query/BABEL-1444.out | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/JDBC/expected/parallel_query/BABEL-1444.out b/test/JDBC/expected/parallel_query/BABEL-1444.out index 536c592b21..9821b95dbe 100644 --- a/test/JDBC/expected/parallel_query/BABEL-1444.out +++ b/test/JDBC/expected/parallel_query/BABEL-1444.out @@ -66,7 +66,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -98,7 +98,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +db1_dbo ~~END~~ SELECT current_setting('search_path'); @@ -135,7 +135,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +db1_dbo ~~END~~ SELECT current_setting('search_path'); @@ -168,7 +168,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -200,7 +200,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -233,7 +233,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -271,7 +271,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -303,7 +303,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +db1_dbo ~~END~~ SELECT current_setting('search_path'); @@ -340,7 +340,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +db1_dbo ~~END~~ SELECT current_setting('search_path'); @@ -373,7 +373,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -405,7 +405,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); @@ -438,7 +438,7 @@ SELECT current_setting('role'); GO ~~START~~ text -none +master_dbo ~~END~~ SELECT current_setting('search_path'); From 6a247e5d78e3f62b2f9558c2da84b7cacc19bc36 Mon Sep 17 00:00:00 2001 From: robverschoor Date: Wed, 18 Dec 2024 11:13:56 +0000 Subject: [PATCH 15/15] Revert "Support unary '+' operators for strings (#3013)" This reverts commit 8ad86ff8811ffce2a5ebda1f1ed42196c14229fb. --- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 57 +- .../unary_plus_op_string-vu-cleanup.out | 11 - .../unary_plus_op_string-vu-prepare.out | 76 -- .../unary_plus_op_string-vu-verify.out | 871 ------------------ .../input/unary_plus_op_string-vu-cleanup.sql | 11 - .../input/unary_plus_op_string-vu-prepare.sql | 76 -- .../input/unary_plus_op_string-vu-verify.sql | 250 ----- test/JDBC/upgrade/latest/schedule | 1 - .../expected_dependency.out | 1 + 9 files changed, 7 insertions(+), 1347 deletions(-) delete mode 100644 test/JDBC/expected/unary_plus_op_string-vu-cleanup.out delete mode 100644 test/JDBC/expected/unary_plus_op_string-vu-prepare.out delete mode 100644 test/JDBC/expected/unary_plus_op_string-vu-verify.out delete mode 100644 test/JDBC/input/unary_plus_op_string-vu-cleanup.sql delete mode 100644 test/JDBC/input/unary_plus_op_string-vu-prepare.sql delete mode 100644 test/JDBC/input/unary_plus_op_string-vu-verify.sql diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index a5e2b2cd10..e5b2c2dc1f 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -2483,11 +2483,11 @@ class tsqlBuilder : public tsqlCommonMutator { // Check for comparison operators directly followed by an '@@' variable, like =@@ handleAtAtVarInPredicate(ctx); - } + } void exitUnary_op_expr(TSqlParser::Unary_op_exprContext *ctx) override { handleBitNotOperator(ctx); - } + } void exitPlus_minus_bit_expr(TSqlParser::Plus_minus_bit_exprContext *ctx) override { handleBitOperators(ctx); @@ -3201,7 +3201,10 @@ class tsqlMutator : public TSqlParserBaseListener // Check for comparison operators directly followed by an '@@' variable, like =@@ handleAtAtVarInPredicate(ctx); } - + void exitUnary_op_expr(TSqlParser::Unary_op_exprContext *ctx) override + { + handleBitNotOperator(ctx); + } void exitPlus_minus_bit_expr(TSqlParser::Plus_minus_bit_exprContext *ctx) override { handleBitOperators(ctx); @@ -3210,54 +3213,6 @@ class tsqlMutator : public TSqlParserBaseListener { handleModuloOperator(ctx); } - - void enterUnary_op_expr(TSqlParser::Unary_op_exprContext *ctx) override - { - /* - * The T-SQL grammar allows an arbitrary number of unary '+' operators to precede an expression, - * but PG only supports that for numeric expressions. For string expressions, such a '+' will raise an error in PG. - * In SQL this shows as redundant operators, for example for concatenation: SELECT 'a' ++ 'b'. Expressions - * such as +++(+++@v)) are also valid syntax according to the T-SQL grammar even though they look unusual. - * Here we remove such unary '+' operators, which are redundant anyway. - * However we do not touch numeric constants (e.g. +123) since the '+', although still redundant, may - * have been included for code clarity (e.g. +123 as opposed to -123). - */ - std::string op = getFullText(ctx->op); - if (op.front() == '+') { - auto rhsctx = ctx->expression(); - while (true) { - std::string rhs = getFullText(rhsctx); - if ( - (rhs.front() == '\'') || // single-quoted strings - (rhs.front() == '"') || // both double-quoted strings and double-quoted identifiers - (rhs.front() == '@') || // variables - (rhs.front() == '(') || // bracketed expressions - (rhs.front() == '[') || // bracket-delimited identifiers - (rhs.front() == '_') || // identifiers starting with an underscore - std::isalpha(rhs.front()) // identifiers as well as the N'...' string notation - ) { - stream.setText(ctx->op->getStartIndex(), " "); - break; - } - if (rhs.front() == '+') { - if (dynamic_cast(rhsctx)) { - TSqlParser::Unary_op_exprContext *uctx = static_cast(rhsctx); - op = getFullText(uctx->op); - if (op.front() == '+') { - rhsctx = uctx->expression(); - continue; - } - } - } - break; - } - } - return; - } - void exitUnary_op_expr(TSqlParser::Unary_op_exprContext *ctx) override - { - handleBitNotOperator(ctx); - } }; diff --git a/test/JDBC/expected/unary_plus_op_string-vu-cleanup.out b/test/JDBC/expected/unary_plus_op_string-vu-cleanup.out deleted file mode 100644 index 7101758e59..0000000000 --- a/test/JDBC/expected/unary_plus_op_string-vu-cleanup.out +++ /dev/null @@ -1,11 +0,0 @@ -drop procedure p1_unary_plus_op_string -go - -drop function f1_unary_plus_op_string -go - -drop view v1_unary_plus_op_string -go - -drop table t1_unary_plus_op_string -go diff --git a/test/JDBC/expected/unary_plus_op_string-vu-prepare.out b/test/JDBC/expected/unary_plus_op_string-vu-prepare.out deleted file mode 100644 index fa33ec42ae..0000000000 --- a/test/JDBC/expected/unary_plus_op_string-vu-prepare.out +++ /dev/null @@ -1,76 +0,0 @@ -create table t1_unary_plus_op_string(i int, vc varchar(30)) -go - -create view v1_unary_plus_op_string as -select 'view '+++(+N'value1') + -+ /*comment*/ -( -+ /*comment*/ -+ -- comment + -( -+ -'value2'))++(+(select 'value3')) as col1, -1 + -2 as col2, -1 ++ -2 as col3, -1 + ~2 as col4, -1 +++++ ~2 as col5, -1 ++++ (++++ -2) as col6, -1 ++++ (++++ ~2) as col7 -go - -create procedure p1_unary_plus_op_string -as -declare @v varchar(20) = ' test' -declare @i int = 1 -declare @d datetime='2024-Jan-01 01:02:03' -declare @dc decimal(10,4)=1 -select 'proc '+'line1' -select 'proc '++'line2' -select 'proc '++N'line3' -select 'proc '+++++'line4' -select 'proc '+++++"line5" -select 'proc '+ -+ /*comment*/ -( -+ /*comment*/ -+ -- comment + -( -+ -"line6"))+++@v -select 'proc ' ++(++(++(select N'line7')))++(+@v) -select 'proc ' ++ case when len('a'+++ 'b')=2 then 'true' else 'false' end -select 'proc line8' where 'x' in (+'x') -select 'proc line9' where 'x' like +'x' -set @v = 'x' -select 'proc line10' where 'x' like (+@v) -select 'proc line11' where 'x' like +(+(+@v)) -select 'proc line 12 ' ++ vc from t1_unary_plus_op_string order by 1 -select 'proc line 13 ' ++(+vc) from t1_unary_plus_op_string order by 1 -select 'proc line 14 ' ++ [vc] from t1_unary_plus_op_string order by 1 -select 1 + @i, 2 + (+@i), 3 ++++(++(+++@i)) -select +@d, + (+@d), ++++(++(+++@d)) -select 1 +@dc, 2 + (+@dc), 3 ++++(++(+++@dc)) -select 1 + -2 as expr1 -select 1 ++ -2 as expr2 -select 1 + ~2 as expr3 -select 1 +++++ ~2 as expr4 -select 1 ++++ (++++ -2) as expr5 -select 1 ++++ (++++ ~2) as expr6 -EXECUTE('select ''execimm ''++''line1''') -EXECUTE('select ''execimm ''++N''line2''') -EXECUTE('select ''execimm ''++(+(select N''line3''))') -go - -create function f1_unary_plus_op_string (@v varchar(10)) returns varchar(30) -as -begin -declare @s varchar(30) -set @s = 'func '+++(+N'value1') + -+ -( -+ /*comment*/ -+ -- comment + -(++(select "value2")))++(+@v) -return @s -end -go diff --git a/test/JDBC/expected/unary_plus_op_string-vu-verify.out b/test/JDBC/expected/unary_plus_op_string-vu-verify.out deleted file mode 100644 index 8cc6573193..0000000000 --- a/test/JDBC/expected/unary_plus_op_string-vu-verify.out +++ /dev/null @@ -1,871 +0,0 @@ -insert t1_unary_plus_op_string values (1, 'abc') -go -~~ROW COUNT: 1~~ - - -set quoted_identifier off -go -select 'x'+'y' -go -~~START~~ -varchar -xy -~~END~~ - -select 'x' + 'y' -go -~~START~~ -varchar -xy -~~END~~ - -select 'x' + -/* comment*/ -'y' -/*comment*/ + - 'z' -go -~~START~~ -varchar -xyz -~~END~~ - -select 'x'++'y' -go -~~START~~ -varchar -xy -~~END~~ - -select 'x'++++++++'y' -go -~~START~~ -varchar -xy -~~END~~ - -select 'x'++N'y' -go -~~START~~ -nvarchar -xy -~~END~~ - -select 'x'++++++++N'y' -go -~~START~~ -nvarchar -xy -~~END~~ - -select 'x' ++++++++ 'y' -go -~~START~~ -varchar -xy -~~END~~ - -select 'x' ++ ++ -/* comment*/ + + -'y' ++ -- comment + -/*comment*/ ++ + - ++ 'z' -go -~~START~~ -varchar -xyz -~~END~~ - -declare @v varchar(10)='y' select 'x'+ @v, 'x' +@v, 'x' ++++++@v -go -~~START~~ -varchar#!#varchar#!#varchar -xy#!#xy#!#xy -~~END~~ - -declare @v varchar(10)='y' select 'x'+ (@v), 'x' + (+@v), 'x' ++++(++(+++@v)) -go -~~START~~ -varchar#!#varchar#!#varchar -xy#!#xy#!#xy -~~END~~ - -declare @v tinyint=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -~~START~~ -int#!#int#!#int -2#!#3#!#4 -~~END~~ - -declare @v int=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -~~START~~ -int#!#int#!#int -2#!#3#!#4 -~~END~~ - -declare @v bigint=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -~~START~~ -bigint#!#bigint#!#bigint -2#!#3#!#4 -~~END~~ - -declare @v decimal(10,4)=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -~~START~~ -numeric#!#numeric#!#numeric -2.0000#!#3.0000#!#4.0000 -~~END~~ - -declare @v money=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -~~START~~ -money#!#money#!#money -2.0000#!#3.0000#!#4.0000 -~~END~~ - -declare @v datetime='2024-Jan-01 01:02:03' select +@v, + (+@v), ++++(++(+++@v)) -go -~~START~~ -datetime#!#datetime#!#datetime -2024-01-01 01:02:03.0#!#2024-01-01 01:02:03.0#!#2024-01-01 01:02:03.0 -~~END~~ - -declare @v datetime2='2024-Jan-01 01:02:03' select +@v, + (+@v), ++++(++(+++@v)) -go -~~START~~ -datetime2#!#datetime2#!#datetime2 -2024-01-01 01:02:03.0000000#!#2024-01-01 01:02:03.0000000#!#2024-01-01 01:02:03.0000000 -~~END~~ - -select +'y' -go -~~START~~ -varchar -y -~~END~~ - -select +N'y' -go -~~START~~ -nvarchar -y -~~END~~ - -select ((+'y')) -go -~~START~~ -varchar -y -~~END~~ - -select ((+N'y')) -go -~~START~~ -nvarchar -y -~~END~~ - -select ++++(++++++(+++++'y')) -go -~~START~~ -varchar -y -~~END~~ - -select 'x'+(+'y') -go -~~START~~ -varchar -xy -~~END~~ - -select 'x'+++((+++(+++'y'))) -go -~~START~~ -varchar -xy -~~END~~ - -select 'x'+++( -(+++ -(+++ -'y'))) -go -~~START~~ -varchar -xy -~~END~~ - -if 'x' <> + char(13) select 'true' else select 'false' -go -~~START~~ -varchar -true -~~END~~ - -if 'x' <> +++ char(13) select 'true' else select 'false' -go -~~START~~ -varchar -true -~~END~~ - -select len(+'x') -go -~~START~~ -int -1 -~~END~~ - -select len(+N'x') -go -~~START~~ -int -1 -~~END~~ - -select 'x' ++ substring('xyz', 2, 1) -go -~~START~~ -varchar -xy -~~END~~ - -select 'x' +++++ substring(+'xyz', 2, 1) -go -~~START~~ -varchar -xy -~~END~~ - -select 'x' ++ case when len('a'+++ 'b')=2 then 'true' else 'false' end -go -~~START~~ -varchar -xtrue -~~END~~ - -select 'x' ++ case when len(+'a'+++ 'b')=2 then +'true' else +++++'false' end -go -~~START~~ -varchar -xtrue -~~END~~ - -declare @v varchar(10) = 'true' -select 'x' ++ case when len(+'a'+++ 'b')=2 then +@v else 'false' end -go -~~START~~ -varchar -xtrue -~~END~~ - -select 1 where 'x' in (+'x') -go -~~START~~ -int -1 -~~END~~ - -select 1 where 'x' like +'x' -go -~~START~~ -int -1 -~~END~~ - -declare @v varchar(10) = 'x' -select 1 where 'x' like (+@v) -go -~~START~~ -int -1 -~~END~~ - -declare @v varchar(10) = 'x' -select 1 where 'x' like +(+(+@v)) -go -~~START~~ -int -1 -~~END~~ - -declare @v varchar(10) = 'x' -if 'y' <> + @v select 'true' else select 'false' -go -~~START~~ -varchar -true -~~END~~ - -declare @v varchar(10) = 'x' -if 'y' <> +++ @v select 'true' else select 'false' -set @v = 'x' ++ case when len('a'+++ 'b')=2 then 'true2' else 'false2' end -select @v -go -~~START~~ -varchar -true -~~END~~ - -~~START~~ -varchar -xtrue2 -~~END~~ - -select 'x' ++vc from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - -select 'x' ++(+vc) from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - -select +(select 'abc') -go -~~START~~ -varchar -abc -~~END~~ - -select ++++(select 'abc') -go -~~START~~ -varchar -abc -~~END~~ - -select +(+((select 'abc'))) -go -~~START~~ -varchar -abc -~~END~~ - - -/*double-quoted strings*/ -select "x"+"y" -go -~~START~~ -varchar -xy -~~END~~ - -select "x" + "y" -go -~~START~~ -varchar -xy -~~END~~ - -select "x" + -/* comment*/ -"y" -/*comment*/ + - "z" -go -~~START~~ -varchar -xyz -~~END~~ - -select "x"++"y" -go -~~START~~ -varchar -xy -~~END~~ - -select "x"++++++++"y" -go -~~START~~ -varchar -xy -~~END~~ - -select "x" ++++++++ "y" -go -~~START~~ -varchar -xy -~~END~~ - -select "x" ++ ++ -/* comment*/ + + -"y" ++ -/*comment*/ ++ + - ++ "z" -go -~~START~~ -varchar -xyz -~~END~~ - -declare @v varchar(10)="y" select "x"+ @v, "x" +@v, "x" ++++++@v -go -~~START~~ -varchar#!#varchar#!#varchar -xy#!#xy#!#xy -~~END~~ - -select +"y" -go -~~START~~ -varchar -y -~~END~~ - -select ((+"y")) -go -~~START~~ -varchar -y -~~END~~ - -select ++++(++++++(+++++"y")) -go -~~START~~ -varchar -y -~~END~~ - -select 'x'+(+"y") -go -~~START~~ -varchar -xy -~~END~~ - -select "x"+++((+++(+++"y"))) -go -~~START~~ -varchar -xy -~~END~~ - -select "x"+++( -(+++ -(+++ -"y"))) -go -~~START~~ -varchar -xy -~~END~~ - -if "x" <> + char(13) select "true" else select "false" -go -~~START~~ -varchar -true -~~END~~ - -if "x" <> +++ char(13) select "true" else select "false" -go -~~START~~ -varchar -true -~~END~~ - -select len(+"x") -go -~~START~~ -int -1 -~~END~~ - -select "x" ++ substring("xyz", 2, 1) -go -~~START~~ -varchar -xy -~~END~~ - -select "x" +++++ substring(+"xyz", 2, 1) -go -~~START~~ -varchar -xy -~~END~~ - -select "x" ++ case when len("a"+++ "b")=2 then "true" else "false" end -go -~~START~~ -varchar -xtrue -~~END~~ - -declare @v varchar(10) = "true" -select "x" ++ case when len(+"a"+++ 'b')=2 then +@v else +"false" end -go -~~START~~ -varchar -xtrue -~~END~~ - -select 1 where "x" in (+"x") -go -~~START~~ -int -1 -~~END~~ - -select 1 where "x" like +"x" -go -~~START~~ -int -1 -~~END~~ - -declare @v varchar(10) = "x" -if "y" <> +++ @v select "true" else select "false" -set @v = "x" ++ case when len(++"a"+++N'b')=2 then "true2" else "false2" end -select @v -go -~~START~~ -varchar -true -~~END~~ - -~~START~~ -varchar -xtrue2 -~~END~~ - -select +(+((select "abc"))) -go -~~START~~ -varchar -abc -~~END~~ - - -/* double-quoted identifiers */ -set quoted_identifier on -go -select 'x' ++ "vc" from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - -select 'x' ++((+(++"vc"))) from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - -set quoted_identifier off -go - -/* bracket-delimited identifiers */ -select 'x' ++ [vc] from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - -select 'x' ++ ((+(++[vc]))) from t1_unary_plus_op_string order by 1 -go -~~START~~ -varchar -xabc -~~END~~ - - -/*numeric expressions should not be affected*/ -select 1 +-2 -go -~~START~~ -int --1 -~~END~~ - -select 1 + -2 -go -~~START~~ -int --1 -~~END~~ - -select 1 ++-2 -go -~~START~~ -int --1 -~~END~~ - -select 1 + + -2 -go -~~START~~ -int --1 -~~END~~ - -select 1 + ~2 -go -~~START~~ -int --2 -~~END~~ - -select 1 ++~2 -go -~~START~~ -int --2 -~~END~~ - -select 1 ++ ~2 -go -~~START~~ -int --2 -~~END~~ - -select 1 ++++ (++++ 2) -go -~~START~~ -int -3 -~~END~~ - -select 1 ++++ (++++ ~2) -go -~~START~~ -int --2 -~~END~~ - -select 1 ++++ (++++ -2) -go -~~START~~ -int --1 -~~END~~ - - -/* execute-immediate */ -execute('select ((+''y'')) ') -go -~~START~~ -varchar -y -~~END~~ - -execute('select ''x''+++((+++(+++''y'')))') -go -~~START~~ -varchar -xy -~~END~~ - -execute('select ''x'' ++vc from t1_unary_plus_op_string order by 1') -go -~~START~~ -varchar -xabc -~~END~~ - - -/* SQL objects */ -select * from v1_unary_plus_op_string -go -~~START~~ -nvarchar#!#int#!#int#!#int#!#int#!#int#!#int -view value1value2value3#!#-1#!#-1#!#-2#!#-2#!#-1#!#-2 -~~END~~ - -execute p1_unary_plus_op_string -go -~~START~~ -varchar -proc line1 -~~END~~ - -~~START~~ -varchar -proc line2 -~~END~~ - -~~START~~ -nvarchar -proc line3 -~~END~~ - -~~START~~ -varchar -proc line4 -~~END~~ - -~~START~~ -varchar -proc line5 -~~END~~ - -~~START~~ -varchar -proc line6 test -~~END~~ - -~~START~~ -nvarchar -proc line7 test -~~END~~ - -~~START~~ -varchar -proc true -~~END~~ - -~~START~~ -varchar -proc line8 -~~END~~ - -~~START~~ -varchar -proc line9 -~~END~~ - -~~START~~ -varchar -proc line10 -~~END~~ - -~~START~~ -varchar -proc line11 -~~END~~ - -~~START~~ -varchar -proc line 12 abc -~~END~~ - -~~START~~ -varchar -proc line 13 abc -~~END~~ - -~~START~~ -varchar -proc line 14 abc -~~END~~ - -~~START~~ -int#!#int#!#int -2#!#3#!#4 -~~END~~ - -~~START~~ -datetime#!#datetime#!#datetime -2024-01-01 01:02:03.0#!#2024-01-01 01:02:03.0#!#2024-01-01 01:02:03.0 -~~END~~ - -~~START~~ -numeric#!#numeric#!#numeric -2.0000#!#3.0000#!#4.0000 -~~END~~ - -~~START~~ -int --1 -~~END~~ - -~~START~~ -int --1 -~~END~~ - -~~START~~ -int --2 -~~END~~ - -~~START~~ -int --2 -~~END~~ - -~~START~~ -int --1 -~~END~~ - -~~START~~ -int --2 -~~END~~ - -~~START~~ -varchar -execimm line1 -~~END~~ - -~~START~~ -nvarchar -execimm line2 -~~END~~ - -~~START~~ -nvarchar -execimm line3 -~~END~~ - -select * from dbo.f1_unary_plus_op_string('test') -go -~~START~~ -varchar -func value1value2test -~~END~~ - - -/* the following should raise an error: unary operator other than '+' is invalid for a string in T-SQL */ -select ~'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: ~ unknown)~~ - -select 'x' + ~'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: ~ unknown)~~ - -select 'x' ++ ~'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: ~ unknown)~~ - -select -'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: - unknown)~~ - -select 'x' + -'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: - unknown)~~ - -select 'x' ++ -'y' -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: operator is not unique: - unknown)~~ - diff --git a/test/JDBC/input/unary_plus_op_string-vu-cleanup.sql b/test/JDBC/input/unary_plus_op_string-vu-cleanup.sql deleted file mode 100644 index 20b05cbd91..0000000000 --- a/test/JDBC/input/unary_plus_op_string-vu-cleanup.sql +++ /dev/null @@ -1,11 +0,0 @@ -drop procedure p1_unary_plus_op_string -go - -drop function f1_unary_plus_op_string -go - -drop view v1_unary_plus_op_string -go - -drop table t1_unary_plus_op_string -go \ No newline at end of file diff --git a/test/JDBC/input/unary_plus_op_string-vu-prepare.sql b/test/JDBC/input/unary_plus_op_string-vu-prepare.sql deleted file mode 100644 index fa33ec42ae..0000000000 --- a/test/JDBC/input/unary_plus_op_string-vu-prepare.sql +++ /dev/null @@ -1,76 +0,0 @@ -create table t1_unary_plus_op_string(i int, vc varchar(30)) -go - -create view v1_unary_plus_op_string as -select 'view '+++(+N'value1') + -+ /*comment*/ -( -+ /*comment*/ -+ -- comment + -( -+ -'value2'))++(+(select 'value3')) as col1, -1 + -2 as col2, -1 ++ -2 as col3, -1 + ~2 as col4, -1 +++++ ~2 as col5, -1 ++++ (++++ -2) as col6, -1 ++++ (++++ ~2) as col7 -go - -create procedure p1_unary_plus_op_string -as -declare @v varchar(20) = ' test' -declare @i int = 1 -declare @d datetime='2024-Jan-01 01:02:03' -declare @dc decimal(10,4)=1 -select 'proc '+'line1' -select 'proc '++'line2' -select 'proc '++N'line3' -select 'proc '+++++'line4' -select 'proc '+++++"line5" -select 'proc '+ -+ /*comment*/ -( -+ /*comment*/ -+ -- comment + -( -+ -"line6"))+++@v -select 'proc ' ++(++(++(select N'line7')))++(+@v) -select 'proc ' ++ case when len('a'+++ 'b')=2 then 'true' else 'false' end -select 'proc line8' where 'x' in (+'x') -select 'proc line9' where 'x' like +'x' -set @v = 'x' -select 'proc line10' where 'x' like (+@v) -select 'proc line11' where 'x' like +(+(+@v)) -select 'proc line 12 ' ++ vc from t1_unary_plus_op_string order by 1 -select 'proc line 13 ' ++(+vc) from t1_unary_plus_op_string order by 1 -select 'proc line 14 ' ++ [vc] from t1_unary_plus_op_string order by 1 -select 1 + @i, 2 + (+@i), 3 ++++(++(+++@i)) -select +@d, + (+@d), ++++(++(+++@d)) -select 1 +@dc, 2 + (+@dc), 3 ++++(++(+++@dc)) -select 1 + -2 as expr1 -select 1 ++ -2 as expr2 -select 1 + ~2 as expr3 -select 1 +++++ ~2 as expr4 -select 1 ++++ (++++ -2) as expr5 -select 1 ++++ (++++ ~2) as expr6 -EXECUTE('select ''execimm ''++''line1''') -EXECUTE('select ''execimm ''++N''line2''') -EXECUTE('select ''execimm ''++(+(select N''line3''))') -go - -create function f1_unary_plus_op_string (@v varchar(10)) returns varchar(30) -as -begin -declare @s varchar(30) -set @s = 'func '+++(+N'value1') + -+ -( -+ /*comment*/ -+ -- comment + -(++(select "value2")))++(+@v) -return @s -end -go diff --git a/test/JDBC/input/unary_plus_op_string-vu-verify.sql b/test/JDBC/input/unary_plus_op_string-vu-verify.sql deleted file mode 100644 index 4e2dd49d89..0000000000 --- a/test/JDBC/input/unary_plus_op_string-vu-verify.sql +++ /dev/null @@ -1,250 +0,0 @@ -insert t1_unary_plus_op_string values (1, 'abc') -go - -set quoted_identifier off -go -select 'x'+'y' -go -select 'x' + 'y' -go -select 'x' + -/* comment*/ -'y' -/*comment*/ + - 'z' -go -select 'x'++'y' -go -select 'x'++++++++'y' -go -select 'x'++N'y' -go -select 'x'++++++++N'y' -go -select 'x' ++++++++ 'y' -go -select 'x' ++ ++ -/* comment*/ + + -'y' ++ -- comment + -/*comment*/ ++ + - ++ 'z' -go -declare @v varchar(10)='y' select 'x'+ @v, 'x' +@v, 'x' ++++++@v -go -declare @v varchar(10)='y' select 'x'+ (@v), 'x' + (+@v), 'x' ++++(++(+++@v)) -go -declare @v tinyint=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -declare @v int=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -declare @v bigint=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -declare @v decimal(10,4)=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -declare @v money=1 select 1 +@v, 2 + (+@v), 3 ++++(++(+++@v)) -go -declare @v datetime='2024-Jan-01 01:02:03' select +@v, + (+@v), ++++(++(+++@v)) -go -declare @v datetime2='2024-Jan-01 01:02:03' select +@v, + (+@v), ++++(++(+++@v)) -go -select +'y' -go -select +N'y' -go -select ((+'y')) -go -select ((+N'y')) -go -select ++++(++++++(+++++'y')) -go -select 'x'+(+'y') -go -select 'x'+++((+++(+++'y'))) -go -select 'x'+++( -(+++ -(+++ -'y'))) -go -if 'x' <> + char(13) select 'true' else select 'false' -go -if 'x' <> +++ char(13) select 'true' else select 'false' -go -select len(+'x') -go -select len(+N'x') -go -select 'x' ++ substring('xyz', 2, 1) -go -select 'x' +++++ substring(+'xyz', 2, 1) -go -select 'x' ++ case when len('a'+++ 'b')=2 then 'true' else 'false' end -go -select 'x' ++ case when len(+'a'+++ 'b')=2 then +'true' else +++++'false' end -go -declare @v varchar(10) = 'true' -select 'x' ++ case when len(+'a'+++ 'b')=2 then +@v else 'false' end -go -select 1 where 'x' in (+'x') -go -select 1 where 'x' like +'x' -go -declare @v varchar(10) = 'x' -select 1 where 'x' like (+@v) -go -declare @v varchar(10) = 'x' -select 1 where 'x' like +(+(+@v)) -go -declare @v varchar(10) = 'x' -if 'y' <> + @v select 'true' else select 'false' -go -declare @v varchar(10) = 'x' -if 'y' <> +++ @v select 'true' else select 'false' -set @v = 'x' ++ case when len('a'+++ 'b')=2 then 'true2' else 'false2' end -select @v -go -select 'x' ++vc from t1_unary_plus_op_string order by 1 -go -select 'x' ++(+vc) from t1_unary_plus_op_string order by 1 -go -select +(select 'abc') -go -select ++++(select 'abc') -go -select +(+((select 'abc'))) -go - -/*double-quoted strings*/ -select "x"+"y" -go -select "x" + "y" -go -select "x" + -/* comment*/ -"y" -/*comment*/ + - "z" -go -select "x"++"y" -go -select "x"++++++++"y" -go -select "x" ++++++++ "y" -go -select "x" ++ ++ -/* comment*/ + + -"y" ++ -/*comment*/ ++ + - ++ "z" -go -declare @v varchar(10)="y" select "x"+ @v, "x" +@v, "x" ++++++@v -go -select +"y" -go -select ((+"y")) -go -select ++++(++++++(+++++"y")) -go -select 'x'+(+"y") -go -select "x"+++((+++(+++"y"))) -go -select "x"+++( -(+++ -(+++ -"y"))) -go -if "x" <> + char(13) select "true" else select "false" -go -if "x" <> +++ char(13) select "true" else select "false" -go -select len(+"x") -go -select "x" ++ substring("xyz", 2, 1) -go -select "x" +++++ substring(+"xyz", 2, 1) -go -select "x" ++ case when len("a"+++ "b")=2 then "true" else "false" end -go -declare @v varchar(10) = "true" -select "x" ++ case when len(+"a"+++ 'b')=2 then +@v else +"false" end -go -select 1 where "x" in (+"x") -go -select 1 where "x" like +"x" -go -declare @v varchar(10) = "x" -if "y" <> +++ @v select "true" else select "false" -set @v = "x" ++ case when len(++"a"+++N'b')=2 then "true2" else "false2" end -select @v -go -select +(+((select "abc"))) -go - -/* double-quoted identifiers */ -set quoted_identifier on -go -select 'x' ++ "vc" from t1_unary_plus_op_string order by 1 -go -select 'x' ++((+(++"vc"))) from t1_unary_plus_op_string order by 1 -go -set quoted_identifier off -go - -/* bracket-delimited identifiers */ -select 'x' ++ [vc] from t1_unary_plus_op_string order by 1 -go -select 'x' ++ ((+(++[vc]))) from t1_unary_plus_op_string order by 1 -go - -/*numeric expressions should not be affected*/ -select 1 +-2 -go -select 1 + -2 -go -select 1 ++-2 -go -select 1 + + -2 -go -select 1 + ~2 -go -select 1 ++~2 -go -select 1 ++ ~2 -go -select 1 ++++ (++++ 2) -go -select 1 ++++ (++++ ~2) -go -select 1 ++++ (++++ -2) -go - -/* execute-immediate */ -execute('select ((+''y'')) ') -go -execute('select ''x''+++((+++(+++''y'')))') -go -execute('select ''x'' ++vc from t1_unary_plus_op_string order by 1') -go - -/* SQL objects */ -select * from v1_unary_plus_op_string -go -execute p1_unary_plus_op_string -go -select * from dbo.f1_unary_plus_op_string('test') -go - -/* the following should raise an error: unary operator other than '+' is invalid for a string in T-SQL */ -select ~'y' -go -select 'x' + ~'y' -go -select 'x' ++ ~'y' -go -select -'y' -go -select 'x' + -'y' -go -select 'x' ++ -'y' -go \ No newline at end of file diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 9c7cead2eb..a2d959cef2 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -497,7 +497,6 @@ set_tran_isolvl with_recompile alter_proc_recompile catalogs_dbo_sys_schema-upgrade -unary_plus_op_string BABEL-4217 Test_ISNULL BABEL-4270 diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index db033f06c7..4fc17b04a7 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -795,6 +795,7 @@ Operator sys.+(sys.fixeddecimal,bigint) Operator sys.+(sys.fixeddecimal,integer) Operator sys.+(sys.fixeddecimal,smallint) Operator sys.+(sys.fixeddecimal,sys.fixeddecimal) +Operator sys.+(sys.nvarchar,sys."varchar") Operator sys.+(sys.smallmoney,bigint) Operator sys.+(sys.smallmoney,integer) Operator sys.+(sys.smallmoney,smallint)