Skip to content

[GH-3486] Keep the Z or M dimension of WKT tagged Z, M or ZM even when its values are all NaN - #3487

Merged
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/wkt-declared-dimensions
Oct 20, 2026
Merged

jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/wkt-declared-dimensions

Conversation

@jiayuasu

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

  • Bump org.datasyslab:jts-io-patch to 1.21.0-datasyslab-3. It adds WKTReader.forDeclaredDimensions(), the WKT counterpart of the WKBReader.forDeclaredDimensions() that Sedona already uses, and its WKBReader reads a point as empty only when X and Y are both NaN.
  • Constructors.geomFromWKT, geomFromEWKT, mPointFromText, mLineFromText, mPolyFromText and geomCollFromText, and the WKT reader in FormatUtils, use WKTReader.forDeclaredDimensions().

Effect:

  • WKT tagged Z, M or ZM keeps that layout when its values are all NaN or the geometry is empty: POINT Z (1 2 NaN) and POINT Z EMPTY are stored as XYZ, and POINT ZM (1 2 NaN NaN) as XYZM. So ST_EqualsIdentical(ST_GeomFromWKT('POINT (1 2)'), ST_GeomFromWKT('POINT Z (1 2 NaN)')) is false, as in GEOS, and a WKT geometry is identical to the same geometry read from WKB.
  • Untagged WKT is read as before, including the old JTS syntax: POINT (1 2 3) is still XYZ and POINT (1 2) still XY.
  • ST_GeomFromWKB reads POINT (NaN 1) as a point with a NaN X instead of POINT EMPTY. POINT (NaN NaN) is still empty.

This changes the output of the WKT constructors for tagged all-NaN input, which used to be stored as 2D.

How was this patch tested?

  • New ConstructorsTest cases: the stored layout of tagged XYZ, XYM and XYZM points, lines, polygons, multipoints and empties, before and after a serializer round trip; untagged and old-syntax input unchanged; EWKT with an SRID; and POINT (NaN 1) versus POINT (NaN NaN) from WKB. New PredicatesTest case for ST_EqualsIdentical on tagged all-NaN WKT. These fail on master with 1.21.0-datasyslab-2.
  • common: 1,446 tests pass. Before rebasing: constructorTestScala, predicateTestScala, functionTestScala, dataFrameAPITestScala and GeoParquetDimensionsSuite (601 passed; the one failure is a MySQL test that needs Docker) and Flink ConstructorTest, PredicateTest, FunctionTest (274 passed), with the published 1.21.0-datasyslab-3.

Did this PR include necessary documentation updates?

  • No, this PR does not add or change a public API. The constructors' documented behavior is unchanged; tagged WKT now keeps the dimension it declares.

…en when its values are all NaN

ST_GeomFromWKT and the other WKT constructors parsed with JTS's WKTReader,
which builds the same coordinate sequences for POINT (1 2) and
POINT Z (1 2 NaN), so the Z dimension was dropped when stored. Use
jts-io-patch 1.21.0-datasyslab-3's WKTReader.forDeclaredDimensions(), which
marks sequences with the layout their Z, M or ZM tag declares, as the WKB
reader already does. Untagged WKT, including the old JTS syntax
POINT (1 2 3), is read as before. The same release makes ST_GeomFromWKB read
POINT (NaN 1) as a point instead of POINT EMPTY.
…oSeries.geom_equals_identical

The test recorded the old behavior, in which POINT Z EMPTY and an all-NaN
LINESTRING Z read from WKT were identical to their 2D counterparts.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Oct 20, 2026
@jiayuasu
jiayuasu merged commit 78920fc into apache:master Oct 20, 2026
43 checks passed
@jiayuasu
jiayuasu deleted the fix/wkt-declared-dimensions branch October 20, 2026 00:46
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_GeomFromWKT drops an all-NaN Z dimension, and ST_GeomFromWKB reads POINT (NaN 1) as empty

1 participant