babelfish-for-postgresql / babelfish_extensions

Babelfish for PostgreSQL provides the capability for PostgreSQL to work with applications written for Microsoft SQL Server. Babelfish understands the SQL Server wire-protocol and T-SQL, the Microsoft SQL Server query and procedural language, so you don’t have to switch database drivers or rewrite all of your application queries.
https://babelfishpg.org/
Apache License 2.0
277 stars 93 forks source link

Fixed Cast from sys.varchar to TIME shows unexpected result due to undefined typmod #2898

Closed Yvinayak07 closed 2 months ago

Yvinayak07 commented 2 months ago

1. Issue:

While casting from varchar to TIME, shows unexpected result due to undefined typmod. It was discovered that some test related to TIME fails randomly on arch64 machine and passed on 32 bit machine. For query select cast(cast('12:45:37.123' as varchar) as time); Output :

Expected result : 12:45:37.1230000

Reason: Junk value for arch32 is set to a value greater then 7. So it will read real value till 7, Whereas in arch64 junk value is set to 0. It won't read any value after '.' setting it to zero.

2. Changes made to fix the issues

time_in function was called from varchar2time function with one argument whereas time_in function expects 3 arguments , 3rd one beign the typmod. As this argument was not passed it was picking junk value. This is fixed by calculating tymod in varchar2time and passing correct value of typmod to time_in function. Also added test cases for this purpose.

Task: BABEL-5179 Authored-by: yashneet vinayak yashneet@amazon.com Signed-off-by: yashneet vinayak yashneet@amazon.com

Issues Resolved

Task: BABEL-5179

Test Scenarios Covered

Check List

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10663690371

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/pl_exec-2.c 3 79.82%
contrib/babelfishpg_tds/src/backend/tds/tdscomm.c 19 76.03%
contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c 35 83.56%
contrib/babelfishpg_tsql/src/pltsql_utils.c 46 91.42%
contrib/babelfishpg_tsql/src/pl_handler.c 54 91.36%
contrib/babelfishpg_tds/src/backend/tds/tdsbulkload.c 115 76.16%
contrib/babelfishpg_tsql/src/pltsql_coerce.c 122 80.1%
<!-- Total: 394 -->
Totals Coverage Status
Change from base Build 10616570889: 0.2%
Covered Lines: 42667
Relevant Lines: 57963

💛 - Coveralls