Validate inputs for FLOAT/REAL data types
Description
T-SQL parity for real/float: reject special literals; add safe casts
- What: String→
real/floatcasts now rejectNaN/Infinity/inf(T-SQL doesn’t allow them).TRY_CASTreturnsNULLinstead of accepting those values. Empty strings cast to0. - Why: Align Babelfish with T-SQL behavior; avoid downstream errors.
- How (high level):
- Added validator
is_valid_tsql_floatand used it invarchar2float4/8,bpchar2float4/8. - Registered explicit casts for
pg_catalog.VARCHAR/BPCHAR/TEXT → FLOAT4/FLOAT8via newsys.*2float*functions. - Parser/coercion: route
TRY_CAST(... AS real|float(p));float(p)usesrealfor1..24,float8otherwise. - Exposed
is_tsql_real_datatype/is_tsql_float_datatypevia 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.
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 | |
|---|---|
| Change from base Build 18562751231: | 0.04% |
| Covered Lines: | 51803 |
| Relevant Lines: | 67553 |
💛 - Coveralls
And let's fix the test cases first.
@Yvinayak07 I don't understand. What do you mean?
Can you please make a review? @Yvinayak07
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?