-
Notifications
You must be signed in to change notification settings - Fork 452
Fix parsing of Geography coordinates with scientific notation #2819 #2837
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
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
- 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
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Rerun CI pipeline was successfully - https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=130697&view=results |
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java
Outdated
Show resolved
Hide resolved
…c notation with e/E and minus signs
…emove delta checks
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.