Skip to content

Fix conversionPreservesOrder accepting UInt8 to a wrapped Bool - #131028

Open
lazerg wants to merge 2 commits into
ClickHouse:masterfrom
lazerg:fix/issue-130889-bool-wrapped-conversion-order
Open

lazerg wants to merge 2 commits into
ClickHouse:masterfrom
lazerg:fix/issue-130889-bool-wrapped-conversion-order

Conversation

@lazerg

@lazerg lazerg commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #130889

conversionPreservesOrder returned true as soon as from.equals(to), but DataTypeNumber::equals only compares the type id, so UInt8 and Bool look the same to it. After Nullable or LowCardinality is unwrapped, UInt8 to Nullable(Bool) reaches that check as (UInt8, Bool) and passes, while the real cast maps every non-zero value to true. So a shard-finalized DISTINCT, GROUP BY or LIMIT BY over such a Distributed or Merge table returned duplicate true rows instead of being refused. Now the shortcut does not accept a Bool target unless the source is Bool too, the same way the Enum branch already excludes Bool. It also looks through Nullable, because Nullable(UInt8) equals Nullable(Bool) as well, which LowCardinality(Nullable(Bool)) over a Nullable(UInt8) column reaches. As the issue notes, a plain Bool (or Nullable(Bool) over Nullable(UInt8)) declared this way is refused too now, which errs on the safe side.

The new test lines fail on the current master build (the queries return true four times each). I did not build the patched server locally.

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 duplicate true rows from DISTINCT, GROUP BY or LIMIT BY over a Distributed or Merge table that declares a Nullable(Bool), LowCardinality(Bool) or Array(Nullable(Bool)) column over a UInt8 column (or LowCardinality(Nullable(Bool)) over Nullable(UInt8)). Such queries are now refused with INCOMPATIBLE_COLUMNS.


Workflow [PR]
Sync PR [sync-upstream/pr/131028]

@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [414a62e]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_binary) DROPPED

AI Review

Summary

The PR prevents conversionPreservesOrder from treating UInt8 to Bool as an identity conversion, including after unwrapping Nullable, and adds regression cases for wrapped columns in Distributed tables. No actionable code findings at PR head 414a62ec623b69cc75099eefe768a017fa9e7f89.

Missing context / blind spots
  • ⚠️ Runtime validation remains unavailable: this checkout has no built ClickHouse binary, and the Praktika report shows tests dropped following an unrelated compilation failure in gtest_s3_object_storage_explicit_settings.cpp. A successful run of 05227_distributed_declared_type_conversion_order on the patched binary would close this gap.
Final Verdict

Status: ✅ Approve. No code changes requested; runtime validation remains subject to the CI limitation above.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 15, 2026
@lazerg

lazerg commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

The arm_tidy build failure is in gtest_s3_object_storage_explicit_settings.cpp, which this PR doesn't touch, and other PRs fail the same way. The new_tests_check failure follows from it, since the bugfix validation jobs were dropped.

@clickhouse-gh clickhouse-gh Bot added comp-data-types Type system & core datatypes used across query planning/execution. and removed comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). labels Nov 19, 2026

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-data-types Type system & core datatypes used across query planning/execution. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distributed DISTINCT/GROUP BY duplicates rows when Bool wraps UInt8 shard column

2 participants