Skip to content

Added BBF hook to adjust numeric result to correct scale #565

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

Conversation

rohit01010
Copy link
Contributor

@rohit01010 rohit01010 commented Apr 3, 2025

Description

For Babelfish, the expected behaviour should be for every arithmetic computation which results in numeric datatype, the result should be adjusted(truncated/rounded) to the correct scale. To get this behaviour added hooks at following places to adjust the result value.

  • evaluate_expr() - All the arithmetic computations that result in constant value, happens here. So added a hook to adjust the result after every such arithmetic computation.
  • ExecInterpExpr() - All the arithmetic computations other than mentioned above, happens here. So added a hook to adjust the result after every such arithmetic computation.
  • finalize_aggregate() - For aggregate functions, the final result is computed here, so added a hook to adjust the result for aggregate functions.

Also,

  • for some nodes such as T_OpExpr, T_DistinctExpr, T_CoerceViaIO the result_typmod was directly hardcoded as -1 in PostgreSQL, Added hook pltsql_exprTypmod_hook to compute the typmod of the expression and passed those instead of -1 to avoid losing typmod information.
  • added pltsql_exprTypmod_hook to compute expression typmod for expressions whose typmod is not computed by exprTypmod.
  • During initialisation of resulttype in function ExecInitResultTypeTL added hook ExecUpdateResultTypeTL_hook to set correct typmod of all attributes of result tuple.

Extension PR: babelfish-for-postgresql/babelfish_extensions#3648
Cherry-picked from: #529

Issues Resolved

BABEL-5467

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 PostgreSQL license, 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.

…or-postgresql#529)

For Babelfish, the expected behaviour should be for every arithmetic computation which results in numeric datatype, the result should be adjusted(truncated/rounded) to the correct scale. To get this behaviour added hooks at following places to adjust the result value.

evaluate_expr() - All the arithmetic computations that result in constant value, happens here. So added a hook to adjust the result after every such arithmetic computation.
ExecInterpExpr() - All the arithmetic computations other than mentioned above, happens here. So added a hook to adjust the result after every such arithmetic computation.
finalize_aggregate() - For aggregate functions, the final result is computed here, so added a hook to adjust the result for aggregate functions.
Also,

for some nodes such as T_OpExpr, T_DistinctExpr, T_CoerceViaIO the result_typmod was directly hardcoded as -1 in PostgreSQL, Added hook pltsql_exprTypmod_hook to compute the typmod of the expression and passed those instead of -1 to avoid losing typmod information.
added pltsql_exprTypmod_hook to compute expression typmod for expressions whose typmod is not computed by exprTypmod.
During initialisation of resulttype in function ExecInitResultTypeTL added hook ExecUpdateResultTypeTL_hook to set correct typmod of all attributes of result tuple.
Extension PR: babelfish-for-postgresql/babelfish_extensions#3455

Issues Resolved
BABEL-5467
Copy link

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

Approved.

@jsudrik jsudrik merged commit 1959e62 into babelfish-for-postgresql:BABEL_3_X_DEV__PG_15_X Apr 4, 2025
2 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