Repository navigation
GeoJSON input format - #98124
GeoJSON input format#98124
Conversation
Adds a new `GeoJSON` input format that reads a GeoJSON FeatureCollection and yields one row per feature with a fixed schema: - `id Nullable(String)` — from `feature.id` if present - `geometry Geometry` — parsed into ClickHouse's `Geometry` variant type - `properties JSON` — the feature's properties object The format is gated behind `allow_experimental_geojson_format = 1`. Also adds `MultiPoint` to the `Geometry` variant type in `DataTypeCustomGeo`, since it was a legitimate GeoJSON geometry type that was previously missing. `GeometryCollection` is not supported and throws an exception with a descriptive message. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Add `done` flag to `GeoJSONRowInputFormat` so that once `]` of the features array is consumed, subsequent calls to `readRow` (which occur when `IRowInputFormat::read` is called for a second block) return `false` immediately instead of attempting to read past the end of the `features` array into the FeatureCollection closing `}`, which caused a `CANNOT_PARSE_INPUT_ASSERTION_FAILED` exception. - Pass the required `FormatSettings::JSON` third argument to `readJSONString` in `skipJSONValue` and `readGeometry`. - Update test to use `INSERT INTO … FORMAT GeoJSON` for the empty features array case, working around the known ClickHouse limitation where `format()` with zero rows raises `NOT_FOUND_COLUMN_IN_BLOCK`. - Add `.reference` file with expected test output. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace the hand-rolled `skipJSONValue` helper (which incorrectly used `JSONUtils::skipTheRestOfObject` — a function that calls `skipComma` before the first key-value pair, assuming it is called mid-object) with the existing `skipJSONField` from `IO/ReadHelpers.h`, which correctly skips any JSON value type including nested objects and arrays. This fixes a `CANNOT_PARSE_INPUT_ASSERTION_FAILED` exception when parsing real-world GeoJSON files that contain extra top-level keys before `features` (e.g., `crs`, `name`). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds the `input_format_geojson_geometry_collection_handling` setting to control behaviour when a `GeometryCollection` geometry type is encountered in `GeoJSON` input. Since `GeometryCollection` cannot be represented in ClickHouse's `Geometry` type, the options are: - `'throw'` (default) — throw an `INCORRECT_DATA` exception. - `'null'` — insert a `NULL` value for the `geometry` column and continue parsing. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Workflow [PR], commit [0a3fd0b] Summary: ✅
AI ReviewSummaryThis PR adds the Final VerdictStatus: ✅ Approve |
Documents the experimental `GeoJSON` input format: fixed output schema (`id`, `geometry`, `properties`), example usage with `file()` and `INSERT`, schema inference, and the `input_format_geojson_geometry_collection_handling` setting. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The MATERIALIZED column referenced `properties` which was not defined in the table. Added `properties JSON` to the schema so the expression is valid. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace generic 'Documentation for the GeoJSON format' with a meaningful meta description that appears in search results. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds words introduced by the GeoJSON input format to the aspell ignore list to fix the style check: - `GeoJSON`, `geojson` - `FeatureCollection` - `GeometryCollection` - `MultiPoint` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The id field in GeoJSON features is infrequently absent; using Nullable(String) complicates ORDER BY key usage. Changed the inferred schema to plain String, with an empty string default for missing ids. Updated the test and documentation accordingly. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Updates the setting description in Settings.cpp and the class comment in GeoJSONRowInputFormat.h to reflect that id is String, not Nullable(String). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The custom readRawJSONValue function was doing the same thing as the existing readJSONField utility in IO/ReadHelpers.h: reading any JSON value (object, array, string, scalar) into a String. Replace it with the standard utility and remove the now-unused WriteBufferFromString include. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…N test Three fixes: 1. Add `allow_experimental_geojson_format` and `input_format_geojson_geometry_collection_handling` to `SettingsChangesHistory.cpp` under 26.3 to fix `02995_new_settings_history`. 2. Remove `MultiPoint` from the `Geometry` variant type and the `DataTypeMultiPointName` class. `DataTypeVariant` sorts its sub-types alphabetically by name, so adding `MultiPoint` shifted the discriminants of `MultiPolygon`, `Point`, `Polygon`, and `Ring` by one. This broke `readWkt.cpp` (which hard-codes the old 6-type discriminant order) and caused `03444_flip_coordinates` to fail. 3. Remove the dead `MultiPoint` coordinate-parsing branch from `GeoJSONRowInputFormat::readGeometry` since the type is no longer in the `Geometry` variant and the branch was never reachable. Fixes: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98124&sha=eadc51a3b9f7213129f7964aaf826d266096b6da&name_0=PR&name_1=Fast+test&name_2=Tests Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Fix two CI failures in PR ClickHouse#98124: 1. `arm_tidy`: Split `Float64 lon, lat;` into two separate declarations in `readGeoJSONPoint` to fix the `readability-isolate-declaration` clang-tidy error (treated as `-warnings-as-errors` in the ARM tidy build). 2. Fast test `04003_geojson_input_format`: The reference file was generated with `PrettyCompactMonoBlock` output format (due to a local client config override), but CI runs `clickhouse-test` with stdout redirected to a file which defaults to `TabSeparated`. Regenerated the reference file in `TabSeparated` format to match CI output. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
With `async_insert = 1` enabled, the `clickhouse-client --multiquery` connection terminates silently after an INSERT with inline FORMAT data, causing all subsequent queries to be skipped. The `SELECT count()` after the empty GeoJSON insert never ran, so its output was missing from stdout, producing a "result differs with reference" failure in the `Stateless tests (amd_debug, AsyncInsert, s3 storage, parallel)` run. Add `SET async_insert = 0` before the CREATE/INSERT/SELECT block that tests the empty-features case. This test is about the GeoJSON format behaviour, not about async inserts, so disabling `async_insert` locally is the correct fix. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace manual token parsing with the utility functions already
available in `JSONUtils`:
- `skipArrayStart` / `checkAndSkipArrayEnd` instead of bare
`assertChar('[')` and `while (!eof && *pos != ']')` loops
- `skipObjectStart` / `checkAndSkipObjectEnd` instead of bare
`assertChar('{')` and `while (!eof && *pos != '}')` loops
- `skipComma` / `checkAndSkipComma` instead of
`if (*pos == ',') ++pos`
- `skipTheRestOfObject` in `readSuffix` instead of the equivalent
open-coded loop
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Three more simplifications on top of the previous JSONUtils refactor:
- Template the three nested-array coordinate readers
(`readGeoJSONLinearRing`, `readGeoJSONPolygonCoordinates`,
`readGeoJSONMultiPolygonCoordinates`) using a single
`readGeoJSONArray` helper, reducing them to one-liners.
- Replace the manual `'n'`-check + `insertDefault` blocks for the
`id` and `properties` fields with
`SerializationNullable::deserializeNullAsDefaultOrNestedTextJSON`,
which is the standard way other JSON-based formats handle nullable
values in non-nullable columns.
- Simplify the null check at the top of `readGeometry` by using
`JSONUtils::checkAndSkipObjectStart`: if `{` is not found the value
must be `null`, so we assert and insert default; otherwise the `{`
is already consumed and the field loop follows immediately.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…rmat
Add two local helpers in the anonymous namespace:
- `forEachFieldInJSONObject(buf, settings, handle_field)` — iterates
every field of an already-opened JSON object, calling
`handle_field(key)`. If the callback returns true the value was
consumed; otherwise the value is skipped with `skipJSONField`.
Used in `readRow` and `readGeometry`.
- `findFieldInJSONObject(buf, settings, key)` — scans a JSON object
for one specific field, skipping all others, and returns true with
the read position at the field value (or false after `}`).
Used in `readPrefix` to locate the `"features"` array.
This removes the three near-identical
`while (!checkAndSkipObjectEnd) { readFieldName; ... else skipJSONField;
checkAndSkipComma; }` loops that previously appeared independently.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The `GeoJSON` format no longer requires setting `allow_experimental_geojson_format = 1`. Removes the `allow_experimental_geojson_format` setting, the `SUPPORT_IS_DISABLED` guard in `GeoJSONRowInputFormat`, and all related test scaffolding. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds a shell test that loads a 258-feature GeoJSON FeatureCollection of world country boundaries (source: https://datahub.io/core/geo-countries/r/0.geojson) and verifies count, geometry type distribution (`Polygon`: 107, `MultiPolygon`: 151), and country name lookup by ISO 3166-1 alpha-2 code. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Remove the experimental note and `allow_experimental_geojson_format` requirement - Update examples to use `properties.name` instead of `JSONExtractString` - Add example showing automatic format detection from `.geojson` extension - Add example querying an ingested table - Rewrite format settings section as a dedicated `GeometryCollection` section Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace the two-Point cities example with a `berlin.geojson` file that mixes `Point`, `LineString`, and `Polygon` features with richer properties. This better demonstrates the `Geometry` variant type and `variantType` function. Adds a `WHERE variantType(geometry) = 'Point'` filter example and a materialized `feature_type` column in the table ingestion example. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace the Berlin example with a London dataset covering Tower of London (Point), River Thames (LineString), and Hyde Park (Polygon), with richer properties including `year_built`, `length_km`, and `area_km2`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Show how to use `variantType` to inspect geometry types per row, and how to access the underlying geometry data using the `geometry.Point`, `geometry.LineString`, and `geometry.Polygon` variant sub-column syntax. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`aspell-dict.txt` was deleted in master along with the `aspell` and `codespell` style checks. Removing the file here so the PR can merge cleanly without a modify/delete conflict.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 483/496 (97.38%) | Lost baseline coverage: none · Uncovered code |
f3d0c03
|
Hi @mneedham @nihalzp — while reviewing this PR I found the following:
Could you review the test PR and add the |
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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the
GeoJSONinput format for reading GeoJSONFeatureCollectiondocuments, producing one row per feature withid(String),geometry(Geometry), andproperties(Nullable(JSON)) columns.Point,LineString,MultiLineString,Polygon, andMultiPolygongeometries are read into ClickHouse's nativeGeometrytype.GeometryCollectionandMultiPoint, which theGeometrytype cannot represent, raise an exception by default, or can be stored asNULLvia theinput_format_geojson_unsupported_geometry_handlingsetting. Contributes to #91533.Documentation entry for user-facing changes
Version info
26.6.1.1025