Skip to content

[GH-3146] Read Parquet GEOGRAPHY columns as geographies - #3573

Merged
jiayuasu merged 4 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-geography-read
Nov 23, 2026
Merged

jiayuasu merged 4 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-geography-read

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 21, 2026 •

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?

GeoParquet 2.0 stores a geography in the GEOGRAPHY logical type of the Parquet format. Since #3544 the geoparquet reader 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:

  • The column has Sedona's geography type on Spark 4.1 and Spark's native geography(<srid>) type on Spark 4.2, as geometry columns do.
  • The SRID comes from the crs property of the logical type by the rules that geometry columns follow. A column without the property has SRID 4326.
  • The stored WKB becomes the value as it is. No JTS or S2 object is built on the way, and a Z coordinate is kept.
  • A column whose edges follow an algorithm other than 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.
  • On Spark 4.2 a column whose CRS is unknown or not geographic is rejected, because the native geography type takes the SRID of a geographic CRS only. A schema with Sedona's own geography type (GeographyUDT, LegacyGeographyType in Python) reads it.
  • A GEOGRAPHY column is not read as a geometry column, which would compute on a plane with its values, and a GEOMETRY column 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 the geo metadata names, counts as a geometry column here.
  • A file of a dataset that lacks the column reads null for it, as it does for any other column.
  • A file that stores a column in a way that the schema of the read does not take is a sound file, not a corrupt one. The reader raises the new GeoParquetColumnMismatchException for it, which is not a RuntimeException or an IOException, the two kinds that Spark's FileScanRDD skips a file for under ignoreCorruptFiles=true on 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:

  • A geography column that Sedona wrote from its own geography type, on any Spark version up to 4.1, is stored as that type is serialized and is not a GEOGRAPHY column. It reads back as before, also when a file written on Spark 4.1 is read on Spark 4.2.
  • GeoParquet 1.x files. A 1.x column with "edges": "spherical" in the geo metadata is read as a geometry column, as before.
  • Writes. A write of a native geography column is still rejected, now by prepareWrite with a message of Sedona's, because supportDataType has to accept the type for reads.

One fix that this change makes necessary: SpatialFilterPushDownForGeoParquet translated a predicate on a geography column into a spatial filter, which compares the planar bounding box of the query geometry with the bbox of 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 a bbox for its geography column, ST_Intersects(geography, ST_GeogFromWKT('POLYGON ((0 60, 90 60, 90 61, 0 61, 0 60))', 4326)) skipped a file with POINT (45 68.2), which that polygon contains. Predicates on geography columns are no longer pushed down. Files that Sedona writes list no bbox for a geography column, so this was not reachable with them.

Limits:

  • On Spark 4.2 the files of a dataset have to agree on the SRID of a geography column, because the native type names it. Sedona already compares the footers of all files before a scan for the SRIDs of the geometry columns, and that check now covers the geography columns. Files that disagree are rejected there, whatever mergeSchema is, with a message that names the column and both SRIDs. A schema with GEOGRAPHY(ANY) for the column reads them. The same check rejects a column that is a geometry column in some files and a GEOGRAPHY column 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.
  • That check decides among the files that a scan reads. With 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.
  • The check looks at the columns at the root of the schema. For a geography column in a struct, a list or a map, and for every column on Spark 4.1, which has no such check because each value carries its SRID there, the scan rejects the file. It does so with ignoreCorruptFiles=true as well.
  • A geography column that Sedona 1.9 or older wrote from its own geography type holds the payload that [GH-3124] Use SRID-prefixed ISO WKB for SQL spatial transport #3528 replaced, and is not read, as the migration guide of [GH-3124] Use SRID-prefixed ISO WKB for SQL spatial transport #3528 says. Next to files with a GEOGRAPHY column of the same name, the read fails on Spark 4.2 with a message that names the column, also with ignoreCorruptFiles=true.
  • The SRID check of a geometry column during a scan is unchanged. It raises an IllegalArgumentException, so a scan with ignoreCorruptFiles=true skips the file. That is the behavior of master and not part of this PR.
  • Spark's native geography type validates the WKB that it takes, so on Spark 4.2 a value that Spark does not accept fails the read.
  • Spark 3.5 and 4.0 cannot open a file with a GEOGRAPHY column, as before.

More changes that the above needs:

  • The reader decides between the two layouts of a Parquet list by comparing the type of the repeated field with the type that the reader asks for. It now compares the types as they are stored, so that a schema with array<binary> reads the WKB of a list of GEOGRAPHY values whose edges are not spherical, and a schema with array<GeographyUDT> reads a list whose CRS the native type cannot represent. Before, the comparison itself rejected these columns.
  • The Parquet projection of a read takes a geography column as the binary column that it is stored in, as it does for a geometry column. A native geography column that a file lacks failed the read of that file before.
  • A file that a spatial filter leaves out of a scan is compared with the schema of the read as a scanned file is. Before, a query with ST_Intersects on a geometry column returned no rows for a file in which the column is a GEOGRAPHY column and whose bbox is outside the query window, and failed without the filter.
  • A repeated GEOMETRY or GEOGRAPHY field 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.
  • A column that the geo metadata 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 a GEOGRAPHY column 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 the geo metadata names nothing.
  • The check of all footers leaves a repeated field to the scan. It took repeated binary items (GEOGRAPHY) for a column of single values and rejected the file on Spark 4.2. The same holds for a repeated GEOMETRY field.

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:

  • points, lines, polygons, null values and a Z coordinate
  • a computation on the geographies that were read (ST_Distance)
  • each form of the crs property: absent, OGC:CRS84, EPSG:4269, srid:4269, inline PROJJSON and projjson:<key>
  • an unknown CRS and a projected CRS, which Spark 4.2 rejects and Sedona's own type reads
  • the four algorithms other than spherical: the error, the read with a binary schema, and the error for a geography schema
  • a schema that gives the column a geography type, with the SRID check of the native type
  • a geography column next to a geometry column, and one nested in a struct
  • a dataset of two files, one that lacks the geography column at the root or in a struct, and two that state different SRIDs for it, at the root and in a struct, with and without ignoreCorruptFiles
  • a column that is a GEOMETRY column in one file and a GEOGRAPHY column in the next, in both orders, with and without ignoreCorruptFiles, and a schema that asks for a geometry, also for a file that a spatial filter leaves out
  • a file with other edges next to a file with spherical edges, with ignoreCorruptFiles
  • a file whose row groups are corrupt and that states another SRID, which is left out with ignoreCorruptFiles
  • a binary column of Sedona's own geography type next to a GEOGRAPHY column of the same name: read for the current payload, rejected for the payload of Sedona 1.9
  • a column that is plain binary in one file and a GEOGRAPHY column in another, in both orders (Spark 4.2)
  • repeated GEOMETRY and GEOGRAPHY fields, 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 checked
  • a geometry column of GeoParquet 1.1 next to a GEOGRAPHY column of the same name, with a geometry and with neither a geometry nor a CRS, in both orders, with and without ignoreCorruptFiles
  • a list of geographies: inferred, read as array<binary> for edges that are not spherical, and read as array<GeographyUDT> for an unknown CRS
  • the geography predicate described above, which failed before the fix
  • the round trip of a geography column of Sedona's own type through a GeoParquet 1.1 write (Spark 3.5 to 4.1), and the rejection of a native geography column on a write (Spark 4.2)

The two tests of GeoParquetNativeTypesSuite that expected a binary column are removed.

Run locally with the other GeoParquet suites:

Spark 4.2 Spark 4.1 Spark 3.5
GeoParquet suites of spark/common 256 236 137
suites of spark/spark-4.2 37

Python, with the shaded jar of this branch: tests/sql/test_geoparquet.py, tests/sql/test_geography.py, tests/sql/test_structured_adapter.py and tests/geopandas/test_io.py pass on Spark 4.2 and 4.1. A geography column read from Spark's fixture collects as PySpark's Geography on Spark 4.2 and as Sedona's Geography on Spark 4.1.

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation. The section on reading GeoParquet 2.0 files in docs/tutorial/files/geoparquet-sedona-spark.md and its Chinese version describe the geography columns, with an example of each schema that a reader may have to give.

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.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 23, 2026
@jiayuasu
jiayuasu merged commit 35e48c8 into apache:master Nov 23, 2026
43 checks passed
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.

1 participant