Skip to content

Fix variant_throw_on_type_mismatch/dynamic_throw_on_type_mismatch=false not catching exceptions during function execution - #105543

Merged
Avogar merged 6 commits into
masterfrom
fix-variant-throw-on-type-mismatch-execute-v2
Jun 8, 2026
Merged

Avogar merged 6 commits into
masterfrom
fix-variant-throw-on-type-mismatch-execute-v2

Conversation

@Avogar

@Avogar Avogar commented May 21, 2026 •

Copy link
Copy Markdown
Member

Closes #103484

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix variant_throw_on_type_mismatch/dynamic_throw_on_type_mismatch=false not catching exceptions during function execution. Closes #103484

Version info

  • Merged into: 26.6.1.510

…ring `execute`

The `try_build` lambda in `FunctionVariantAdaptor` and `FunctionDynamicAdaptor`
only wrapped `build()` in a try-catch for type-related errors. Some functions
(e.g. comparison functions like `equals`) pass `build()` successfully but throw
`NO_COMMON_TYPE` during `execute()` because `executeGeneric` calls
`getLeastSupertype` which rejects incompatible types like `String` and `UInt8`.

Add a `try_execute` helper that wraps `execute()` calls with the same
try-catch pattern, returning NULL for incompatible-type rows when
`throw_on_type_mismatch` is disabled. Apply the fix to all three execution
paths in both adaptors (single variant no NULLs, single variant with NULLs,
and the general multi-variant case).

Closes #103484

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [41b943b]

Summary: ❌

job_name test_name status info comment
Performance Comparison (arm_release, master_head, 6/6) FAIL Performance dashboard
countIf #3::old FAIL query history IGNORED
countIf #3::new FAIL query history IGNORED
logical_functions_medium #0::old FAIL query history IGNORED
logical_functions_medium #0::new FAIL query history IGNORED
logical_functions_medium #1::old FAIL query history IGNORED
logical_functions_medium #1::new FAIL query history IGNORED
logical_functions_medium #2::old FAIL query history IGNORED
logical_functions_medium #2::new FAIL query history IGNORED
logical_functions_medium #3::old FAIL query history IGNORED
logical_functions_medium #3::new FAIL query history IGNORED
8 more test cases not shown

AI Review

Summary
  • This PR fixes execute-time type-mismatch handling for Variant and Dynamic default function adaptors by converting NO_COMMON_TYPE from compatible-at-build functions, especially comparisons, into NULL rows when variant_throw_on_type_mismatch or dynamic_throw_on_type_mismatch is disabled. The change is narrowly scoped, keeps value-dependent execution exceptions propagating, and adds focused regression coverage for the main adaptor paths plus the overbroad-catch regression.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 21, 2026
@alexbakharew alexbakharew self-assigned this May 27, 2026

@alexbakharew alexbakharew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial PR #95811 was backported to 26.1.

@Avogar Do you know why only to 26.1 and not to other supported versions?

This fix should be backported as well

alexbakharew and others added 2 commits June 5, 2026 09:08
The try_execute lambda in both FunctionVariantAdaptor and FunctionDynamicAdaptor
was catching ILLEGAL_TYPE_OF_ARGUMENT, TYPE_MISMATCH, and CANNOT_CONVERT_TYPE in
addition to NO_COMMON_TYPE. This was too broad: functions like geoToS2 throw
ILLEGAL_TYPE_OF_ARGUMENT during execute() for value-dependent reasons (NaN/infinite
coordinates), not because of a type incompatibility. With variant_throw_on_type_mismatch=false,
these legitimate execution failures were silently converted to NULL.

The fix narrows try_execute to only suppress NO_COMMON_TYPE, which is the specific
error getLeastSupertype throws in executeGeneric when the alternative type is
incompatible with the other argument (e.g. comparison functions). All other errors
now propagate correctly even with throw_on_type_mismatch=false.

try_build is unchanged — it still catches the full set of type-related errors, as
build() failures for incompatible types are always legitimate to suppress.

Add regression test (requires s2): 04264_variant_throw_on_type_mismatch_value_error

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 66/73 (90.41%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Avogar
Avogar added this pull request to the merge queue Jun 8, 2026
Merged via the queue into master with commit e160809 Jun 8, 2026
164 of 166 checks passed
@Avogar
Avogar deleted the fix-variant-throw-on-type-mismatch-execute-v2 branch June 8, 2026 16:20
@clickgapai

clickgapai commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Fix variant_throw_on_type_mismatch/dynamic_throw_on_type_mismatch=false not catching exceptions during function execution

ClickGap verified: reproduced it with the script below on 26.5; tested 3 version(s) — 2 affected, 1 clean (see Affects); bisected to a candidate range — a single introducing PR could not be pinned (see Bisect).

Reproduction

SET enable_variant_type=1; SET allow_suspicious_variant_types=1; SET variant_throw_on_type_mismatch=false; SELECT v = 42 FROM (SELECT 'hello'::Variant(UInt64, String) AS v);

Bisect

  • Bisected on master in several steps (confidence: HIGH); a single introducing PR could not be pinned (PR Fix server crash from recursive Avro schema #102853 only modifies Avro format parsing logic, while the bug involves variant type comparison and exception handling in function execution—completely unrelated subsystems. — a coincidental boundary, not the cause).
  • The source-build bisect converged to Fix server crash from recursive Avro schema #102853, but it is not the introducer (see above) — not attributing it.

Affects

  • Tested on master @ commit 84d36b6f9381 (aarch64)
  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4
  • Does NOT reproduce on: master
  • Feature not present (repro inconclusive — the affected code path postdates these releases): 26.3, 25.8
  • Backport needed: 26.5, 26.4

Suggested next step

The bisect boundary above narrows the search in comp-json-datatype — treat the candidate range as the starting point; the single introducing PR is unconfirmed.

Component: comp-json-datatype
Severity: P2

cc fix PR author: @Avogar
cc fix PR reviewer: @alexbakharew


ClickGap · Finding: phase_d_pr105543

Triage metadata

  • Primary component: comp-json-datatype
  • Secondary components: comp-testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

variant_throw_on_type_mismatch=false fails for comparison functions: try_build only wraps build, not execute

5 participants