Skip to content

Support the Parquet GEOMETRY and GEOGRAPHY logical types - #125131

Merged
alexey-milovidov merged 20 commits into
masterfrom
parquet-geometry-logical-type
Oct 21, 2026
Merged

alexey-milovidov merged 20 commits into
masterfrom
parquet-geometry-logical-type

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Support the Parquet GEOMETRY and GEOGRAPHY logical types (https://github.com/apache/parquet-format/blob/master/Geospatial.md) in the native Parquet reader and writer.

Reading: columns annotated with GEOMETRY or GEOGRAPHY are decoded from WKB into ClickHouse geo types, even without GeoParquet geo metadata. The type comes from an explicit type hint, then from the GeoParquet metadata, then from GeospatialStatistics (if all column chunks list one 2D type), and is Geometry otherwise. If GeospatialStatistics list a geometry type with Z and/or M coordinates (not supported by ClickHouse geo types), the column is read as raw WKB String. A String hint returns raw WKB. GEOGRAPHY is read into the same types; CRS and edge interpolation are not represented. Min/max statistics of these columns are ignored, as the spec requires. Spatial pruning by geospatial_statistics.bbox now also handles bounding boxes that cross the antimeridian (xmin > xmax).

Writing: the new setting output_format_parquet_geometry_logical_type annotates WKB geo columns with GEOMETRY and writes GeospatialStatistics (bbox and geometry types) instead of min/max statistics and the column index. A Geometry column is then also described in the geo metadata. The setting is disabled by default, because readers that don't know the logical type (Arrow C++ / pyarrow before 20) can't open the whole file.

The ParquetMetadata format now shows geospatial_statistics.

Tests include reference files from apache/parquet-testing data/geospatial/ (written by Arrow C++ and DataFusion) and pyarrow-written files.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Support the Parquet GEOMETRY and GEOGRAPHY logical types: such columns are read as ClickHouse geo types, and GeospatialStatistics are used for spatial pruning. Geo columns can be written with the GEOMETRY logical type and GeospatialStatistics with the new setting output_format_parquet_geometry_logical_type.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125131]

Version info

  • Merged into: 26.11.1.383-master (included in 26.11 and later)

alexey-milovidov and others added 4 commits October 11, 2026 02:35
Add the `have_geospatial_statistics` and `geospatial_statistics` (bounding box
and geometry type codes) fields to the column chunks of `row_groups`. They are
present for columns with the Parquet `GEOMETRY` and `GEOGRAPHY` logical types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading: `BYTE_ARRAY` columns annotated with `GEOMETRY` or `GEOGRAPHY` are
decoded from WKB into ClickHouse geo types, also without the GeoParquet `geo`
metadata. The geometry type is taken from the explicitly requested type, then
from the `geo` metadata, then from `GeospatialStatistics` if all column chunks
list the same single 2D type; otherwise `Geometry`. A `String` type hint returns
the raw WKB. Controlled by `input_format_parquet_allow_geoparquet_parser`.
`GEOGRAPHY` is read into the same types (edge interpolation and CRS are not
represented). Min/max statistics and the column index of these columns are
ignored, as the sort order is undefined. Spatial pruning by
`GeospatialStatistics` now also handles a bounding box that crosses the
antimeridian (`xmin > xmax`).

Writing: WKB geo columns are annotated with `GEOMETRY` (default CRS) and get
`GeospatialStatistics` instead of min/max statistics and the column index. A
`Geometry` column is now also described in the `geo` metadata, with an empty
list of geometry types. New setting `output_format_parquet_geometry_logical_type`
(enabled by default, disabled by `compatibility` before 26.10).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading files written by Arrow C++ (`pyarrow`) and the files from
apache/parquet-testing `data/geospatial/` (`crs-default.parquet`,
`crs-geography.parquet`, `crs-srid.parquet`, `geography-points.parquet`),
round trip of ClickHouse geo types, written metadata and statistics, settings,
and spatial pruning by `GeospatialStatistics`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Readers that do not know the `GEOMETRY` logical type cannot open the whole
file: Arrow C++ and `pyarrow` before version 20 fail with "Metadata contains
Thrift LogicalType that is not recognized", and older parquet-java / Spark 3.x
are likely affected as well. Disable the setting by default and describe the
default write behavior in the documentation as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7ee673a]

Summary: ✅


AI Review

Summary

Adds native Parquet GEOMETRY and GEOGRAPHY decoding, optional GEOMETRY output with GeospatialStatistics, spatial pruning, and metadata inspection. Reviewed the complete diff at 7ee673ae634694046077fd4d46c05c7fe5016371, surrounding reader/writer paths, regression tests, and every prior discussion. No actionable findings remain; the earlier fixes hold in the current code, and the deliberate geography interpretation is adequately explained.

Missing context / blind spots
  • ⚠️ Tests were not executed locally because this checkout has no ClickHouse binary or build. The current-head targeted CI report has not published test results yet; its completion will provide independent runtime validation of the checked-in regressions.
Final Verdict

✅ Approve. No new inline findings or thread changes are needed.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Oct 11, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Oct 11, 2026
alexey-milovidov and others added 3 commits October 12, 2026 01:07
Address review: when `GeospatialStatistics` of a `GEOMETRY` / `GEOGRAPHY`
column list a geometry type with Z and/or M coordinates (ISO WKB codes
1000+), `parseWKBFormat` cannot decode the values. Return the raw WKB
bytes as `String` for such columns instead of inferring `Geometry` and
throwing during decoding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dictionary page of a Parquet column chunk with only NULLs has no values.
For a `GEOMETRY` column decoded into `Geometry`, `GeoConverter::convertColumn`
was called with `num_values = 0` and evaluated `offsets[num_values - 1]`,
which is a pointer overflow reported by UBSan and aborted the
`05360_parquet_geometry_logical_type_write` test in sanitizer builds:

    Decoding.cpp:2401:5: runtime error: addition of unsigned offset to 0x... overflowed to 0x...

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125131&sha=a2db6624ac81361b9af2c6fc9424a0068c3b6040&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
#125131

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `output_format_parquet_geometry_logical_type`, the column carries the
`GEOMETRY` logical type with its default CRS (`OGC:CRS84`), while the `geo`
metadata said `"crs": "EPSG:4326"`, which has a different axis order. Omit
`crs` from the `geo` metadata in this case: in GeoParquet an omitted `crs`
means `OGC:CRS84` as well, so both kinds of metadata agree. Without the
logical type, the metadata is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125131&sha=1df2112fbe60a0079d6e7af19de8b3d87f488ff7&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%201%2F4%29 (test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads timed out after 900 s inside a Spark spark.sql call, before ClickHouse reads anything; unrelated to this PR) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #125448 (mine, merged 2026-10-13 01:47Z). This run predates it: the workflow was triggered at 2026-10-12 18:48Z, so the tested tree did not have it.

What happened in this job: on xdist worker gw2, test_storage_delta/test_writes_interop.py ran first, and test_concurrent_reads then reused its Spark JVM (the session conf still has the interop-only keys and spark.app.submitTime = 23:29:06Z, the interop module's start). The JVM-wide Hadoop FileSystem cache gave the new session the old s3a://root FileSystem, still bound to the previous module's MinIO, so getFileStatus failed with No route to host and spark.sql hung until the 900 s timeout. The retry in a fresh process on gw0 passed. #125448 clears that cache when a live JVM is reused.

Since the merge, all 20 failures of this test were in workflows triggered before 01:47Z, each with the interop module on the same worker; master has 85 passes and no failure on a tree with the fix. The new head cfc6f7c is tested merged with current master, so it includes the fix.

@clickhouse-gh clickhouse-gh Bot added comp-parquet-reader-v3 Issues related to the native Parquet reader. and removed comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 7ee673ae634694046077fd4d46c05c7fe5016371 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

…gical-type

# Conflicts:
#	src/Client/BuzzHouse/Generator/SessionSettings.cpp
#	src/Core/FormatFactorySettings.h
#	src/Formats/FormatFactory.cpp
#	src/Formats/FormatSettings.h
#	src/Processors/Formats/Impl/Parquet/Write.h
#	src/Processors/Formats/Impl/ParquetBlockOutputFormat.cpp
#	src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, thanks for the explanation of the Iceberg timeout; confirmed that #125448 is on master.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125131&sha=cfc6f7c5d1165b1f3842bfcd7150a2cf8e9fda7b&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 (Logical error: Cannot call function A because is has B arguments but C columns were captured (STID: 2458-4cb4), from ReadFromFile::createIterator filtering by the _etag virtual column under indexHint). It is unrelated to this PR: it has appeared in about 75 runs over many PRs and master since 2026-10-10, and it still appears after #125150 was merged. Please provide a fix in a separate PR. If the fix is already in progress, link it here.

The branch is now merged with the current master (conflicts with the new output_format_parquet_write_file_logical_type setting resolved by keeping both settings).

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #125126 (mine, merged 2026-10-13 15:34Z). This run predates it: the workflow for cfc6f7c5 was created at 11:43Z, so the tested tree did not have it. #125150 fixed the sibling indexHint arity defect (STID 3408-3735), not this one, which is why it kept appearing after #125150.

The abort is the reduced and that splitFilterNodeForAllowedInputs returns when ReadFromFile prunes files by virtual columns (getFilterByPathAndFileIndexes in the stack); #125126 rebuilds that and for the arguments it keeps. I ran this exact fuzzer query (with the 02841.parquet file from the reproduce commands) on the master debug builds on both sides of the merge: it aborts in ColumnFunction::reduce 10/10 on 2ca8bd90 (the merge's first parent) and passes 10/10 on 50b17deb.

All 4 CIDB occurrences after the merge (17:31Z to 18:27Z) come from runs created before it, and there are none since 2026-10-13 18:27Z. The current head ec568b15 contains #125126.

Address review:
- A bounding box crossing the antimeridian (`xmin > xmax`) bounds the vertices,
  but not the straight segments used by the Cartesian predicates, e.g.
  `polygonsIntersectCartesian`. Use the wrapped X range only if the column chunk
  is known to contain only points and multipoints.
- A NULL read into a non-nullable geo type becomes the default value, e.g. the
  point (0, 0), which is not covered by the bounding box. Do not prune if the
  column chunk can have NULLs and the query bounding box contains (0, 0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125131&sha=ec568b153c057b9bce2147e3f5b9bd89a419dd01&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%202%2F2%29 (04502_autopr_input_bytes_estimation_window_function: 04502_autopr_window_function_query_plan_based returned 0 instead of 1; the rerun with the same randomized settings failed 19/46, so it is flaky and unrelated to the Parquet changes) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The AST fuzzer (amd_debug, targeted) failure (STID 2959-3490, ReadFromURL::createIterator filtering by the key Hive partition column) is unrelated too and is being fixed in #125024.

The two review comments about GeospatialStatistics pruning are addressed in f050d6a.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. No fix for 04502_autopr_input_bytes_estimation_window_function is in progress yet; I am investigating the 04502_autopr_window_function_query_plan_based row and will follow up here with a separate PR (or my findings).

@groeneai

Copy link
Copy Markdown
Collaborator

The fix for 04502_autopr_input_bytes_estimation_window_function is #125877 (test-only). The failing check is the Output <= 2 * Input bound: that job drew ratio_of_defaults_for_sparse_serialization = 0, so key/value are stored Sparse and the output estimate is priced about 1.7x higher (Output/Input 1.28-2.21 over 47 runs). The PR pins the setting to 1.0 on the test's table; locally it is 200/200 with that job's settings vs 2-4/200 failing without it. It needs the can be tested label before CI runs.

alexey-milovidov and others added 3 commits October 15, 2026 17:45
…converts coordinates

If a geometry column is requested with a type that changes coordinates, e.g.
`Tuple(UInt8, UInt8)` instead of `Point`, the bounding box from the statistics
no longer bounds the values, so a matching row group could be pruned. Use spatial
pruning only if the requested type is raw WKB `String` or has `Float64`
coordinates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Parquet geospatial column read as `Nullable(Point)` lost its null map, so
NULLs silently became `(0,0)`. `Point` can be inside `Nullable`, so keep the
null map when `Nullable` is requested explicitly. Add regressions for this and
for spatial pruning with a narrowing coordinate type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and addressed both review threads (6415d28, e1a7627).

The remaining CI failures are unrelated to this PR:

alexey-milovidov and others added 6 commits October 15, 2026 22:05
The release branch for 26.10 was created in #126122

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/Processors/Formats/Impl/Parquet/SchemaConverter.cpp
…ad as `Point`

`pointInPolygon` accepts the `Array(Point)` representation of a `MultiPoint` as a polygon and
connects its vertices, so a bounding box crossing the antimeridian does not bound it. Use the
wrapped X range only if `geospatial_types` lists only points and the column is read as a `Tuple`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `GeospatialStatistics`

After #124364 the Parquet footer is parsed
without `RowGroup::columns`, so `getGeoTypeFromGeospatialStatistics` saw no column chunks
and inferred `Geometry` for every column with the `GEOMETRY` or `GEOGRAPHY` logical type.
`SchemaConverter` now takes the `FileFooter` and parses the chunks of only that column.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (6e4f724). After #124364 the Parquet footer is parsed without column chunks, so a column with the GEOMETRY logical type was always inferred as Geometry instead of the type from GeospatialStatistics. Fixed in 7ee673a: SchemaConverter now parses the chunks of only that column. All Parquet geo tests that run with clickhouse-local pass locally on the merged tree.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125131&sha=8d1e2e8335aad82bbb562247cd21b51ba4b69c93&name_0=PR&name_1=Storage%20memory%20check (05_multiple_tables.sql, live allocation delta master=+41,752 B, PR=+235,264 B) and provide a fix in a separate PR. If the fix is already in progress, link it here. It is unrelated to this PR: the scenario only creates and fills MergeTree tables, the differing stacks are MutationsInterpreter / Context::createCopy / ThreadGroup allocations rather than Parquet code, and the same scenario failed in the last week on the unrelated PRs #122854 and #124600.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is already open: #121545 (mine), the quiescent checkpoint agreed on #113201. Before each heap dump the profiler waits until the background executor task metrics are zero, so a finished mutation task is no longer charged to the next scenario.

8d1e2e83 is the conserved 04 -> 05 pair, not a low baseline:

Scenario master PR change
04_add_projection.sql +229,896 +36,384 -193,512 (OK)
05_multiple_tables.sql +41,752 +235,264 +193,512 (FAIL)

On the master arm the finished MATERIALIZE PROJECTION task was still alive at the after_04 dump and was freed during 05. Only a positive change fails, so the 04 half passes. #124600 @ 6dfdaae3 is the same pair (-213,568 / +213,568), and its re-run on that sha today is green. CIDB, 30 days: 16 such pairs, 12 of them since #121545 was opened. The #122854 reds are a different shape (master side normal, PR side +67,600 B, also on 02/03, clean on its final head), not this race.

The master arm runs the merge-base binary (get_merge_base_profiler_url()), so this red stops only once #121545 is on master; nothing to do on this PR. #121545 has had no review since 2026-09-22. It still merges cleanly, and its only CI reds were Upgrade check failures owned by other PRs. Could you review it? I can rebase it first if you want a fresh CI run.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit 6d49fd0 Oct 21, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the parquet-geometry-logical-type branch October 21, 2026 04:41
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parquet-reader-v3 Issues related to the native Parquet reader. pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants