Skip to content

GeoJSON output format - #108065

Merged
nihalzp merged 61 commits into
ClickHouse:masterfrom
nihalzp:geojson-output-format
Jun 27, 2026
Merged

nihalzp merged 61 commits into
ClickHouse:masterfrom
nihalzp:geojson-output-format

Conversation

@nihalzp

@nihalzp nihalzp commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

Related: #98124
Closes: #91533

Continuation of:

Additionally, it makes some small bug fixes to the GeoJSON input format like making id column return type Nullable(String) to differentiate between non-existent null vs empty string.

Changelog category (leave one):

  • New Feature

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

Add the GeoJSON output format for writing GeoJSON FeatureCollection documents, producing one feature per row. The single geo-typed column (Point, LineString, MultiLineString, Polygon, MultiPolygon, Ring, or Geometry) becomes each feature's geometry; a column named id becomes the feature id; and any remaining columns become the feature properties, where a lone object-typed column named properties (a JSON, Map, or named Tuple) is written directly as the properties object. A Ring is written as a single-ring Polygon. The new format_geojson_validate_geometry setting (enabled by default) controls whether geometries that are not valid GeoJSON shapes — such as a Polygon with fewer than four points or an unclosed Polygon ring — are rejected when reading and writing. Additionally, the GeoJSON input format now infers the id column as Nullable(String) instead of String, so a feature with an absent or explicit "id": null member is read as NULL and kept distinct from an empty string "".

Version info

  • Merged into: 26.7.1.148

nihalzp added 30 commits June 20, 2026 21:19
@mneedham

Copy link
Copy Markdown
Contributor

I tested this out and the semantics of how it works look good to me

@nihalzp
nihalzp added this pull request to the merge queue Jun 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 26, 2026
Comment thread docs/en/interfaces/formats/GeoJSON.md Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.30% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.50% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 316/319 (99.06%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@nihalzp
nihalzp added this pull request to the merge queue Jun 27, 2026
Merged via the queue into ClickHouse:master with commit 32e0185 Jun 27, 2026
169 checks passed
@nihalzp
nihalzp deleted the geojson-output-format branch June 27, 2026 03:58
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @nihalzp @mneedham — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

pull Bot pushed a commit to Haofei/ClickHouse that referenced this pull request Jun 27, 2026
pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Jul 7, 2026
…ursion bound, and a GEOS differential oracle

Adds test coverage for the GeoJSON input/output format (introduced in ClickHouse#108065,
closes ClickHouse#91533) that the original PR did not cover:

- 04490_geojson_input_geometry_collection.sql: the unrepresentable-geometry
  policy for MultiPoint and GeometryCollection. By default such features are
  rejected; with input_format_geojson_unsupported_geometry_handling = 'null'
  they are validated and stored as NULL. Covers recursive (nested)
  GeometryCollection validation, an empty GeometryCollection, and confirms a
  malformed or degenerate member is still rejected in the 'null' mode, so the
  choice is only unrepresentable-but-valid -> NULL versus throw and never lets
  malformed data through. Also covers the interaction with
  format_geojson_validate_geometry and the validation-only path taken when the
  geometry column is not selected.

- 04491_geojson_input_deep_recursion.sh: recursion is bounded by
  input_format_json_max_depth, so a pathologically nested document raises
  TOO_DEEP_RECURSION instead of exhausting the parser stack. Exercised for
  nested GeometryCollections and for strictly skipped ignored values, with the
  limit lowered so the check is deterministic and cheap.

- tests/integration/test_geojson_format: a differential test against Shapely
  (GEOS), an independent RFC 7946 parser, to catch a consistent
  misinterpretation that a ClickHouse-only round-trip cannot. Each geometry is
  round-tripped through ClickHouse (GeoJSON -> Geometry -> GeoJSON) and compared
  against the oracle. Covers the RFC 7946 Appendix A geometries plus adversarial
  cases: high-precision coordinates, an antimeridian-crossing line, the silent
  altitude drop, non-RFC winding-order preservation, and the accept/reject
  asymmetry for degenerate geometries.

Related: ClickHouse#108065
alexey-milovidov added a commit that referenced this pull request Jul 23, 2026
Query forwarding to external databases (#107740) is based on Denis
Vidiaev's #79652, the GeoJSON output format (#108065) on Mark Needham's
#98124, and SZ3 (#108788) revives Konstantin Vedernikov's #83088.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Query forwarding to external databases (ClickHouse#107740) is based on Denis
Vidiaev's ClickHouse#79652, the GeoJSON output format (ClickHouse#108065) on Mark Needham's
ClickHouse#98124, and SZ3 (ClickHouse#108788) revives Konstantin Vedernikov's ClickHouse#83088.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ursion bound, and a GEOS differential oracle

Adds test coverage for the GeoJSON input/output format (introduced in ClickHouse#108065,
closes ClickHouse#91533) that the original PR did not cover:

- 04490_geojson_input_geometry_collection.sql: the unrepresentable-geometry
  policy for MultiPoint and GeometryCollection. By default such features are
  rejected; with input_format_geojson_unsupported_geometry_handling = 'null'
  they are validated and stored as NULL. Covers recursive (nested)
  GeometryCollection validation, an empty GeometryCollection, and confirms a
  malformed or degenerate member is still rejected in the 'null' mode, so the
  choice is only unrepresentable-but-valid -> NULL versus throw and never lets
  malformed data through. Also covers the interaction with
  format_geojson_validate_geometry and the validation-only path taken when the
  geometry column is not selected.

- 04491_geojson_input_deep_recursion.sh: recursion is bounded by
  input_format_json_max_depth, so a pathologically nested document raises
  TOO_DEEP_RECURSION instead of exhausting the parser stack. Exercised for
  nested GeometryCollections and for strictly skipped ignored values, with the
  limit lowered so the check is deterministic and cheap.

- tests/integration/test_geojson_format: a differential test against Shapely
  (GEOS), an independent RFC 7946 parser, to catch a consistent
  misinterpretation that a ClickHouse-only round-trip cannot. Each geometry is
  round-tripped through ClickHouse (GeoJSON -> Geometry -> GeoJSON) and compared
  against the oracle. Covers the RFC 7946 Appendix A geometries plus adversarial
  cases: high-precision coordinates, an antimeridian-crossing line, the silent
  altitude drop, non-RFC winding-order preservation, and the accept/reject
  asymmetry for degenerate geometries.

Related: ClickHouse#108065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

GeoJSON as a input/output format

4 participants