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
274 stars 93 forks source link

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

Closed Yvinayak07 closed 4 weeks ago

Yvinayak07 commented 1 month 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 1 month ago

Pull Request Test Coverage Report for Build 10698341164

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_tds/src/backend/tds/tdsutils.c 3 73.8%
contrib/babelfishpg_tsql/src/pl_exec-2.c 3 81.63%
contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c 4 87.13%
contrib/babelfishpg_tsql/src/schemacmds.c 4 92.54%
contrib/babelfishpg_tsql/src/tsqlIface.cpp 10 89.72%
contrib/babelfishpg_tsql/src/hooks.c 14 80.35%
contrib/babelfishpg_tds/src/backend/tds/tdscomm.c 20 76.03%
contrib/babelfishpg_tsql/src/extendedproperty.c 26 94.83%
contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c 35 83.56%
contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c 37 71.45%
<!-- Total: 944 -->
Totals Coverage Status
Change from base Build 10626928379: 0.2%
Covered Lines: 44679
Relevant Lines: 60188

💛 - Coveralls