Repository navigation
Conversation
…Impl`
`polygonsIntersectCartesian` and `polygonsWithinCartesian` are defined for
areal geometries only: `boost::geometry::intersects` and `within` have no
meaning for a `Point` or for the one-dimensional kinds, so both functions
refuse them at any argument position.
They refused them while EXECUTING, from inside `callOnTwoGeometryDataTypes`,
with `getReturnTypeImpl` returning `UInt8` without looking at its arguments at
all. A rejection bound to the data path rather than to the query plan is not
observable when nothing is evaluated, so anything that removes every row --
an empty part, a constant-false filter, primary-key pruning -- answers `0`
instead of raising:
SELECT polygonsIntersectCartesian(p, poly) FROM t WHERE 0;
answered `0` for a `Point` column `p` that the function rejects outright.
`checkArealPredicateArgumentTypes` (`Functions/geometryConverters.h`) states
that domain once, deriving it from the same `callOnTwoGeometryDataTypes`
dispatch that executes the predicate, and both functions apply it from
`getReturnTypeImpl`. The rejection now happens during analysis, uniformly
with every other function, and raises from `EXPLAIN` alone.
The `if constexpr` throw chain in `executeImpl` is left in place. It is
unreachable now, but the converters still need it to compile.
Related: ClickHouse#116786
Related: ClickHouse#104437
Co-Authored-By: Claude Opus 5 <[email protected]>
|
@PedroTadim ptal |
Generalize `checkArealPredicateArgumentTypes` into `checkGeometryArgumentType` / `checkGeometryArgumentTypes`, parameterized by a bit set of refused geometry kinds, and call them from `getReturnTypeImpl` in every geometry function that dispatched on the argument type from `executeImpl`: `polygonsUnion`, `polygonsIntersection`, `polygonsSymDifference`, `polygonsIntersect`, `polygonsWithin`, `polygonsEquals`, `polygonsDistance`, `polygonArea`, `polygonPerimeter`, `polygonConvexHull`, `geometryIntersect`, `wkt`, `svg`, `h3PolygonToCells`, `h3PolygonToCellsWithContainment`. A rejection raised from `executeImpl` is bound to the data path rather than to the query plan, so anything that removes every row suppresses it silently: with a `Nullable` argument, `useDefaultImplementationForNulls` returns early for `input_rows_count == 0`, and a sibling conjunct that filters the block empty makes the function answer as if the argument had been valid. Raising from analysis makes the rejection depend on the argument types alone. Closes: ClickHouse#116786 Closes: ClickHouse#117208 Co-Authored-By: Claude Opus 5 <[email protected]>
getReturnTypeImplgetReturnTypeImpl
|
🕵 Widened to every geometry function, so this now closes both issues.
New test |
|
The analysis-time checks signal type rejection with error codes the
On current master all of these work, because these functions use the default SELECT wkt(CAST((0., 0.)::Point AS Variant(Point, String))); -- 'POINT(0 0)'
SELECT polygonAreaCartesian(CAST([[(0.,0.),(1.,0.),(1.,1.),(0.,1.)]]::Polygon AS Variant(Polygon, String))); -- -1
SELECT polygonsIntersectCartesian(CAST([[(0.,0.),(2.,0.),(2.,2.),(0.,2.)]]::Polygon AS Variant(Polygon, String)), [[(1.,1.),(3.,1.),(3.,3.),(1.,3.)]]::Polygon); -- 1
SELECT polygonConvexHullCartesian(CAST([(0.,0.),(2.,0.),(1.,1.)]::Ring AS Variant(Point, Ring))); -- [[(0,0),(1,1),(2,0),(0,0)]]With this change they fail during analysis, independent of the values and of Suggestion: make For the concrete (non- |
`FunctionBaseVariantAdaptor` resolves a function per `Variant` alternative at build time and skips an alternative only for `ILLEGAL_TYPE_OF_ARGUMENT`, `TYPE_MISMATCH`, `CANNOT_CONVERT_TYPE` and `NO_COMMON_TYPE`; anything else is re-thrown, and the same list guards the lenient `variant_throw_on_type_mismatch = 0` paths. Two of the analysis-time rejection paths raised `BAD_ARGUMENTS`: `callOnGeometryDataType`'s own "Unknown geometry type", reachable from `getReturnTypeImpl` whenever a `Variant` lists a non-geometry alternative, and `polygonConvexHull`'s `Point` rejection. Moving those rejections into `getReturnTypeImpl` therefore turned queries over `Variant` arguments into hard analysis errors even when every stored value is a valid geometry. `callOnGeometryDataType` and `callOnTwoGeometryDataTypes` now take the code for the unknown-type throw, defaulting to `BAD_ARGUMENTS` so the execute-time dispatch is unchanged, and the analysis-time checks pass `ILLEGAL_TYPE_OF_ARGUMENT` for both the refused-kind and the unknown-type throw. `polygonConvexHull`'s check uses it too, matching its ten siblings. A `Variant` alternative a geometry function refuses is skipped again, keeping the uniform `Variant` semantics every other function has. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
|
🕵 Good catch — fixed in 01a603b, and you were right that this was a real regression for
All four of your queries now answer exactly as they do on master:
Thanks also for probing the full kind matrix on the concrete types; agreed that the h3 functions' |
|
Workflow [PR], commit [0c42668] Summary: ✅
AI ReviewSummaryThis PR moves geometry-function argument-domain validation into Final Verdict✅ No actionable findings. LLVM Coverage ReportMeasured on commit 0c42668.
Changed lines: Changed C/C++ lines covered: 110/123 (89.43%) · Uncovered code |
…308_polygon_area` The style check requires every translation unit to declare the error codes it uses in its own `ErrorCodes` block, even when the code resolves through an included header: `ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT is used in file polygonConvexHull.cpp but not defined`. `01308_polygon_area` asserted `BAD_ARGUMENTS` for `SELECT polygonAreaCartesian([])`. An `Array(Nothing)` argument reaches `callOnGeometryDataType`'s "Unknown geometry type" throw, which now signals `ILLEGAL_TYPE_OF_ARGUMENT` so that `FunctionBaseVariantAdaptor` reads it as type incompatibility and skips the alternative. The expectation moves with it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117567&sha=01a603b9b64b9722a98d059409182112e13296ad&name_0=PR Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes24 object files changed (+241.18 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units49 translation units recompiled, 477 s compile time in total, 49 of them have a recent master baseline. |
… rejection `h3PolygonToCells` refuses a `Point` first argument from `getReturnTypeImpl` now, so the rejection is decided from the argument type and raises `ILLEGAL_TYPE_OF_ARGUMENT` rather than the `ILLEGAL_COLUMN` the execute-time `checkAndGetColumn` used to raise once the column arrived. Both `Point` cases move with it; the second argument's `String` case still reaches `executeImpl` and keeps `ILLEGAL_COLUMN`. The header comments described the old execute-time coverage, which no longer applies to the first argument, and are rewritten to match. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117567&sha=12168680da43786de2f968323d8453733c28e167&name_0=PR Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
`h3PolygonToCells` and `h3PolygonToCellsWithContainment` now refuse a `Point` first argument from `getReturnTypeImpl`, but the test only pinned the error code, which a purely execute-time check could also produce. Add `EXPLAIN` cases, which evaluate no rows at all, so the analysis-time rejection is what is actually exercised, plus a positive case keeping the accepted domain covered. `h3PolygonToCellsWithContainment` is changed by this pull request and had no test at all. Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
`wkb` was the one geometry function left on the execute-time path: it returned `String` for every argument type and only refused unreadable ones from `executeImpl`. That leaves it with exactly the bug class this pull request fixes elsewhere -- `EXPLAIN SELECT wkb(n)` on a `Nullable(UInt8)` column passed analysis, and a `Variant` alternative it refuses could not be skipped, because the refusal was not signalled as a type mismatch until execution. Its accepted domain is every geometry kind the dispatch reads except `Ring`, which has no WKB representation, so the check is `checkGeometryArgumentType<CartesianPoint, GeoKindRing>` with `ILLEGAL_TYPE_OF_ARGUMENT`. The wording of the message is unchanged. Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
…ution The previous commit stated `wkb`'s domain through `callOnGeometryDataType`, which reads anonymous structural types -- `Array(Array(Tuple(Float64, Float64)))` and friends -- that `executeImpl` has no WKB transform for, because it selects the transform by the type's name. So those types passed analysis and were still refused at execution, exactly the split this pull request removes. Extract `tryGetWKBTransform` and call it from both `getReturnTypeImpl` and `executeImpl`, so there is a single predicate and the two cannot drift. Everything the function refuses now raises `ILLEGAL_TYPE_OF_ARGUMENT`, which `FunctionBaseVariantAdaptor` reads as type incompatibility, instead of `BAD_ARGUMENTS`. Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
…rters The build profile diff flagged 20 object files growing by 2.34 MiB in total, `polygonsIntersect.cpp.o` by 11.45%. The cause is that the argument-domain checks ran through `callOnGeometryDataType`, so every function instantiated the whole converter dispatch a second time, and the two-argument functions instantiated the 7x7 cross product of `callOnTwoGeometryDataTypes` twice. The checks never needed the converters: they ask about the TYPE, and a converter only matters once there is a column to read. Add `geoKindOf`, a plain function mirroring the same dispatch chain but answering with a `GeoKindBits` bit, and make `checkGeometryArgumentType` and `checkGeometryArgumentTypes` ordinary functions taking the rejected kinds as a runtime argument, so they cost no instantiations at all. `geoKindBitOf` had no other caller and is gone. Measured locally: `polygonsIntersect.cpp.o` 3651248 -> 3280304 bytes and `polygonsSymDifference.cpp.o` 20392888 -> 20020328, each recovering slightly more than the reported regression. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117567&sha=1868d1dbe51a28553dec0b772959725f083bedf8&name_0=PR&name_1=Build%20profile%20diff Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
|
@PedroTadim @zlareb1 ptal. It's pretty small and ready to be landed. |
Two remnants of the execute-time checks were left behind by the move to `getReturnTypeImpl`, both unreachable from a query. `polygonConvexHull` raised `BAD_ARGUMENTS` for a `Point` argument while every other function in the family raised `ILLEGAL_TYPE_OF_ARGUMENT` for the same rejection. The branch cannot simply be deleted: `callOnGeometryDataType` instantiates the continuation for every converter, and `boost::geometry::convex_hull` has no overload taking a point, so the branch is load-bearing at compile time. It now raises the same code as its siblings, with a comment recording why it stays. `callOnGeometryDataType` and `callOnTwoGeometryDataTypes` still carried an `unknown_type_error_code` parameter. No caller passes it any more -- the argument-domain checks stopped routing through it once they were de-templated -- so it is removed and the code is hard-coded to `BAD_ARGUMENTS`, exactly what the remaining callers `MVTEncodeGeom` and the BigQuery conversions already got. They dispatch without an analysis-time check, so their user-visible error code is deliberately left alone. Neither change is observable from SQL; `04145` and `05056` continue to pass. Related: ClickHouse#117567 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BfLNA7mjyk7MGB6sNNsFBi
ping |
Every geometry function dispatches on its argument types, via
callOnGeometryDataType/callOnTwoGeometryDataTypes, and raises for a type it cannot read or a geometry kind it refuses —boost::geometry::intersects,within,union_,intersectionandsym_differencehave no meaning for aPointor for the one-dimensional kinds, andpolygonArea/polygonPerimeter/polygonConvexHullrefuse aPointlikewise.That dispatch ran from
executeImpl, withgetReturnTypeImplreturning without looking at its arguments at all. A rejection bound to the data path rather than to the query plan is not observable when nothing is evaluated, so anything that removes every row — an empty part, a constant-false filter, primary-key or skip-index pruning — answers as if the argument had been valid:answered
0for aPointcolumn the function rejects outright. The same hole opens with no pruning at all: with aNullableargument,useDefaultImplementationForNullsmakesIFunction::executereturn early forinput_rows_count == 0, so a sibling conjunct that filters the block empty suppresses the exception — the reproduction in #117208.checkGeometryArgumentTypeandcheckGeometryArgumentTypes(src/Functions/geometryConverters.h) state the accepted domain once, ascallOnGeometryDataType's dispatch minus a bit set of refused geometry kinds, derived from the very dispatch that executes the function. Every geometry function now applies one of them fromgetReturnTypeImpl:polygonsUnion,polygonsIntersection,polygonsSymDifference,polygonsIntersect,polygonsWithin,polygonsEquals,polygonsDistance,polygonArea,polygonPerimeter,polygonConvexHull,geometryIntersect,wkt,svg,h3PolygonToCellsandh3PolygonToCellsWithContainment. The rejection now happens during analysis, uniformly with every other function, and raises fromEXPLAINalone.The
if constexprthrow chains inexecuteImplare left in place: they are unreachable now, but the converters still need them to compile.MVTEncodeGeomalready validated its argument ingetReturnTypeImpland is unchanged.Split out of #104437, which needs this property to prune
spatial_bboxgranules for these predicates without restating their accepted domain; that pull request carries an earlier copy of the code and will absorb this one when it lands.Closes: #116786
Closes: #117208
Related: #104437
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed geometry functions (
polygonsIntersectCartesian,polygonsUnionCartesian,polygonAreaCartesian,wktand others) answering as if the argument had been valid, instead of raising, for an argument type or geometry kind they reject, when the query evaluated them on no rows.Workflow [PR]
Sync PR [sync-upstream/pr/117567]