babelfish_extensions icon indicating copy to clipboard operation
babelfish_extensions copied to clipboard

Validate inputs for FLOAT/REAL data types

Open bilalkah opened this issue 3 months ago • 4 comments

Description

T-SQL parity for real/float: reject special literals; add safe casts

  • What: String→real/float casts now reject NaN/Infinity/inf (T-SQL doesn’t allow them). TRY_CAST returns NULL instead of accepting those values. Empty strings cast to 0.
  • Why: Align Babelfish with T-SQL behavior; avoid downstream errors.
  • How (high level):
  • Added validator is_valid_tsql_float and used it in varchar2float4/8, bpchar2float4/8.
  • Registered explicit casts for pg_catalog.VARCHAR/BPCHAR/TEXT → FLOAT4/FLOAT8 via new sys.*2float* functions.
  • Parser/coercion: route TRY_CAST(... AS real|float(p)); float(p) uses real for 1..24, float8 otherwise.
  • Exposed is_tsql_real_datatype / is_tsql_float_datatype via common utility plugin.
  • Added upgrade scripts to install new casts/functions.

Issues Resolved

https://github.com/babelfish-for-postgresql/babelfish_extensions/issues/4028

Test Scenarios Covered

  • CAST('' AS real) → 0; CAST('Infinity' AS float) → error
  • TRY_CAST('NaN' AS real) → NULL
  • TRY_CAST('123' AS float(24)) → real; float(25) → float8
  • Whitespace/exponent forms accepted; non-numeric strings error (or NULL via TRY_CAST)

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.

bilalkah avatar Sep 10 '25 11:09 bilalkah

Pull Request Test Coverage Report for Build 18575071680

Details

  • 73 of 79 (92.41%) changed or added relevant lines in 4 files are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.04%) to 76.685%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/pltsql_coerce.c 12 13 92.31%
contrib/babelfishpg_common/src/varchar.c 51 56 91.07%
<!-- Total: 73 79
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_common/src/varchar.c 2 87.94%
contrib/babelfishpg_tds/src/backend/tds/tdscomm.c 2 76.23%
<!-- Total: 4
Totals Coverage Status
Change from base Build 18562751231: 0.04%
Covered Lines: 51803
Relevant Lines: 67553

💛 - Coveralls

coveralls avatar Sep 16 '25 09:09 coveralls

And let's fix the test cases first.

@Yvinayak07 I don't understand. What do you mean?

bilalkah avatar Sep 24 '25 08:09 bilalkah

Can you please make a review? @Yvinayak07

bilalkah avatar Sep 29 '25 12:09 bilalkah

Hi @Yvinayak07 , Can you please help me understand the upgrade test from version X_Y to latest? As far as I understand, in such test cases, the result should include my changes since it has been upgraded to latest. However, the results are saying that. For example, I need to provide old results in test/JDBC/upgrade/17_7/schedule. Why is that?

bilalkah avatar Oct 03 '25 20:10 bilalkah