Skip to content

Enable use_variant_as_common_type by default - #90677

Merged
alexey-milovidov merged 13 commits into
masterfrom
use_variant_as_common_type-by-default
Jan 24, 2026
Merged

alexey-milovidov merged 13 commits into
masterfrom
use_variant_as_common_type-by-default

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 23, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Enable use_variant_as_common_type by default, which lets you use incompatible types inside an Array, in UNION queries, and in branches of if/multiIf/case.

Version info

  • Merged into: 26.1.1.805

@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [495a0f6]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
00625_arrays_in_nested FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 23, 2025
@serxa serxa self-assigned this Nov 24, 2025
alexey-milovidov and others added 11 commits January 19, 2026 18:24
Remove `NO_COMMON_TYPE` error expectations from queries that now succeed
when `use_variant_as_common_type` is enabled by default. Update the
reference file with expected Variant type outputs.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The test expected an exception when using mixed types (string and integer)
in an array literal for `NOT IN`, but now arrays can use Variant as the
common type, so the query succeeds.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@alexey-milovidov
alexey-milovidov merged commit dd479cd into master Jan 24, 2026
128 of 130 checks passed
@alexey-milovidov
alexey-milovidov deleted the use_variant_as_common_type-by-default branch January 24, 2026 00:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 24, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 11, 2026
…types

Since use_variant_as_common_type became the default (ClickHouse#90677), if/multiIf/
coalesce/ifNull/array/map over mixed numeric branches that have no lossless
common type (for example a Decimal and a Float64, or an Int64 and a Float64)
produce a Variant. Value-combining aggregate functions (sum, avg, min, max)
reject a Variant argument, so an expression like sum(if(1, toDecimal64(1, 2),
0.)) fails with ILLEGAL_TYPE_OF_ARGUMENT. This is not a regression: the same
query threw NO_COMMON_TYPE before ClickHouse#90677, only the error text changed.

This adds a new setting allow_lossy_numeric_supertype, disabled by default.
When enabled, getLeastSupertypeOrVariant first tries the lossless common type;
if there is none and every branch is numeric with at least one floating point
branch, it resolves to Float64 (matching binary arithmetic promotion) instead
of building a Variant, so the result can be aggregated. Integer-only sets that
lack a common type (for example Int64 and UInt64) keep producing a Variant
because there is no obvious lossy numeric supertype.

The setting is threaded through if/multiIf/coalesce/ifNull/array/map and the
MultiIfToIf / IfChainToMultiIf analyzer passes. The aggregate functions sum,
avg, min and max now mention the setting in their "illegal type" error when the
rejected argument is an all-numeric Variant, so users get a clear escape hatch.

allow_lossy_numeric_supertype is a behavior opt-in, not an experimental gate,
so it is whitelisted in check_style/experimental_settings_ignore.txt rather
than added to enableAllExperimentalSettings.cpp.

Closes ClickHouse#106707

Co-Authored-By: Claude Opus 4.8 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 11, 2026
…types

Since use_variant_as_common_type became the default (ClickHouse#90677), if/multiIf/
coalesce/ifNull/array/map over mixed numeric branches that have no lossless
common type (for example a Decimal and a Float64, or an Int64 and a Float64)
produce a Variant. Value-combining aggregate functions (sum, avg, min, max)
reject a Variant argument, so an expression like sum(if(1, toDecimal64(1, 2),
0.)) fails with ILLEGAL_TYPE_OF_ARGUMENT. This is not a regression: the same
query threw NO_COMMON_TYPE before ClickHouse#90677, only the error text changed.

This adds a new setting allow_lossy_numeric_supertype, disabled by default.
When enabled, getLeastSupertypeOrVariant first tries the lossless common type;
if there is none and every branch is numeric with at least one floating point
branch, it resolves to Float64 (matching binary arithmetic promotion) instead
of building a Variant, so the result can be aggregated. NULL-only branches (a
bare NULL literal, Nullable(Nothing)) are skipped while nullability is tracked,
so a normal conditional shape such as multiIf(c1, NULL, c2, toDecimal64(1, 2),
0.) resolves to Nullable(Float64) instead of falling through to a Variant.
Integer-only sets that lack a common type (for example Int64 and UInt64) keep
producing a Variant because there is no obvious lossy numeric supertype.

The setting is threaded through if/multiIf/coalesce/ifNull/array/map and the
MultiIfToIf / IfChainToMultiIf analyzer passes. The aggregate functions sum,
avg, min and max now mention the setting in their "illegal type" error when
enabling it would actually replace the rejected Variant with a numeric
supertype (all-numeric alternatives with at least one floating point branch);
the hint reuses the fallback eligibility check, so it is not shown for
integer-only Variants that the setting cannot help.

allow_lossy_numeric_supertype is a behavior opt-in, not an experimental gate,
so it is whitelisted in check_style/experimental_settings_ignore.txt rather
than added to enableAllExperimentalSettings.cpp.

Closes ClickHouse#106707

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

Labels

pr-improvement Pull request with some product improvements 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.

3 participants