Repository navigation
[GH-3588] Write WKT and EWKT coordinates with every digit needed to read them back - #3589
Draft
james-willis wants to merge 2 commits into
Draft
james-willis wants to merge 2 commits into
james-willis wants to merge 2 commits into
Conversation
…d to read them back ST_AsText and ST_AsEWKT wrote at most 16 decimal places, so coordinates below 1 could lose their last digit and anything below 5e-17 became 0. The JTS WKTWriter sizes its formatter from the floating model's 16 significant digits but applies them as decimal places (locationtech/jts#243). jts-io-patch 1.21.0-datasyslab-4 writes the floating model with full precision in decimal notation; bump to it, and write geography text with the same isolated writer instead of the stock JTS one. Two tests asserted truncated strings and now assert the full values. Document the behavior on the ST_AsText and ST_AsEWKT pages.
Four more tests asserted strings the old writer had truncated: Flink FunctionTest.testRotate (0.0000000000000002 is really 2.4492935982947064e-16), Spark ST_ScaleGeom (-0.263672 is really -0.26367199999999996) and ST_Rotate (ordinates near 3e-16 and 9e-16). ST_MinimumBoundingCircle built its expected string with stock JTS toText(), which still truncates; it now uses Sedona's own writer.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Yes.
Is this PR related to a ticket?
Closes #3588.
What changes were proposed in this PR?
ST_AsTextandST_AsEWKTwrote coordinates with at most 16 decimal places, so coordinates below 1 could lose their last significant digit and anything below 5e-17 became0; a valid polygon could come back invalid from a text round trip. The limit comes from the JTSWKTWriter, which sizes its formatter from the floating precision model's 16 significant digits but applies them as decimal places (locationtech/jts#243, open since 2017).The writer is fixed in Sedona's isolated IO artifact:
org.datasyslab:jts-io-patch:1.21.0-datasyslab-4(jiayuasu/jts#16) uses JTS's own full-precisionOrdinateFormat.DEFAULTfor the floating model, so every ordinate is written with the digits needed to read the samedoubleback, in decimal notation, never scientific. Fixed precision models still round. This PR bumpsjts.io.patch.versionto that release.Geography text (
ST_AsTextandST_AsEWKTon a geography) went through the stock JTS writer viaGeometry.toText(); it now goes throughGeomUtils.getWKT, the same isolated writer as geometry.Output for ordinary coordinates is unchanged: a value with magnitude 1 or more already fit in 16 decimal places. Only values that were losing digits change, for example
0.30000000000000004instead of0.3and0.00000000000000001instead of0. Two existing tests asserted truncated strings (FunctionsTest.testUnion:-0.0000000000000254is really-2.5444437451708134e-14;FunctionsTest.rotate: a 17-digit value) and now assert the full values.The SQL and Flink pages for
ST_AsTextandST_AsEWKTsay that output round-trips since v2.0.0, that scientific notation is never used, and point toST_ReducePrecisionfor rounding, with a worked example.How was this patch tested?
New
FunctionsTest.asWKTWritesEveryDigitOfTheCoordinate(WKT and EWKT of 1e-17, 0.1 + 0.2, 0.39452545497198344 and 1e20 read back equal) andGeography.FunctionTest.asText_writesEveryDigitOfTheCoordinate; both fail on1.21.0-datasyslab-3.commonsuite: 1,513 tests pass against the module installed locally as1.21.0-datasyslab-4. Spark and Flink suites are running; this description will be updated with their results.Did this PR include necessary documentation updates?
Status. Draft until
org.datasyslab:jts-io-patch:1.21.0-datasyslab-4is on Maven Central; CI cannot resolve the artifact before the jiayuasu/jts#16 release.