Repository navigation
Declarative function signatures, continuation of #3775 - #104948
Conversation
|
This would also be an interesting way of supporting named arguments in all functions, so you can do |
…-2026 # Conflicts: # src/Common/ErrorCodes.cpp
|
Workflow [PR], commit [8c05b60] Summary: ✅
AI ReviewSummaryThis PR introduces declarative function signatures, uses them for return-type inference across many function families, and exposes them through Findings❌ Blockers
Tests
Missing context / blind spots
Final Verdict
|
`useable` → `usable`. From the "codespell" style check in PR #104948 (#104948). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The `WithContext` style guard is intended to prevent `Functions/*` from holding a copy of the query context that may expire under MergeTree default expressions and async inserts. The four entries added here deliberately use `WithContext` only to defer query-context lookup to `executeImpl` so the function can be instantiated by `system.functions` (which only reads `getSignatureString`) without a query context. All four are non-deterministic and are not used in default expressions, so the original concern does not apply. From the "various" style check in PR #104948 (#104948). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
These 29 functions previously declared error codes for hand-written argument validation in `getReturnTypeImpl`. With the declarative signature DSL, type-mismatch and arity checks are produced by `applyFunctionSignature`, so the local `extern const int` declarations are no longer referenced. From the "cpp" style check in PR #104948 (#104948). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`bugprone-empty-catch` is enforced in `arm_tidy`. The catch in `fillRow` is intentional: some functions throw on construction unless specific settings are enabled (e.g. deprecated / error-prone functions), and `system.functions` should still list them — just with an empty `signature` column. Annotate the catch with `NOLINT(bugprone-empty-catch)` to match the convention used in `TCPHandler.cpp`, `CacheDictionaryUpdateQueue.cpp` and other places where construction- failure swallowing is intentional. From the "arm_tidy" build in PR #104948 (#104948). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`Nullable(LowCardinality(T))` is not a valid SQL type — the well-formed nullable shape for a `LowCardinality(T)` argument is `LowCardinality(Nullable(T))`. Use `makeNullableOrLowCardinalityNullable` to mirror what hand-written `getReturnTypeImpl` implementations do for functions affected by `join_use_nulls`, `FULL JOIN`, `SEMI LEFT JOIN` on `LowCardinality` columns, `isNullable` on `toNullable(toLowCardinality(...))`, and similar cases. Fixes failures such as `01410_nullable_key_and_index_negate_cond`, `01049_join_low_card_crash`, `02007_join_use_nulls` etc. from the fast-test report in PR #104948 (#104948). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Several call sites reach `IFunction::getReturnTypeImpl` through the
`DataTypes` overload directly:
- `Analyzer/Resolve/resolveFunction.cpp` constructs a placeholder
`FunctionToFunctionBaseAdaptor` for `FunctionExists` (correlated
`EXISTS` decorrelation) and calls `getReturnTypeImpl(DataTypes{})`
to fill in the return type.
- MergeTree text-index pruning synthesizes a `like` call when expanding
`mapContainsKeyLike` / `mapContainsValueLike` to drive
`MergeTreeIndexConditionText`, and resolves its return type via the
same overload.
Without this fix the `DataTypes` overload throws `NOT_IMPLEMENTED` even
when the function exposes a non-empty `getSignatureString`, breaking
`02346_text_index_map_support`, `02346_text_index_hint_map`,
`03413_analyzer_correlated_subqueries_bug_2` and similar tests in the
PR #104948 fast-test report
(#104948).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…-2026 # Conflicts: # src/Functions/array/FunctionsMapMiscellaneous.cpp
Style check on #104948 reported ~30 `extern const int <CODE>;` declarations that became unused after the function-signature DSL replaced the hand-written argument validation in those functions. Drop each unused declaration; remove the empty `namespace ErrorCodes` block from `svg.cpp` where it was the only entry.
Three signature corrections requested in PR review: - `FunctionSpaceFillingCurve.h`: the tuple form of `mortonEncode` / `hilbertEncode` only required `TupleOfSize(N)` and let any element type through. Switched to `Tuple(NativeUInt, …)` so the per-element type is enforced at type-check time, matching the legacy `getReturnTypeImpl`. - `FunctionsCodingUUID.cpp`: `parseVariant` reads the optional second argument via `getInt(0)`, so the signature's `[Any]` was too wide. Narrowed to `[Integer]` on `UUIDNumToString`, `UUIDStringToNum`, `UUIDToNum`. - `extractAllGroups.h`: the regexp is read as a constant in `executeImpl` (`getValue<String>` on a `ColumnConst`), so the second argument must be `const StringOrFixedString`, not just `StringOrFixedString`.
Three functions had their declarative signatures advertise a hard `const tz StringOrFixedString` argument while the legacy code respected the `allow_nonconst_timezone_arguments` setting: with the setting enabled, a non-constant timezone is accepted and the result is tz-less `DateTime` / `DateTime64`. After the refactor, that path was lost — the resolver no longer kept the setting from `Context`. Restore the legacy `getReturnTypeImpl` override for `now64`, `toTimezone`, and `FunctionFromUnixTimestamp64`, keeping the setting and calling `extractTimeZoneNameFromFunctionArguments` with it. Drop the declarative signature for these — setting-gated argument constness is one of the exclusions noted in the PR description.
`FunctionExists` is a marker — the analyzer constructs it for correlated
EXISTS and the JOIN planner replaces it; it is never executed. Resolving
the function in `resolveFunction.cpp` calls
`function_exists->getReturnTypeImpl(DataTypes{})` with empty args because a
subquery has no regular column type. After the declarative-signature switch
the default base-class path runs the DSL and rejects 0 args against
`(Any) -> UInt8`, breaking every correlated EXISTS query
(`tests/queries/0_stateless/03315_analyzer_correlated_subqueries.sql`).
Override `getReturnTypeImpl(const DataTypes &)` to return `UInt8` directly,
restoring the marker semantics while keeping the declarative signature for
`system.functions` display.
Also update `02117_show_create_table_system.reference`: `system.functions`
now exposes the `signature` column.
The declarative function signatures replaced the manual type-checking code in many functions, leaving `extern const int ...;` declarations that the style check now flags as unused. Also reword the `Empty variable name` exception message in `FunctionSignature.cpp` to avoid the `Logical error:` literal that the style check rejects (the exception is already coded as LOGICAL_ERROR). CI report: #104948 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When a `const` matcher position in a declarative signature receives a non-constant column, the framework was throwing `ILLEGAL_TYPE_OF_ARGUMENT`. Several existing tests annotate this case with `serverError ILLEGAL_COLUMN`, matching the legacy code thrown by hand-written checks. Detect the "but it is not constant" suffix and surface `ILLEGAL_COLUMN` in that case. Affected tests include `01246_extractAllGroupsVertical`, `01277_random_fixed_string`, and `03130_generateSnowflakeId`. CI report: #104948 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… arguments as `const`
- Widen the timezone argument from `const String` to `const StringOrFixedString` in the
signatures of `ULIDStringToDateTime`, `UUIDv7ToDateTime`, the `toDateTime*Or{Zero,Null}` /
`parseDateTime*BestEffort*` family, `makeDateTime`, `makeDateTime64`,
`YYYYMMDDhhmmssToDateTime` and `YYYYMMDDhhmmssToDateTime64`, matching the legacy resolvers.
- Mark constant-only arguments as `const` in the signatures of `substringIndex`, `lemmatize`,
`roundDown`, `__patchPartitionID`, `minSampleSizeContinuous` and `minSampleSizeConversion`,
so non-constant arguments are rejected during analysis again.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-12, automated pass on head
|
…o-fasttest` The test uses `ULIDStringToDateTime` and `lemmatize`, which are not built in the fast test. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104948&sha=cc4ac15470daff65235b6fa6ee62a201c765d31e&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-13, automated pass on head
|
…zone check The empty-timezone guard in `FunctionDateOrDateTimeToDateTimeOrDateTime64`, `FunctionDateOrDateTimeToDateOrDate32` and `FunctionDateOrDateTimeToSomething` called `extractTimeZoneNameFromFunctionArguments` before the signature was applied, so a 2nd argument of a wrong type (e.g. `toStartOfHour(dt, 1)`) was reported by the timezone extractor as `ILLEGAL_COLUMN` instead of `ILLEGAL_TYPE_OF_ARGUMENT`. Apply the signature first. Address review: #104948 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-13, automated pass on head
|
… narrowed it - `ifNotFinite`: derive the result type from `if` built in the query context again, so it follows `use_variant_as_common_type` like `if` does; a `leastSupertype` signature ignored the setting. - `toInterval`: accept an `Interval` first argument, which the delegated `toInterval*` conversion supports (`toInterval(toIntervalDay(1), 'hour')` = 24). - `arrayAvg` / `arrayProduct`: accept `Enum` and `Interval` elements, as `ArrayAggregateImpl::getReturnType` and the executor do. - `FunctionDateOrDateTimeToSomething`: the `Interval` branch bypasses the signature, so run `checkArguments` there to reject a timezone and extra arguments. - `FunctionMapToArrayAdapter`: route the types-only `getReturnTypeImpl` to the adapter for documentation-only signatures, as `FunctionArrayMapped` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-14, automated pass on head
|
… narrowed it - `uniqThetaUnion` / `uniqThetaIntersect` / `uniqThetaNot`: the signature is documentation-only again, so sketches built from several `uniqTheta` arguments are accepted and mismatched inner-argument lists are rejected by the legacy validator. - `numericIndexedVectorPointwise*`: the signature is documentation-only again, so the legacy validator rejects sketches with different index or value types before `executeImpl` reinterprets the second state. - `bitShiftLeft` / `bitShiftRight` / `bitRotateLeft` / `bitRotateRight` / `bitTest`: the signatures are documentation-only, as in `bitAnd`, so `IPv4` / `IPv6` operands are accepted again. - `sign` / `roundAge` / `roundDuration`: accept 128-bit and 256-bit integers. - `nowInBlock`: accept a constant `FixedString` timezone. - `toInterval`: accept a numeric `FixedString` value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-15, automated pass on head
|
Now I think this can be merged. |
This is an experimental continuation of #3775 (2018) by @alexey-milovidov, which proposed a declarative way to describe function signatures so that argument validation and return-type inference can be driven by a small DSL instead of hand-written
getReturnTypeImpllogic per function.What's in this branch
A
getSignatureString()method onIFunctionandIFunctionOverloadResolver. When a function exposes a non-empty signature, the basegetReturnTypeImpl(ColumnsWithTypeAndName)parses and applies it via a small grammar of type matchers (UInt,Number,Array(T),MaybeNullable(T),Function((args), R),T : Anycapture, …) and type functions (leastSupertype,nativeNumber,aggregateFunctionReturnType(AggregateFunction(name, …)),subcolumnTypeOf,typeFromString,DateTime64(scale, tz), …). The DSL supports variadic positions (…), ellipsis grouping for repeated argument units (T1, V1, …repeats the pair),ORbetween alternatives, optional positions[T], const-value capture (const name String), lambdas, etc.The grammar / parser / type matchers / type functions live under
src/DataTypes/FunctionSignature.h,FunctionSignature.cpp,TypeMatchers.cpp,TypeFunctions.cpp.Coverage
~191 commits on top of master, each is a small per-family round titled
Function signatures: round N — …. Current state on this branch:(With `allow_experimental_nlp_functions = 1`; the few remaining unset ones are setting / config-gated functions like `aiClassify`, `region*`, `synonyms`, whose `create` throws unless the relevant config block / setting is present, so `system.functions.tryGet` returns null even though the signature is in source. With the right config + setting they all surface — verified in tmp/ test config.)
Roughly:
getReturnTypeImplis either gone or bypassed): higher-order array functions (arrayMap,arrayFilter,arrayFirst*, …),toIntervalX, comparison,multiSearch*/multiMatch*, vector L-norms / distances / dot product,UUIDv7ToDateTime,arrayReduce/arrayReduceInRanges,reverse,mapKeys/mapValues,getSubcolumn, theleast/greatestresolver, paired-variadictimeSeriesTagsToGroup/timeSeriesStoreTags, …system.functionsbut the legacygetReturnTypeImplstill runs because the result type uses promotion / widening / setting-dependent dispatch the current DSL can't express): arithmetic (plus,minus,multiply,divide, modulo / intDiv family), array widening (arraySum/arrayCumSum*/arrayDifference),mapContains*Like,dateTrunc,toStartOfWeek,parseDateTime*,transform,range,toXconversions, etc.There is a
signature_documentationopt-in alongsidesignaturein the binary-arithmetic, unary-arithmetic, FunctionArrayMapped, and FunctionMapToArrayAdapter families specifically so a function can advertise a signature without the DSL accidentally hijacking the legacy widening logic.Status
Draft / experimental.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/104948]
Version info
26.11.1.20-master(included in26.11and later)