Repository navigation
Add sqr arithmetic function - #109061
Add sqr arithmetic function#109061
Conversation
|
@alexey-milovidov Please approve the check workflow. Thank you. |
|
Workflow [PR], commit [217312e] Summary: ✅
AI ReviewSummaryThis PR adds the Findings
Final VerdictChanges requested. The |
The previous revision disabled the default `LowCardinality`, sparse and
replicated column implementations for `FunctionSqr` and forwarded a
duplicated argument pair `{arg, arg}` to the inner `multiply`. For a
constant `LowCardinality` argument the overload resolver reports the result
type as `LowCardinality` (a constant argument is not counted as a full
low-cardinality column in `IFunctionOverloadResolver::getReturnType`), so
`multiply` was then executed on two `LowCardinality` columns with a
`LowCardinality` result type. The default implementation supports only a
single `LowCardinality` argument, which raised `Logical error: Default
functions implementation for LowCardinality is supported only with a single
LowCardinality argument.`
This was found by the AST fuzzer and `FunctionsStress`, e.g.
`SELECT sqr(CAST(1964064 AS LowCardinality(UInt64)))`.
CI: ClickHouse#109061
`sqr` is a unary function, so let it use the default `LowCardinality`,
sparse and replicated implementations like every other unary function. Only
a single argument is ever low-cardinality, so the throwing path is never
reached, and `sqr(x)` now preserves `LowCardinality` by running the wrapped
`multiply` on the dictionary. This differs from `multiply(lc, lc)`, which
flattens two low-cardinality columns to a plain result, but that is the
expected behavior for a unary function; the test now checks the actual
behavior and adds a regression case for the constant `LowCardinality` input.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed Root cause: the previous revision disabled the default Fix: Verified locally: the fuzzer query and the full @alexey-milovidov note this is past your earlier LGTM (which was on the first commit) — worth a re-check of the last two commits. |
… the `sqr` test The AST fuzzer found the original logical error via `SELECT sqr(CAST(1964064 AS LowCardinality(UInt64)))`, which goes through `CastOverloadResolver` rather than the `toLowCardinality` function. Lock down that exact constant-`LowCardinality` surface as requested in review. The query needs `allow_suspicious_low_cardinality_types` (as the fuzzer runs it). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@lalitx17 Pushed
The |
|
The sole red —
The jobs that caught the earlier |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 26/41 (63.41%) · Uncovered code |
…cess The client-side AST fuzzer loop swallowed every exception thrown during a fuzzing step: the `catch (...)` handler recorded the error, the loop bottom reset it, and fuzzing continued. When the failure mode is persistent - most importantly a dead server, where the reconnection attempt inside `processParsedSingleQuery` throws instantly - the client sprints through the remaining corpus at hundreds of steps per second without contacting the server and exits with code 0, which the job reports as "Fuzzer exited with success". Evidence from `AST fuzzer (amd_debug, targeted)` on PR ClickHouse#109061 (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109061&sha=1419f6b7e95c81c812f945c06333998b92d56ad3&name_0=PR&name_1=AST+fuzzer+%28amd_debug%2C+targeted%29): `fuzzer.log` records 68972 fuzzing steps, of which 52837 produced no outcome (silent exception), while `server.log` shows the server received only 209 queries within a 47-second window before dying. On PR ClickHouse#106250 (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106250&sha=latest&name_0=PR&name_1=AST+fuzzer+%28amd_debug%2C+targeted%29) a 5-file corpus with ~20 SELECT statements (about 20000 fuzzing steps, over an hour of work at the measured debug-build rate of 2-6 steps/s) "completed" in 74 seconds and the job passed. Overall, 13-33% of targeted AST fuzzer runs per month finish in under 8 minutes of their 30-minute budget. Client fixes (`programs/client/FuzzLoop.cpp`): - Print thrown exceptions in the fuzzing-step catch handlers instead of swallowing them silently, so `fuzzer.log` shows what actually happened. - After a thrown exception, check the connection via `tryToReconnect` (the same check `processASTFuzzerStep` does for errors received without throwing) and stop fuzzing when the server is gone instead of uselessly sprinting through the rest of the corpus. - Register query parameters generated by `QueryFuzzer` (from `getLastQueryParameters`) for client-side substitution, mirroring the server-side fuzzer in `executeASTFuzzerQueries`; previously any fuzzed query containing a substituted `{name:type}` parameter failed with "Substitution ... is not set" before reaching the server. Job fix (`ci/jobs/scripts/fuzzer/run-fuzzer.sh`): - When the AST fuzzer walks the whole corpus and exits 0 with a meaningful part of the FUZZ_TIME_LIMIT budget remaining, restart it (each pass uses a fresh random seed) instead of ending the job after a couple of minutes. This matters for the targeted variant, whose corpus is a handful of test files. The restart is gated on a server liveness probe so a dead server still terminates the job for classification.
This is okay. As it is a unary function, it has a chance to keep LowCardinality in more cases. |
…cess The client-side AST fuzzer loop swallowed every exception thrown during a fuzzing step: the `catch (...)` handler recorded the error, the loop bottom reset it, and fuzzing continued. When the failure mode is persistent - most importantly a dead server, where the reconnection attempt inside `processParsedSingleQuery` throws instantly - the client sprints through the remaining corpus at hundreds of steps per second without contacting the server and exits with code 0, which the job reports as "Fuzzer exited with success". Evidence from `AST fuzzer (amd_debug, targeted)` on PR ClickHouse#109061 (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109061&sha=1419f6b7e95c81c812f945c06333998b92d56ad3&name_0=PR&name_1=AST+fuzzer+%28amd_debug%2C+targeted%29): `fuzzer.log` records 68972 fuzzing steps, of which 52837 produced no outcome (silent exception), while `server.log` shows the server received only 209 queries within a 47-second window before dying. On PR ClickHouse#106250 (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106250&sha=latest&name_0=PR&name_1=AST+fuzzer+%28amd_debug%2C+targeted%29) a 5-file corpus with ~20 SELECT statements (about 20000 fuzzing steps, over an hour of work at the measured debug-build rate of 2-6 steps/s) "completed" in 74 seconds and the job passed. Overall, 13-33% of targeted AST fuzzer runs per month finish in under 8 minutes of their 30-minute budget. Client fixes (`programs/client/FuzzLoop.cpp`): - Print thrown exceptions in the fuzzing-step catch handlers instead of swallowing them silently, so `fuzzer.log` shows what actually happened. - After a thrown exception, check the connection via `tryToReconnect` (the same check `processASTFuzzerStep` does for errors received without throwing) and stop fuzzing when the server is gone instead of uselessly sprinting through the rest of the corpus. - Register query parameters generated by `QueryFuzzer` (from `getLastQueryParameters`) for client-side substitution, mirroring the server-side fuzzer in `executeASTFuzzerQueries`; previously any fuzzed query containing a substituted `{name:type}` parameter failed with "Substitution ... is not set" before reaching the server. Job fix (`ci/jobs/scripts/fuzzer/run-fuzzer.sh`): - When the AST fuzzer walks the whole corpus and exits 0 with a meaningful part of the FUZZ_TIME_LIMIT budget remaining, restart it (each pass uses a fresh random seed) instead of ending the job after a couple of minutes. This matters for the targeted variant, whose corpus is a handful of test files. The restart is gated on a server liveness probe so a dead server still terminates the job for classification.
The previous revision disabled the default `LowCardinality`, sparse and
replicated column implementations for `FunctionSqr` and forwarded a
duplicated argument pair `{arg, arg}` to the inner `multiply`. For a
constant `LowCardinality` argument the overload resolver reports the result
type as `LowCardinality` (a constant argument is not counted as a full
low-cardinality column in `IFunctionOverloadResolver::getReturnType`), so
`multiply` was then executed on two `LowCardinality` columns with a
`LowCardinality` result type. The default implementation supports only a
single `LowCardinality` argument, which raised `Logical error: Default
functions implementation for LowCardinality is supported only with a single
LowCardinality argument.`
This was found by the AST fuzzer and `FunctionsStress`, e.g.
`SELECT sqr(CAST(1964064 AS LowCardinality(UInt64)))`.
CI: ClickHouse#109061
`sqr` is a unary function, so let it use the default `LowCardinality`,
sparse and replicated implementations like every other unary function. Only
a single argument is ever low-cardinality, so the throwing path is never
reached, and `sqr(x)` now preserves `LowCardinality` by running the wrapped
`multiply` on the dictionary. This differs from `multiply(lc, lc)`, which
flattens two low-cardinality columns to a plain result, but that is the
expected behavior for a unary function; the test now checks the actual
behavior and adds a regression case for the constant `LowCardinality` input.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add sqr arithmetic function
Closes: #108759
Adds the
sqrarithmetic function as a convenience wrapper for calculatingx * x. The function delegates to existingmultiplysemantics, so it preserves the same result type behavior for integers, floats, Decimals, constants, and Nullable values.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the
sqrarithmetic function for calculating the square of a number.Version info
26.7.1.809(included in26.7and later)