Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavioural differences due to return type and handle constant string literal inputs differently for COALESCE function #2533

Merged

Conversation

basasairohan
Copy link
Contributor

Description

Behavioural differences mentioned below have been found out better PG Coalesce and T-SQL Coalesce function.

  1. Consistency in return datatype i.e., for the same set of input datatypes T-SQL should return consistent return datatype as shown in below example
-- T-SQL
select coalesce(cast(8 as smallint), cast(1 as bit))
go
~~START~~
smallint
8
~~END~~
select coalesce(cast(1 as bit), cast(8 as smallint))
go
~~START~~
smallint
1
~~END~~

-- BBF

select coalesce(cast(8 as smallint), cast(1 as bit))
go
~~START~~
smallint
8
~~END~~
select coalesce(cast(1 as bit), cast(8 as smallint))
go
~~START~~
bit
1
~~END~~
  1. When the input is constant string literal i.e., T-SQL should take short circuit evaluation meaning unnecessary arguments should not be evaluated
-- T-SQL
1> SELECT COALESCE(NULL, 1, 2, 'I am a string')
2> go
           
-----------
          1

(1 rows affected)

-- BBF
1> SELECT COALESCE(NULL, 1, 2, 'I am a string')
2> go
Msg 22, Level 16, State 1, Server BABEL, Line 1
invalid input syntax for integer: "I am a string"

This change adds a new function select_common_type_for_coalesce_function to choose the return datatype which will be called from tsql_select_common_type_hook whenever the caller function is T-SQL COALESCE.

Issues Resolved

[BABEL-726]

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

Signed-off-by: Sai Rohan Basa [email protected]

Test Scenarios Covered

  • Use case based - babel_726.sql

  • Boundary conditions - Yes

  • Arbitrary inputs - Yes

  • Negative test cases - Yes

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests - N/A

  • Tooling impact - N/A

  • Client tests - N/A

Check List

  • 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.

Copy link
Contributor

@jsudrik jsudrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cherry pick from the other branch. Approved.

@jsudrik jsudrik merged commit b80c264 into babelfish-for-postgresql:BABEL_2_X_DEV Apr 25, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants