Skip to content

Commit

Permalink
Resolved jdbc latest schedule file conflict during cherry pick
Browse files Browse the repository at this point in the history
Uninitialized variable fix for ISNUMERIC function with varchar and nvarchar arguments (#2945)

* Fix uninitialised variable issue related to varchar2numeric function

Task: BABEL-5129
Signed-off-by: manisha-deshpande <[email protected]>

* Test cases for isnumeric function with varchar and nvarchar variables

Task: BABEL-5129
Signed-off-by: “manisha-deshpande” <“[email protected]”>

* removing unintended merged commits

Fixing pr comments, added test name to jdbc latest schedule

Task: BABEL-5129
Signed-off-by: “manisha-deshpande” <“[email protected]”>

Fixed issue in SP_TABLES() when @table_name parameter has square brackets around underscore (#2940)

Currently, SP_TABLES procedure does not support wild card [], which matches to any character that is specified in
square bracket. Due to this SP_TABLES procedure returns different output when @table_name parameter value is
table_1 and table[_]1. This issue exists because previously we were using helper function sp_tables_internal whose
body language was plpgsql hence we were using PostgresSQL Like operator for comparison, which does not support
square bracket wild card expression. Fixed the issue by removing this helper function and migrating this function logic
inside the SP_TABLES procedure whose language is pltsql and Like operator in pltsql supports square bracket wild card.

Task: BABEL-4128
Signed-off-by: Rohit Bhagat <[email protected]>

Fix date functions to take into account the timezone setting (#2947)

Issues -

When the timezone parameter group setting is set to something other than the default UTC, Babelfish date
related functions like SYSDATETIME(), SYSDATETIMEOFFSET(), GETDATE() and CURRENT_TIMESTAMP don't take it
into account, while they should. The same issue occurs with a session-level timezone parameter.
SYSDATETIMEOFFSET() function returns datetimeoffset which does not store timezone due to incorrect casting
function.

Changes made to fix the issues -

Added appropriate CAST from TIMESTAMP to respective return types of date functions to ensure proper accounting for
timezone setting. Added timestamptz_datetimeoffset function for converting timestamp with time zone to
datetimeoffset. It ensures to store timezone property similar to timestamptz_datetime2 and timestamptz_datetime
functions.

Task: BABEL-5069
Signed-off-by: Anikait Agrawal <[email protected]>

refactoring (#2951)

Reduce the number of arguments passed to gen_createdb_subcmds & gen_dropdb_subcmds. Create a helper functions to generate RoleSpec & AccessPriv nodes from cstring. Create a new function for inserting fixed roles/users to bbf_authid_user_ext catalog during create database. Remove unused declaration update_RevokeRoleStmt

Issues Resolved: [BABEL-5274]

Signed-off-by: Tanzeel Khan [email protected]

Support Cross-database references in views (#2899)

Support execution of views which references objects (tables/views/functions) from
across the databases. Here we are talking about Babelfish logical database (T-SQL database)
which is different from a physical Postgres database.
To support this, perform permission checks for cross database objects using session user (login)
instead of current_user (user of current T-SQL database). The reason login can be used for
permission check is since login is member of all it’s users, so it inherits all their permissions so it
will be able execute any cross database objects owned by its users.

This commit handles functions and tables/views separately for cross database permission
checks. For functions/procedures, a new hook `ExecFuncProc_AclCheck_hook` and for tables/views
existing `ExecutorStart_hook` will be used to decide whether to use session user or current_user
for permission check depending upon whether the object is from same or different database.
We will be using `is_schema_from_db` function to identify if the object is from different database
which performs a lookup into `babelfish_namespace_ext` catalog table which can be expensive as will
be doing it pretty frequently. So, added this table into SYSCACHE for better performance.
Tables/views permissions are handled slightly different than functions as we do not blindly want to check
the permissions against session user (current login) since permissions of RTEs inside a view are checked
against that view's owner which can very well be a user of some different database. So if we blindly check
permission against session user instead of view's owner then it would break view's ownership chaining.
Instead, we will replace `checkAsUser` with it's corresponding mapped login if present and only in cases
where `checkAsUser` is not set, we will replace it with session user (login). We are using login to allow cross
database queries since login can access all its objects across the databases. Getting mapped login to a
user require lookup into sys.babelfish_authid_user_ext catalog table using its primary key column (rolname) so
added this table is also into SYSCACHE.

Additionally, remove previous code to globally set current user to session user since newer logic
takes care of the permission check now.

Task: BABEL-5206
Signed-off-by: Rishabh Tanwar <[email protected]>

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#434

Revert unintended rebase commits "Support Cross-database references in views (#2899)"

This reverts commit 90a0b1f.

Revert unintended changes "refactoring (#2951)"

This reverts commit 37ce130.

Revert unintended rebase commit "Fix date functions to take into account the timezone setting (#2947)"

This reverts commit 3df9fa0.

Revert unintended rebase commit "Fixed issue in SP_TABLES() when @table_name parameter has square brackets around underscore (#2940)"

This reverts commit 230c433.

* Added null test case

Task: BABEL-5129
Signed-off-by: “manisha-deshpande” <“[email protected]”>

* Added boundary test cases

Signed-off-by: “manisha-deshpande” <“[email protected]”>

---------

Signed-off-by: manisha-deshpande <[email protected]>
Signed-off-by: “manisha-deshpande” <“[email protected]”>
Co-authored-by: “manisha-deshpande” <“[email protected]”>
  • Loading branch information
manisha-deshpande and “manisha-deshpande” committed Oct 1, 2024
1 parent 1b0a48a commit 1a96153
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contrib/babelfishpg_common/src/varchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,10 @@ varchar2numeric(PG_FUNCTION_ARGS)
char *str;

str = varchar2cstring(source);
result = DatumGetNumeric(DirectFunctionCall1(numeric_in, CStringGetDatum(str)));
result = DatumGetNumeric(DirectFunctionCall3(numeric_in,
CStringGetDatum(str),
ObjectIdGetDatum(InvalidOid),
Int32GetDatum(-1)));
pfree(str);
PG_RETURN_NUMERIC(result);
}
Expand Down
2 changes: 2 additions & 0 deletions test/JDBC/expected/BABEL-5129-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE babel_5129
GO
28 changes: 28 additions & 0 deletions test/JDBC/expected/BABEL-5129-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

-- Tests for ISNUMERIC function with varchar and nvarchar variables
CREATE TABLE babel_5129 (
int_type int,
numeric_type numeric(10,5),
money_type money,
varchar_type varchar(20),
nvarchar_type nvarchar(20)
)
GO

INSERT INTO babel_5129 (
int_type,
numeric_type,
money_type,
varchar_type,
nvarchar_type
)
VALUES (
45000,
12345.12,
237891.22,
'12.3420000000',
'12.3420000000'
)
GO
~~ROW COUNT: 1~~

217 changes: 217 additions & 0 deletions test/JDBC/expected/BABEL-5129-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@

-- Tests for ISNUMERIC function with varchar and nvarchar variables
SELECT * FROM babel_5129
GO
~~START~~
int#!#numeric#!#money#!#varchar#!#nvarchar
45000#!#12345.12000#!#237891.2200#!#12.3420000000#!#12.3420000000
~~END~~

-- Test int
SELECT ISNUMERIC(int_type)
FROM babel_5129
GO
~~START~~
int
1
~~END~~

-- Test numeric
SELECT ISNUMERIC(numeric_type)
FROM babel_5129
GO
~~START~~
int
1
~~END~~

-- Test money
SELECT ISNUMERIC(money_type)
FROM babel_5129
GO
~~START~~
int
1
~~END~~

-- Test varchar
SELECT ISNUMERIC(varchar_type)
FROM babel_5129
GO
~~START~~
int
1
~~END~~

-- Test nvarchar
SELECT ISNUMERIC(nvarchar_type)
FROM babel_5129
GO
~~START~~
int
1
~~END~~


-- Test numeric variable
DECLARE @a numeric(24,6);
SELECT @a = 12.3420000000;
SELECT ISNUMERIC(@a), LEN(@a), DATALENGTH(@a)
GO
~~START~~
int#!#int#!#int
1#!#9#!#6
~~END~~


-- Test varchar variable
DECLARE @v varchar(20);
SELECT @v = '12.3420000000';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
1#!#13#!#13
~~END~~


-- Test nvarchar variable
DECLARE @nv nvarchar(10);
SELECT @nv = '12.3420000000';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
1#!#10#!#10
~~END~~


-- Test NULL varchar variable
DECLARE @v varchar(20);
SELECT @v = NULL;
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
0#!#<NULL>#!#<NULL>
~~END~~


-- Test NULL nvarchar variable
DECLARE @nv nvarchar(10);
SELECT @nv = null;
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
0#!#<NULL>#!#<NULL>
~~END~~


-- Test empty varchar variable
DECLARE @v varchar(20);
SELECT @v = '';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
0#!#0#!#0
~~END~~


-- Test empty nvarchar variable
DECLARE @nv nvarchar(10);
SELECT @nv = '';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
0#!#0#!#0
~~END~~


-- Test varchar with number argument that exceeds range of bigint.
DECLARE @v varchar(20);
SELECT @v = '9223372036854775807';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
1#!#19#!#19
~~END~~


DECLARE @v varchar(20);
SELECT @v = '-9223372036854775808';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
1#!#20#!#20
~~END~~


-- Test nvarchar with number argument that exceeds range of bigint.
DECLARE @nv nvarchar(20);
SELECT @nv = '9223372036854775807';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
1#!#19#!#19
~~END~~


DECLARE @nv nvarchar(20);
SELECT @nv = '-9223372036854775808';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
1#!#20#!#20
~~END~~


-- Test varchar with lengthy numeric value
DECLARE @v varchar;
SELECT @v = '12345678901234567890123456789012345';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
1#!#1#!#1
~~END~~


-- Test nvarchar with lengthy numeric value
DECLARE @nv nvarchar;
SELECT @nv = '12345678901234567890123456789012345';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
1#!#1#!#1
~~END~~


-- Test varchar variable with invalid numeric
DECLARE @v varchar(20);
SELECT @v = '12.34.20000000';
SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v)
GO
~~START~~
int#!#int#!#int
0#!#14#!#14
~~END~~


-- Test nvarchar variable with invalid numeric
DECLARE @nv nvarchar(10);
SELECT @nv = '12.34.20000000';
SELECT ISNUMERIC(@nv), LEN(@nv), DATALENGTH(@nv)
GO
~~START~~
int#!#int#!#int
0#!#10#!#10
~~END~~

2 changes: 2 additions & 0 deletions test/JDBC/input/BABEL-5129-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE babel_5129
GO
26 changes: 26 additions & 0 deletions test/JDBC/input/BABEL-5129-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Tests for ISNUMERIC function with varchar and nvarchar variables

CREATE TABLE babel_5129 (
int_type int,
numeric_type numeric(10,5),
money_type money,
varchar_type varchar(20),
nvarchar_type nvarchar(20)
)
GO

INSERT INTO babel_5129 (
int_type,
numeric_type,
money_type,
varchar_type,
nvarchar_type
)
VALUES (
45000,
12345.12,
237891.22,
'12.3420000000',
'12.3420000000'
)
GO
Loading

0 comments on commit 1a96153

Please sign in to comment.