Repository navigation
[GH-3146] Read Parquet GEOGRAPHY columns as geographies - #3573
Merged
jiayuasu merged 4 commits intoNov 23, 2026
Merged
Conversation
A read of a dataset whose files differ in a geography column could lose rows or compute on a plane: - A file without the column failed on Spark 4.2, because the Parquet projection had no stored type for a native geography column. The column now reads as null there. - A reader of geometries took the values of a GEOGRAPHY column. It now rejects the column, as a reader of geographies rejects a GEOMETRY column. - The check of all footers that settles the SRIDs of geometry columns on Spark 4.2 now covers geography columns. It rejects files that state different SRIDs for one, and a column that is a geometry column in some files and a geography column in others, before a scan could skip such a file as a corrupt one. - The layout of a Parquet list is decided by the stored types, so that a schema with binary or GeographyUDT elements reads a list of GEOGRAPHY values that the inferred type rejects.
…t fit its schema A file that stores a column in a way that the schema of a read does not take is a sound file. The reader raises GeoParquetColumnMismatchException for it, which a scan with ignoreCorruptFiles does not skip a file for. - A file that a spatial filter leaves out is compared with the schema of the read as a scanned file is. - The check of all footers leaves out a file whose row groups are corrupt before it rejects the files that differ in a column. - The check leaves a repeated field to the scan. - The tutorial shows the schemas that a reader may have to give.
… GeoParquet 1 geometry column for a geography - A repeated GEOMETRY or GEOGRAPHY field stays an array when the file carries the schema of a Spark write. The reader made it a column of single values and returned the last value of each row. - A column that the GeoParquet metadata of a file names as a geometry column is not read as a geography column. Next to a file with a GEOGRAPHY column of the same name, its WKB was read as a geography when the other file came first. - In the check of all footers, a geometry column without a value and without a CRS fits the SRID of the other files and is still a geometry column. The check left such a column out, so a GEOGRAPHY column of the same name was rejected or not by the order of the files.
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. Writing geography columns is the next PR, so this one does not close the issue.What changes were proposed in this PR?
GeoParquet 2.0 stores a geography in the
GEOGRAPHYlogical type of the Parquet format. Since #3544 thegeoparquetreader returns such a column as a binary column that holds WKB. With this PR it returns a geography column, on Spark 4.1 and later:geography(<srid>)type on Spark 4.2, as geometry columns do.crsproperty of the logical type by the rules that geometry columns follow. A column without the property has SRID 4326.spherical(vincenty,thomas,andoyer,karney) is rejected with a message that names the column and the algorithm. Sedona computes on a sphere, and so does Spark's native geography type. A schema in which the column is binary still reads its WKB.GeographyUDT,LegacyGeographyTypein Python) reads it.GEOGRAPHYcolumn is not read as a geometry column, which would compute on a plane with its values, and aGEOMETRYcolumn is not read as a geography column. A schema that asks for either is rejected, and so is a dataset in which a column is the one kind in some files and the other kind in others. A geometry column of a GeoParquet 1.x file, a binary column that thegeometadata names, counts as a geometry column here.GeoParquetColumnMismatchExceptionfor it, which is not aRuntimeExceptionor anIOException, the two kinds that Spark'sFileScanRDDskips a file for underignoreCorruptFiles=trueon Spark 3.5 to 4.2. So the read fails instead of returning the rows of the other files as if they were all. This covers a column of the other kind, edges that are not spherical, a CRS that the native geography type cannot represent, an SRID other than the one of the geography type of the read, and a binary column that is read as a geography column but holds something else.Unchanged:
GEOGRAPHYcolumn. It reads back as before, also when a file written on Spark 4.1 is read on Spark 4.2."edges": "spherical"in thegeometadata is read as a geometry column, as before.prepareWritewith a message of Sedona's, becausesupportDataTypehas to accept the type for reads.One fix that this change makes necessary:
SpatialFilterPushDownForGeoParquettranslated a predicate on a geography column into a spatial filter, which compares the planar bounding box of the query geometry with thebboxof a file. The edges of a geography are arcs of great circles and leave the planar bounding box of their end points. With a file that lists abboxfor its geography column,ST_Intersects(geography, ST_GeogFromWKT('POLYGON ((0 60, 90 60, 90 61, 0 61, 0 60))', 4326))skipped a file withPOINT (45 68.2), which that polygon contains. Predicates on geography columns are no longer pushed down. Files that Sedona writes list nobboxfor a geography column, so this was not reachable with them.Limits:
mergeSchemais, with a message that names the column and both SRIDs. A schema withGEOGRAPHY(ANY)for the column reads them. The same check rejects a column that is a geometry column in some files and aGEOGRAPHYcolumn in others. A geometry column without a value and without a CRS fits the SRID of the other files, as [GH-3568] Read a GeoParquet file without geometries in a column next to files that state its CRS #3569 made it, and is still a geometry column in this check. Before, the check left such a column out, and whether the read failed depended on the order of the files.ignoreCorruptFiles=true, a file whose row groups cannot be read is left out before the files are compared, as [GH-3568] Read a GeoParquet file without geometries in a column next to files that state its CRS #3569 does for a geometry column without values. The row groups are only read where the files differ in a column. This now also holds for geometry columns whose files state two SRIDs.ignoreCorruptFiles=trueas well.GEOGRAPHYcolumn of the same name, the read fails on Spark 4.2 with a message that names the column, also withignoreCorruptFiles=true.IllegalArgumentException, so a scan withignoreCorruptFiles=trueskips the file. That is the behavior of master and not part of this PR.GEOGRAPHYcolumn, as before.More changes that the above needs:
array<binary>reads the WKB of a list ofGEOGRAPHYvalues whose edges are not spherical, and a schema witharray<GeographyUDT>reads a list whose CRS the native type cannot represent. Before, the comparison itself rejected these columns.ST_Intersectson a geometry column returned no rows for a file in which the column is aGEOGRAPHYcolumn and whosebboxis outside the query window, and failed without the filter.GEOMETRYorGEOGRAPHYfield stays an array when the file carries the schema of a Spark write. The reader took the type of such a field from the Parquet schema as that of a single value, and returned the last value of each row.geometadata of a file names as a geometry column is not read as a geography column. On Spark 4.1 a GeoParquet 1.1 file next to a file with aGEOGRAPHYcolumn of the same name returned its WKB as a geography with SRID 257 when the other file came first. The reader looks at the columns of the file for this and not at the fields within them, where thegeometadata names nothing.repeated binary items (GEOGRAPHY)for a column of single values and rejected the file on Spark 4.2. The same holds for a repeatedGEOMETRYfield.How was this patch tested?
New
GeoParquetGeographySuite. Its files come from parquet-java's own writer, and from Spark 4.2's Parquet writer for the two fixtures that were already in the repository. It covers:ST_Distance)crsproperty: absent,OGC:CRS84,EPSG:4269,srid:4269, inline PROJJSON andprojjson:<key>spherical: the error, the read with a binary schema, and the error for a geography schemaignoreCorruptFilesGEOMETRYcolumn in one file and aGEOGRAPHYcolumn in the next, in both orders, with and withoutignoreCorruptFiles, and a schema that asks for a geometry, also for a file that a spatial filter leaves outignoreCorruptFilesignoreCorruptFilesGEOGRAPHYcolumn of the same name: read for the current payload, rejected for the payload of Sedona 1.9GEOGRAPHYcolumn in another, in both orders (Spark 4.2)GEOMETRYandGEOGRAPHYfields, in a file without the schema of a Spark write and with one that gives them binary or spatial elements, with both values of a row checkedGEOGRAPHYcolumn of the same name, with a geometry and with neither a geometry nor a CRS, in both orders, with and withoutignoreCorruptFilesarray<binary>for edges that are not spherical, and read asarray<GeographyUDT>for an unknown CRSThe two tests of
GeoParquetNativeTypesSuitethat expected a binary column are removed.Run locally with the other GeoParquet suites:
spark/commonspark/spark-4.2Python, with the shaded jar of this branch:
tests/sql/test_geoparquet.py,tests/sql/test_geography.py,tests/sql/test_structured_adapter.pyandtests/geopandas/test_io.pypass on Spark 4.2 and 4.1. A geography column read from Spark's fixture collects as PySpark'sGeographyon Spark 4.2 and as Sedona'sGeographyon Spark 4.1.Did this PR include necessary documentation updates?
docs/tutorial/files/geoparquet-sedona-spark.mdand its Chinese version describe the geography columns, with an example of each schema that a reader may have to give.