Repository navigation
[GH-3146] Keep M coordinates and write Z and M bounds in GeoParquet 2.0 files - #3562
Merged
jiayuasu merged 7 commits intoNov 20, 2026
Merged
Conversation
The GeoParquet writer keeps X, Y and Z and discards M, because GeoParquet 1.1 has no M coordinate. GeoParquet 2.0 has one: its geometry_types allow the M and ZM suffixes, and the GEOMETRY logical type of the Parquet format holds ISO WKB of all four layouts. A 2.x write now stores XYM and XYZM geometries as they are, and geometry_types name the layout from the stored type code. A 1.x write discards M as before.
…ox without all bounds A native Spark geometry value holds WKB, and it keeps the Z and M dimensions that an empty multi-geometry or collection declares. A JTS geometry has no coordinates to keep them in. The writer and the reader both went through JTS, so MULTIPOINT M EMPTY became MULTIPOINT EMPTY, and a GEOMETRYCOLLECTION M with such a member became a collection of members with two layouts, which Spark's native type rejects. The same happened with Z before this change. A 2.x write now stores the WKB of a native value as it is, and the reader hands the stored WKB to a native value as it is. A 1.x write still goes through JTS, because it has to discard M. GeoParquet 2.0 asks for the bounds of all four dimensions in the bbox of a column with XYZM geometries. The writer has the X and Y bounds only, so it leaves the optional bbox out for such a column. The test compares the types in the row-group statistics with geometry_types for the geometries that have coordinates.
The bbox of a column in the geo metadata of a 2.x file now lists the bounds of every dimension that has them: six values for a column with Z coordinates and eight for a column with Z and M coordinates. A column with XYZM geometries had no bbox, so its files could not be skipped. GeoParquet 1.x files keep the four values of the X and Y bounds.
jiayuasu
force-pushed
the
feature/geoparquet-2.0-m-coordinates
branch
from
November 20, 2026 08:00
153c78b to
1672729
Compare
… GeoParquet tutorials
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?
Is this PR related to a ticket?
[GH-XXX] my subject. Part of Update GeoParquet writer and reader to support GeoParquet 2.0.0 #3146. It follows [GH-3146] Write GeoParquet 2.0 files with the Parquet GEOMETRY type #3553, so it does not close the issue.What changes were proposed in this PR?
The GeoParquet writer keeps X, Y and Z and discards M, because GeoParquet 1.1 has no M coordinate: its
geometry_typesonly know theZsuffix. GeoParquet 2.0 has M. Itsgeometry_typesallowMandZM, and theGEOMETRYlogical type of the Parquet format holds ISO WKB of all four layouts. After #3553 a 2.x write still dropped M.With this PR a 2.x write keeps M:
geometry_typesin thegeometadata name the layout from the stored type code:Point M,LineString ZMand so on.MULTIPOINT M EMPTYbecameMULTIPOINT EMPTY, and aGEOMETRYCOLLECTION Mwith such a member became a collection of members with two layouts, which Spark's native type rejects withWKB_PARSE_ERROR. The same happened with Z before this PR, on the write and on the read. A column ofGeometryUDTis not affected, because its values come from JTS geometries. The writer converts a native value to WKB once and reads the JTS geometry for the metadata from the same bytes. The reader still goes through a JTS geometry for WKB that Spark does not take as it is, such as a line of one point or a ring that is not closed, which the WKB reader completes.bboxof a column in thegeometadata of a 2.x file lists the bounds of every dimension that has them, as GeoParquet 2.0 asks: six values for a column with Z coordinates,[xmin, ymin, zmin, xmax, ymax, zmax], and eight for a column with Z and M coordinates,[xmin, ymin, zmin, mmin, xmax, ymax, zmax, mmax]. The writer had the X and Y bounds only, so a column with XYZ geometries had four values after [GH-3146] Write GeoParquet 2.0 files with the Parquet GEOMETRY type #3553. A column with M and without Z coordinates keeps its four values, because the specification has nobboxwith M bounds and without Z bounds. A Z or M coordinate that is NaN is not a bound, as in the bounding box of the Parquet statistics, and a dimension without a coordinate that is a number is left out. The reader takes the X and Y bounds of such abboxsince [GH-3560] Read the X and Y bounds of a GeoParquet bbox that has Z or M bounds #3561.bbox. JSON has no number for such a bound: the writer stored the string"Infinity"ornullin its place, which the GeoParquet schema does not allow. This applies to the X and Y bounds of a 1.x file too.What stays the same:
bbox.Sedona 1.9.1 reads a
bboxof six or eight values as if it had four (#3560). It does not get that far with a 2.0 file: on Spark 3.5 and 4.0 it cannot read the footer, and on Spark 4.1 the read fails unless Spark's geospatial feature is enabled, and then the column has Spark's native type, which the functions of 1.9.1 do not take.Known limit: the geometry types in the row-group statistics come from parquet-java. It skips empty geometries and takes the Z and M dimensions from the first coordinate, so
LINESTRING M (1 2 NaN, 3 4 99)is stored with type code 2002 and listed asLineString Mingeometry_types, while the statistics report type 2. #3553 notes the same for Z, and Spark's own writer produces the same statistics. parquet-java computes them from the stored WKB while it writes the column, so the fix belongs there.How was this patch tested?
GeoParquetDimensionsSuitehas a new test that writes XYM and XYZM points and lines, empty XYM and XYZM geometries, and XY and XYZ points to a 2.0 file. It compares the stored bytes with the ISO WKB of the input, checksgeometry_types, compares the types in the row-group statistics with the geometries that have coordinates, checks the eight values of thebbox, and reads the file back with thegeoparquetreader. On Spark 4.2 it runs for a native geometry column and for aGeometryUDTcolumn. For the native column it also writes empty multi-geometries with M, ZM and Z and collections with an empty member, and comparesST_AsBinaryof the values read back with the input.Fifteen more tests check the
bboxof one column each: XYM geometries, XYZ geometries, XYZ next to XYM geometries, Z and M coordinates that are NaN in some or in all geometries, XYZ geometries in a 1.1 file, an infinite M next to no Z, and the columns that get nobboxbecause an X, Y, Z or M coordinate is infinite or a Y coordinate is NaN. Those files are read back with a spatial filter. Two further tests cover the single conversion of a value on the write and the read of a line of one point and of a ring that is not closed. The existing tests still cover that a 1.1 write discards M.The GeoParquet suites pass locally on Spark 4.2 / Scala 2.13 (including the GeoParquet suites of the
spark-4.2module), Spark 4.1 / Scala 2.13 and Spark 3.5 / Scala 2.12.Did this PR include necessary documentation updates?