Repository navigation
Conversation
They convert one GeoJSON geometry object to `Geometry` and back, with the aliases `ST_GeomFromGeoJSON` and `ST_AsGeoJSON`. The geometry reader and writer of the `GeoJSON` format become free functions, so both follow the same rules and settings. Closes: ClickHouse#126458
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
@alexey-milovidov ready for review. This implements ClickHouse/ClickHouse#126458 and reuses the geometry reader and writer of the GeoJSON format, so the functions follow its rules and settings. Could you approve CI? One deviation from the issue: GeometryCollection can’t be stored in Geometry, so it is an error by default (NULL with input_format_geojson_unsupported_geometry_handling = 'null'), as in the format. The other choices are listed in the description. |
|
Workflow [PR], commit [09090d5] Summary: ✅
AI ReviewSummaryAdds Final VerdictStatus: ✅ Approve |
Master enabled `modernize-use-nodiscard` in `clang-tidy`.
|
@alexey-milovidov merged master to resolve the conflict in GeoJSONRowInputFormat.h: the discriminator map is now UnorderedMapWithMemoryTracking, as master changed it, because src/Processors/Formats is now checked for standard containers. The function methods are marked [[nodiscard]] for the new clang-tidy check. The two red checks from the previous run are unrelated: Code Review failed on access to its API key (ssm:GetParameter not allowed for the runner), and test_read_temporary_tables_on_failure/test.py::test_different_versions fails on master too (DID NOT RAISE). 05497_read_geojson_and_geojson_functions passed all 431 runs, including ASan, UBSan, MSan, TSan and the flaky check. |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/geoJSON.cpp.o |
new | 551.86 KiB | +551.86 KiB |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
2781 translation units recompiled, 10366 s compile time in total, 2780 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Functions/geoJSON.cpp: 9.7 s
The value was converted to text with the output settings of the session, so `output_format_float_precision` rounded the coordinates. It now uses default settings, and `Float32` and `BFloat16` in a `Tuple` are widened to `Float64` first, as a cast does.
Rewriting the type and casting failed for `Variant` alternatives that collide or change, and missed `Dynamic` values. Write each `Float32` and `BFloat16` as `Float64` while walking the value instead.
The adaptors hold only the overload resolver, which had no `updateHash`, so the settings a function captured were lost in the expression hash and the query condition cache mixed results of different settings.
|
@alexey-milovidov CI is green now. I merged master to fix the GeoJSONRowInputFormat.h conflict, and since then I've fixed JSON/Tuple argument reading so it doesn't lose precision. 05497 passed all 431 runs across the ASan/MSan/TSan/UBSan and flaky checks. Could you take a look when you have time? Thanks! |
Add readGeoJSON and geoJSON functions
Adds
readGeoJSON(aliasST_GeomFromGeoJSON) andgeoJSON(aliasST_AsGeoJSON), to convert a single GeoJSON geometry object toGeometryand back. GeoJSON geometries often come as a field of JSON Lines or a string column of CSV, and theGeoJSONformat only reads a wholeFeatureCollection.The functions reuse the geometry reader and writer of the
GeoJSONformat (moved out of the format classes into free functions), so they follow the same rules and the same settings:format_geojson_validate_geometry,input_format_geojson_unsupported_geometry_handlingandprecise_float_parsing.readGeoJSONtakes aString, aJSONvalue, the namedTuplethat schema inference gives for ageometryobject in JSON Lines, orDynamic. A JSONnull, a NULL argument and a missing field of aJSONcolumn give NULL. Coordinates after the first two (altitude) are ignored.geoJSONtakes any geo type orGeometry. ARingis written as aPolygonwith one ring, because GeoJSON has no ring. ForGeometrythe result isNullable(String). Coordinates are written with full precision and never quoted; NaN and infinity are an error, because JSON has no such numbers.Both functions keep the settings they use and add them to
updateHash, astoJSONStringdoes, so the query condition cache tells results for different settings apart.geoJSONofGeometryandreadGeoJSONofDynamicrun behind theVariantandDynamicadaptors, which build the function for each type only when they execute it, and those adaptors dropped the hash. SoIFunctionOverloadResolvergetsupdateHash, andFunctionToOverloadResolverAdaptorand both adaptors forward it (test05813_geojson_query_condition_cache_adaptors). Resolvers that implementIFunctionOverloadResolverthemselves do not add a hash, as before.Choices a reviewer may want to change:
GeometryCollectioncan't be represented byGeometry, so by default it is an error, as in the format, and NULL withinput_format_geojson_unsupported_geometry_handling = 'null'. The issue lists seven types; six are supported.format_geojson_validate_geometry = 1,geoJSONrejects shapes that the reader would reject, such as an emptyLineStringor an unclosed ring, so the output can always be read back.JSONcolumn is a sub-object, so it is read asj.^geometry;j.geometrygives NULL. This is documented.JSONtype stores integers outside theInt64/UInt64range as strings, so aJSONvalue with such a coordinate (for example123456789012345680000) is rejected. AStringargument reads it fine.Checked locally: the new test 20/20 with random settings; 1M random
Float64bit patterns round-trip exactly throughStringand throughJSON; 200k random shapes of every type round-trip;geoJSONmatches the geometry written by theGeoJSONoutput format; deep nesting givesTOO_DEEP_RECURSIONinstead of a stack overflow;clang-tidyis clean.Closes: #126458
Related: #43941
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added functions
readGeoJSON(aliasST_GeomFromGeoJSON) andgeoJSON(aliasST_AsGeoJSON) to convert between a GeoJSON geometry object and theGeometrytype.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/129199]