babelfish_extensions icon indicating copy to clipboard operation
babelfish_extensions copied to clipboard

Added wrapper for UPPER() and LOWER() functions for CHAR and NCHAR to handle padding for shorter strings

Open Anikait143 opened this issue 1 year ago • 3 comments

Description

1. Issues

  • UPPER() and LOWER() functions for CHAR or NCHAR types compared to a string shorter than definition cause condition to fail.
  • String functions do not handle chinese characters for NVARCHAR type when collation is not used in UPPER() and LOWER() functions

2. Changes made to fix the issues

  • Added wrapper function handling for UPPER() and LOWER() functions to handle CHAR and NCHAR as VARCHAR and NVARCHAR respectively.
# Input
DECLARE @class NCHAR(2) = N'H'
SELECT '[' + @class + ']' WHERE upper(@class) = N'H'
SELECT '[' + @class + ']' WHERE lower(@class) = N'h'
# previous output (wrong output)               
--------------------

(0 rows affected)
# current output (correct output)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[H ]                                                                                                                                                                                                                                                            

(1 rows affected)
# previous output (wrong output)
1> declare @string1 nvarchar(30) = N'比尔·拉';
2> select UPPER(@string1)
3> GO
@string1                      
------------------------------
??·?  
# current output (correct output)
1> declare @string1 nvarchar(30) = N'比尔·拉';
2> select UPPER(@string1)
3> GO
@string1                      
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
比尔·拉
  • Added Test Cases for these issues

Task: BABEL- 3395 Authored-by: Anikait Agrawal [email protected] Signed-off-by: Anikait Agrawal [email protected]

Test Scenarios Covered

  • Use case based - BABEL-3395-vu-*

  • Boundary conditions -

  • Arbitrary inputs -

  • Negative test cases -

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Memory tests -

  • Client tests -

Check List

  • [x] Commits are signed per the DCO using --signoff

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.

Anikait143 avatar Feb 27 '24 15:02 Anikait143

Pull Request Test Coverage Report for Build 8637308639

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 72.568%

Totals Coverage Status
Change from base Build 8633276413: 0.005%
Covered Lines: 41152
Relevant Lines: 56708

💛 - Coveralls

coveralls avatar Feb 27 '24 20:02 coveralls

Have we verified with other datatypes whether it is hitting the newer version of the function or the older PG one?

1> DECLARE @smalldatetime smalldatetime = '1955-12-13 12:43:10';
2> select CAST(@smalldatetime AS varchar)
3> go

Right missed it earlier, I have now added handling and tests with all other datatypes as well for the newer function definition

Anikait143 avatar Feb 29 '24 12:02 Anikait143

Kindly add newly created test BABEL-3395 in schedule files of upgrades

rohit01010 avatar Apr 09 '24 04:04 rohit01010