Skip to content

Fix parsing of Geography coordinates with scientific notation #2819 - #2837

Merged
Divang Sharma (divang) merged 6 commits into
mainfrom
users/divang/fix-spatial-datatype-minus-sign
Nov 26, 2025
Merged

Fix parsing of Geography coordinates with scientific notation #2819#2837
Divang Sharma (divang) merged 6 commits into
mainfrom
users/divang/fix-spatial-datatype-minus-sign

Conversation

@divang

@divang Divang Sharma (divang) commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Problem
When creating Geography objects with very small coordinate values (e.g., 0.0001234), a NumberFormatException is thrown. This occurs because coordinates with three or more zeros after the decimal point are represented in scientific notation (e.g., "1.23E-4") when converted to strings.

Root Cause
The readPointWkt() method in SQLServerSpatialDatatype.java parses Well-Known Text (WKT) coordinate strings. The parsing loop that identifies the end position of a numeric value checks for digits, decimal points, and the exponent indicators 'E' and 'e', but does not account for the minus sign (-) that appears in negative exponents.

When parsing "1.23E-4", the loop terminates at the 'E' character instead of continuing through the full scientific notation. This causes BigDecimal to attempt parsing "1.23E" (an incomplete scientific notation), resulting in a NumberFormatException.

Solution
Added support for the minus sign (-) in the character validation loop within readPointWkt(). This allows the parser to correctly identify the complete scientific notation string including negative exponents.

Test
A new test case testGeographySmallCoordinates() has been added to verify that Geography objects can be created with small coordinate values that result in scientific notation.

Very small coordinates that contain three or more zeros after the dot (like 0.000123) have a string representation of 1.23E-4. The readPointWkt did not account for this and set the end pos to the E, thus the BigDecimal tried to parse "1.23E". This resulted in a NumberFormatException.

This fixes the issue by also allowing the minus sign when determining the end of the number.
@codecov

codecov Bot commented Nov 12, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.49%. Comparing base (a5b1412) to head (63f89e8).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...osoft/sqlserver/jdbc/SQLServerSpatialDatatype.java 25.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2837      +/-   ##
============================================
+ Coverage     56.33%   56.49%   +0.16%     
- Complexity     4516     4572      +56     
============================================
  Files           151      151              
  Lines         34431    34445      +14     
  Branches       5736     5741       +5     
============================================
+ Hits          19397    19461      +64     
+ Misses        12406    12405       -1     
+ Partials       2628     2579      -49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Only allow +/- signs after E/e in exponents (more precise validation)

- Add comprehensive test coverage for edge cases

- Test negative coords, small values, and both Geography/Geometry types
@muskan124947

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@divang

Copy link
Copy Markdown
Contributor Author

@machavan Mahendra Chavan (machavan) added this to the 13.3.1 milestone Nov 25, 2025
@divang
Divang Sharma (divang) merged commit c2ae869 into main Nov 26, 2025
18 of 19 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.

5 participants