Skip to content

setting to control type mismatch behavior for variant and dynamic - #99085

Merged
bharatnc merged 11 commits into
masterfrom
ncb/setting-variant-dynamic-mismatch
Apr 20, 2026
Merged

bharatnc merged 11 commits into
masterfrom
ncb/setting-variant-dynamic-mismatch

Conversation

@bharatnc

@bharatnc bharatnc commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Add a setting to control type mismatch behavior for variant and dynamic (throw or return null).

Changelog category (leave one):

  • Improvement

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

Add a setting to control type mismatch behavior for variant and dynamic (throw or return null).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.1068
  • Backported to: 26.3.14.33

@bharatnc
bharatnc requested a review from Avogar March 9, 2026 15:18
@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c9ef26a]

Summary: ⏳

job_name test_name status info comment
Unit tests (msan) ERROR IGNORED
Upgrade check (amd_release) FAIL
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL IGNORED

AI Review

Summary

This PR introduces variant_throw_on_type_mismatch and dynamic_throw_on_type_mismatch to control whether incompatible rows in default Variant/Dynamic function execution throw or yield NULL, with matching docs and stateless tests. The core behavior change and compatibility wiring look correct, but two textual inconsistencies remain and should be fixed before merge to avoid misleading users and maintainers.

Findings

💡 Nits

  • [src/Functions/FunctionDynamicAdaptor.h:38] The comment says false is the default, but the setting default is true. Update the comment to match actual default behavior.
  • [docs/en/sql-reference/data-types/variant.md:557-559] The Error handling note still states type-related errors are converted to NULL, but this is now controlled by variant_throw_on_type_mismatch (default true throws). Please clarify that NULL conversion applies when the setting is false.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ✅
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Fix the incorrect default-value comment in src/Functions/FunctionDynamicAdaptor.h.
    • Update the Variant docs Error handling note to reflect variant_throw_on_type_mismatch behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 9, 2026
@Avogar Avogar self-assigned this Mar 9, 2026
@bharatnc
bharatnc marked this pull request as ready for review March 16, 2026 23:49
Comment thread src/Core/Settings.cpp Resolved

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes looks good to me, but we need to fix build and add new tests for these settings

@bharatnc
bharatnc force-pushed the ncb/setting-variant-dynamic-mismatch branch from 436f2a0 to 53f539d Compare April 16, 2026 13:00
@bharatnc
bharatnc force-pushed the ncb/setting-variant-dynamic-mismatch branch from 53f539d to 335332b Compare April 16, 2026 13:00
Comment thread src/Functions/FunctionVariantAdaptor.h Resolved
Comment thread src/Functions/FunctionDynamicAdaptor.h Resolved
@bharatnc
bharatnc force-pushed the ncb/setting-variant-dynamic-mismatch branch from 8f89f43 to acaa13b Compare April 16, 2026 13:55
Comment thread src/Core/Settings.cpp Resolved
@bharatnc
bharatnc requested a review from Avogar April 16, 2026 16:24
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@bharatnc
bharatnc force-pushed the ncb/setting-variant-dynamic-mismatch branch from 4b2e3bf to a94334c Compare April 17, 2026 11:49

### Type mismatch behavior {#variant-type-mismatch-behavior}

The setting `variant_throw_on_type_mismatch` controls what happens when a function is applied to a `Variant` column and the actual stored type of a row is incompatible with the function:

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.

This new section documents variant_throw_on_type_mismatch=true as default throwing behavior, but the existing note a few lines above still says type-related errors are caught and converted to NULL.

Could you update that note to mention it applies only when variant_throw_on_type_mismatch = false? Otherwise readers will get contradictory behavior descriptions on the same page.

@clickhouse-gh

clickhouse-gh Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 87.16% (95/109) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@bharatnc
bharatnc added this pull request to the merge queue Apr 20, 2026
Merged via the queue into master with commit 9fcf13d Apr 20, 2026
158 of 161 checks passed
@bharatnc
bharatnc deleted the ncb/setting-variant-dynamic-mismatch branch April 20, 2026 12:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 20, 2026
@Avogar

Avogar commented May 19, 2026

Copy link
Copy Markdown
Member

@bharatnc what do you think about backporting it to 26.3 where we added default implementation for Variant for consistency?

@bharatnc

bharatnc commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@bharatnc what do you think about backporting it to 26.3 where we added default implementation for Variant for consistency?

sure, we can backport.

robot-ch-test-poll1 added a commit that referenced this pull request Jun 9, 2026
Cherry pick #99085 to 26.3: setting to control type mismatch behavior for variant and dynamic
robot-clickhouse added a commit that referenced this pull request Jun 9, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 9, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 10, 2026
bharatnc added a commit that referenced this pull request Jun 17, 2026
Backport #99085 to 26.3: setting to control type mismatch behavior for variant and dynamic
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
Dependency of the ClickHouse#100939 backport (e1f3ced0221): its code reads the setting
variant_throw_on_type_mismatch that this change adds, so e1f3ced0221 does not compile
without it (found by the candidate build: FunctionVariantAdaptor.cpp, undeclared
Setting::variant_throw_on_type_mismatch). The 26.3 branch merged this backport on 2026-06-17,
before the ClickHouse#100939 backport. The default (true) keeps the behaviour (SettingsChangesHistory:
true -> true): a function applied to a Variant/Dynamic row of an incompatible type throws;
setting it to false returns NULL instead. Upstream patch unchanged, with its test
04101_variant_dynamic_type_mismatch_settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…f upstream fixes

The stateless selection gets the upstream tests of the 34 backports of the residual audit
and of the two backports they depend on (ClickHouse#99085, ClickHouse#107562), 04627 (runnable with the gate's
loopback Keeper), and 10317/10318 (Parquet Decimal512): 152 tests. 04670 (needs pyarrow) and
00900 (a long load test whose skip list changed) run outside the gate.

known_defects.json: a fixed KD-UP entry per backport (fixed_by = its commit); KD-UP-108790
points at the ClickHouse#115705 backport, which carries its change; KD-UP-107663 records its ClickHouse#112601
dependency. Defects found by the release gate on the candidate 91efe1f244ce and fixed:
KD-D512-PERF-OVERFLOW-CHECKS (e91167f), KD-TEST-BLOCKCHAIN-TYPENAME (f006d0d),
KD-GATE-NO-KEEPER (095b89c). 80 entries, 0 open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants