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

Fixed case expression when one of the branch is NUMERIC and other is of EXACT NUMERIC. #3584

Open
wants to merge 3 commits into
base: BABEL_5_X_DEV
Choose a base branch
from

Conversation

Yvinayak07
Copy link
Contributor

@Yvinayak07 Yvinayak07 commented Mar 18, 2025

Issues

CASE statement doesn't gives correct typmod when one of the branch is numeric and other is of exact numeric. The precision is being set 5 and scale is set to 4 in babelfish.
So expected result (123.0000) won't fit in Numeric(5,4). So we need to figure out correct precision and scale in this case.

SELECT CASE
WHEN 1 = 0 THEN 0.0001
ELSE 123
END;
Expected Result (TSQL): 123.0000
Actual Result (Babelfish): "Msg 33557097, Level 16, State 1, Line 2
numeric field overflow"
2)

Changes made to fix the issues

In the tsql_select_common_typmod hook, allowed exact numeric types for calculating correct precision and scale.

Task: BABEL-5678
Authored-by: yashneet vinayak [email protected]
Signed-off-by: yashneet vinayak [email protected]

Test Scenarios Covered

  • **Use case based -**YES

  • **Boundary conditions -**YES

  • **Arbitrary inputs -**YES

  • **Negative test cases -**YES

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • **Client tests -**YES

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.

yashneet vinayak added 2 commits March 18, 2025 12:22
Signed-off-by: yashneet vinayak <[email protected]>
@coveralls
Copy link
Collaborator

coveralls commented Mar 18, 2025

Pull Request Test Coverage Report for Build 13945425615

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

  • 27 of 27 (100.0%) changed or added relevant lines in 4 files are covered.
  • 444 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.04%) to 74.998%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/pl_handler.c 6 90.37%
contrib/babelfishpg_tsql/src/pltsql_identity.c 13 93.87%
contrib/babelfishpg_tsql/src/dbcmds.c 199 59.29%
contrib/babelfishpg_tsql/src/hooks.c 226 84.01%
Totals Coverage Status
Change from base Build 13917204879: -0.04%
Covered Lines: 47453
Relevant Lines: 63272

💛 - Coveralls

@@ -561,7 +561,7 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
Numeric num;
int64 val;

if ((!(con->consttype == INT4OID) && !is_numeric_datatype(con->consttype)) ||
if ((!(con->consttype == INT8OID) && !(con->consttype == INT4OID) && !(con->consttype == INT2OID) && !is_numeric_datatype(con->consttype)) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we fix this for UDTs as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Case and Union we are handling UDT's before this hook.

@@ -577,7 +577,7 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
* the appropriate typmod. This process ensures correct
* numeric precision handling in Babelfish TSQL operations.
*/
if (plan == NULL && con->consttype == INT4OID)
if (plan == NULL && (con->consttype == INT4OID || con->consttype == INT8OID || con->consttype == INT2OID))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Multi-line

Signed-off-by: yashneet vinayak <[email protected]>
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