Repository navigation
[GH-3146] Take the CRS of a GeometryUDT column from its first geometry - #3559
Merged
jiayuasu merged 5 commits intoNov 21, 2026
Merged
Conversation
jiayuasu
force-pushed
the
feature/geoparquet-2.0-write-udt
branch
4 times, most recently
from
November 19, 2026 07:16
248ccb0 to
9ec89b5
Compare
jiayuasu
marked this pull request as ready for review
November 19, 2026 07:16
…eometry GeoParquet 2.0 states the CRS of a geometry column in the Parquet schema, which the Parquet writer needs before the first row. A GeometryUDT column, the geometry type on Spark 4.1 and older, has an SRID on each geometry only, so a 2.x write of such a column required geoparquet.crs. A 2.x write now holds rows back until every such column has shown a geometry, opens the file with those SRIDs as the CRS of the columns, and fails if a later geometry of the file has another SRID. A column with SRID 0, or without any geometry in the file, is written with an unknown CRS. The rows held back are limited to 16 MB per file, which geoparquet.crs.lookahead.bytes changes. A column that has shown no geometry by then is written with an unknown CRS as well. geoparquet.crs and geoparquet.crs.<column> still state the CRS as given, without a check against the geometries. GeoParquet 1.x writes are unchanged.
jiayuasu
force-pushed
the
feature/geoparquet-2.0-write-udt
branch
from
November 20, 2026 16:58
9ec89b5 to
37965e7
Compare
…row held back fails, and write the row that ends the wait without a copy
… one column each, and hold back rows of any kind as copies of their own
…ritten to that column, before any other option that the key is in another case
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. This is the third PR for GeoParquet 2.0, after [GH-3146] Read Parquet GEOMETRY columns in the GeoParquet reader #3544 and [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?
GeoParquet 2.0 states the CRS of a geometry column in the Parquet schema, which the Parquet writer needs before the first row. A native Spark geometry type (Spark 4.2) names its SRID, so the writer knows the CRS up front. A
GeometryUDTcolumn, the geometry type on Spark 4.1, has an SRID on each geometry only. After #3553 a 2.x write of such a column therefore fails unlessgeoparquet.crsorgeoparquet.crs.<column_name>is set.With this PR the writer takes the CRS from the data when no CRS option covers the column:
FirstGeometryOutputWriterholds the first rows of each file back until every such column has shown a non-null geometry. It then opens the Parquet file with the SRIDs of those geometries as the CRS of the columns and writes the held rows.srid:0, andnullin thegeometadata).geoparquet.srid.lookahead.byteschanges the limit. The key is not undergeoparquet.crs., where every longer key names a column. A column that has shown no geometry by then is written with an unknown CRS, and a later geometry with an SRID fails the write.UnsafeRowof its own. Spark's write paths hand overUnsafeRows, which are copied as before. A caller of the writer that hands over another kind of row, such as aGenericInternalRowthat it uses again for the next row, gets the row converted first, so the copy shares no values with the caller and its size counts against the limit.close()has failed.geoparquet.version,geoparquet.crs,geoparquet.crs.<column_name>,geoparquet.covering,geoparquet.covering.<column_name>,geoparquet.covering.modeandgeoparquet.srid.lookahead.bytes. Before, a key in another case,GEOPARQUET.CRSfor example, was ignored without a message. A 2.x write then failed for the missing CRS, and with this PR it would have taken the CRS from the data instead of the option.prepareWritenow sets each option of the write in the Hadoop configuration under the key that the writer reads, so an option of the write also replaces a value that the Hadoop configuration has for the same key in another case. This applies to 1.x writes too.geoparquet.covering.MODEis the covering of a columnMODEas before, not the covering mode in upper case. If no geometry column has the name in that case and the key is no other option either, the key is for the column whose name differs in case only. Withspark.sql.caseSensitive=truea DataFrame can have several of those, and the write then fails with a message that names the key and the columns.What stays the same:
geoparquet.crsandgeoparquet.crs.<column_name>state the CRS as given, without a check against the geometries, and no rows are held back for a column they cover.geometadata, which is written after the last row.Not in this PR: the default version (still
1.1.0), geography columns, and reading on Spark 3.5/4.0.How was this patch tested?
GeoParquetNativeTypesSuitehas new tests for a 2.x write ofGeometryUDTcolumns without a CRS option: the CRS comes from the first geometry after null rows, each of two geometry columns gets the CRS of its own first geometry, a second SRID in a column fails the write, a column without geometries is written with an unknown CRS, the writer stops waiting when the rows held back reachgeoparquet.srid.lookahead.bytes, andgeoparquet.crsis written as given without a check against the geometries. Further tests cover option keys in another case (geoparquet.crs.<column_name>for 2.x and 1.x,GEOPARQUET.CRS,GeoParquet.Version), two columns that differ in case only where the option of one must not reach the other, a key that fits both of them in a case that neither has, an option of the write against a value in the Hadoop configuration,geoparquet.covering.MODEfor a geometry columnMODEand the covering mode under a key in another case (both ingeoparquetIOTests), a column namedlookahead.byteswith its own CRS option, and the Parquet writer being released when a row held back fails at the end of the file. Three tests call the writer of a write task directly: the row that ends the wait reaches the Parquet writer as the same object, aGenericInternalRowthat the caller changes after the write is read back with the values it had, and an 8 KiBGenericInternalRowreaches a limit of 4 KiB. The existing test that took the CRS from the SRID of a native column now runs forGeometryUDTcolumns as well.The GeoParquet suites pass locally on Spark 4.1 / Scala 2.13, Spark 3.5 / Scala 2.12 and Spark 4.2 / Scala 2.13 (including the GeoParquet suites of the
spark-4.2module).Did this PR include necessary documentation updates?
geoparquet.srid.lookahead.bytesamong them, with the rules for the case of their keys.