Skip to content

[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
apache:masterfrom
james-willis:fix/wkt-writer-precision
Draft

james-willis wants to merge 2 commits into
apache:masterfrom
james-willis:fix/wkt-writer-precision

Conversation

@james-willis

Copy link
Copy Markdown
Collaborator

Did you read the Contributor Guide?

Yes.

Is this PR related to a ticket?

Closes #3588.

What changes were proposed in this PR?

ST_AsText and ST_AsEWKT wrote coordinates with at most 16 decimal places, so coordinates below 1 could lose their last significant digit and anything below 5e-17 became 0; a valid polygon could come back invalid from a text round trip. The limit comes from the JTS WKTWriter, 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-precision OrdinateFormat.DEFAULT for the floating model, so every ordinate is written with the digits needed to read the same double back, in decimal notation, never scientific. Fixed precision models still round. This PR bumps jts.io.patch.version to that release.

Geography text (ST_AsText and ST_AsEWKT on a geography) went through the stock JTS writer via Geometry.toText(); it now goes through GeomUtils.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.30000000000000004 instead of 0.3 and 0.00000000000000001 instead of 0. Two existing tests asserted truncated strings (FunctionsTest.testUnion: -0.0000000000000254 is really -2.5444437451708134e-14; FunctionsTest.rotate: a 17-digit value) and now assert the full values.

The SQL and Flink pages for ST_AsText and ST_AsEWKT say that output round-trips since v2.0.0, that scientific notation is never used, and point to ST_ReducePrecision for 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) and Geography.FunctionTest.asText_writesEveryDigitOfTheCoordinate; both fail on 1.21.0-datasyslab-3. common suite: 1,513 tests pass against the module installed locally as 1.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?

  • Yes, I have updated the documentation.

Status. Draft until org.datasyslab:jts-io-patch:1.21.0-datasyslab-4 is on Maven Central; CI cannot resolve the artifact before the jiayuasu/jts#16 release.

…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

No deployments
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.

ST_AsText and ST_AsEWKT write at most 16 decimal places, so coordinates below 1 do not round-trip

1 participant