Skip to content

fix: Use topological (recursive) emptiness#80

Merged
kylebarron merged 3 commits into
datafusion-contrib:mainfrom
ianthetechie:use-topological-emptiness
Jun 22, 2026
Merged

fix: Use topological (recursive) emptiness#80
kylebarron merged 3 commits into
datafusion-contrib:mainfrom
ianthetechie:use-topological-emptiness

Conversation

@ianthetechie

Copy link
Copy Markdown
Contributor

I stumbled upon some other edge cases when checking compatibility against PostGIS. Basically the PG stance (also verified in JTS, so I assume GEOS is also the same) is that emptiness checks should be recursive based on the principle of "does this thing actually represent at least a point or does the structure simply collapse to nothing."

This showed up as I was working on an implementation for ST_Dump (PR soon :D) and trying to keep it native. After a bunch of test cases, I realized that PostGIS actually drops these, and there went the afternoon researching what we should do 😂

@github-actions github-actions Bot added the fix label Jun 18, 2026
@ianthetechie ianthetechie mentioned this pull request Jun 18, 2026
Comment on lines +208 to +213
// Recursive emptiness (PostGIS / JTS topological semantics).
// A collection whose every leaf is empty is itself reported as empty,
// even though it has structurally non-zero children.
//
// NB: GeoArrow explicitly denies recursive collections,
// so we only need to test one level.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like this only applies to GeometryCollection? Can any other supported geometry types have an empty child?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question... so in OGC terms, no, it actually applies to everything. MultiPoints can have a mix of empty and non-empty points, etc... My quick reading of the GeoArrow spec also seems to allow this. However, when writing up some extra tests for those, I discovered that the WKT parser we depend on only accepts mixed empty/non-empty multi-linestrings (georust/wkt#111 seems to acknowledge this, but the symptom I see right now isn't a crash but a parse error). And multipolygons mixing empty and non-empty seem to crash, but those should also technically be allowed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have a few WKB fixtures for this (this is what we do in SedonaDB). geoarrow.pyarrow's WKT parser should be able to generate these for you.

https://github.com/apache/sedona-db/blob/298911255f91e0d55146a8baf8e9b49aad404b35/rust/sedona-testing/src/fixtures.rs#L22-L29

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I generated them with PostGIS ST_AsBinary and interpolated the literal, but same idea.

The multipolygon case I came up with is still broken due to an assumption in geoarrow-array. I'm not sure if there is a geoarrow rule forbidding that structure, but it works in PostGIS 🤷

@ianthetechie
ianthetechie force-pushed the use-topological-emptiness branch from fbcf8a5 to 58583eb Compare June 20, 2026 01:43

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kylebarron
kylebarron merged commit 146cd10 into datafusion-contrib:main Jun 22, 2026
7 checks passed
@ianthetechie
ianthetechie deleted the use-topological-emptiness branch June 22, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants