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

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

Open
wants to merge 29 commits into
base: BABEL_5_X_DEV__PG_17_X
Choose a base branch
from

Conversation

rohit01010
Copy link
Contributor

@rohit01010 rohit01010 commented Feb 5, 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#3455

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.

Rohit Bhagat added 2 commits February 5, 2025 05:42
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Rohit Bhagat added 2 commits February 5, 2025 06:26
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Rohit Bhagat added 4 commits February 5, 2025 10:49
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Rohit Bhagat added 4 commits February 6, 2025 10:54
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
@@ -762,6 +766,10 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
}
fcinfo->isnull = false;
d = op->d.func.fn_addr(fcinfo);

if (sql_dialect == SQL_DIALECT_TSQL && bbf_trunc_numeric_result_hook)
Copy link
Contributor

@shah-nirmit shah-nirmit Feb 12, 2025

Choose a reason for hiding this comment

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

Question: For every FuncExpr we will enter this hook, extra instructions for every expression evaluation, seems to me it will affect performance

Rohit Bhagat added 9 commits February 12, 2025 11:34
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
…nction

Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
Deepesh125
Deepesh125 previously approved these changes Mar 4, 2025
KushaalShroff
KushaalShroff previously approved these changes Mar 5, 2025
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
@rohit01010 rohit01010 changed the title Added BBF hook to truncate numeric result to correct scale Added BBF hook to adjust numeric result to correct scale Mar 9, 2025
Signed-off-by: Rohit Bhagat <rohitbgt@amazon.com>
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.

6 participants