Repository navigation
Support CAST from QBit to Array - #108072
Conversation
`CAST` from a `QBit` to an `Array` was not implemented: it failed with `CAST AS Array can only be performed between same-dimensional Array, Map or String types`. Only the forward `Array` -> `QBit` direction existed. This adds the reverse conversion. The original vector is reconstructed from the bit-transposed representation using the existing untranspose kernel (`SerializationQBit::resolveUntransposeBitPlane`), so an `Array` -> `QBit` -> `Array` round trip is lossless for `Float32` and `Float64`, and matches a direct `BFloat16` conversion for `BFloat16`. The reconstructed array has the `QBit`'s element type and is then converted to the requested element type, so casts such as `QBit(Float32, N)` -> `Array(Float64)` work too. The trailing padding elements that exist when the dimension is not a multiple of 8 are dropped. Test 04406. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [21deb12] Summary: ✅
AI ReviewSummaryThis PR adds the missing reverse Final VerdictStatus: ✅ Approve |
The style check forbids `std::vector` in `src/Functions`; use the memory-tracking alternative, as the rest of the file already does. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `Build (arm_tidy)` job failed with two `-warnings-as-errors` diagnostics in the new `QBit` -> `Array` cast code: - `performance-unnecessary-copy-initialization`: `from_nested_type` was copy-constructed from the `const DataTypePtr &` returned by `DataTypeQBit::getElementType`; bind a const reference instead. The lambda still captures it by value, so the type stays alive. - `readability-inconsistent-declaration-parameter-name`: the declaration of `createQBitToArrayWrapper` named the second parameter `to_array_type` while the definition used `to_type`; align the declaration to `to_type`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108072&sha=73810d3854ac37b0aaab46485179d2306532c6b8&name_0=PR&name_1=Build%20%28arm_tidy%29 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…nd trip
The Float64 round-trip line printed the reconstructed values:
SELECT [0.1, 0.2, 0.3, 0.4, 0.5]::QBit(Float64, 5)::Array(Float64);
On `arm_darwin` the `Float64` literal `0.3` parses to a bit pattern one ULP
higher than on x86, so it prints as `0.30000000000000004` and the result
diverged from the reference. The `QBit` -> `Array` reconstruction is purely
bit-wise and therefore bit-exact on every platform; the divergence comes only
from the platform-dependent decimal of the parsed literal, not from the cast.
Assert the round-trip property (equality with the source array) instead of
printing a platform-dependent decimal. This verifies losslessness directly and
is stable across platforms.
CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108072&sha=a7ce9a0c23c1efb766a208f54198f04aa7689b05&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Addresses review feedback: the `QBit` -> `Array` cast wrapper received the source `ColumnNullable` but ignored it, reconstructing every row regardless of the null map. Pass the null map into `convertQBitToArray` and, for NULL rows, emit a default (all-zero) array without running the bit untranspose kernel. This mirrors the `Array` -> `QBit` path, which already inserts default values for NULL rows instead of transposing them. A NULL row's reconstructed value is never observed: casting a `Nullable(QBit)` that contains NULLs to a non-`Nullable` `Array` is rejected with `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN`, and `accurateCastOrNull` to `Array` is rejected because `Array` cannot be inside `Nullable`. The all-zero array therefore matches the previous output for any row that is ultimately observed, while avoiding the dominant per-row cost for wide QBits. Extends test 04406 with a `Nullable(QBit)` source. Co-Authored-By: Claude Opus 4.8 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Everything is perfect, but need to add Int8.
The latest master added `Int8` as a supported `QBit` element type (8 bit planes), with a `case 8` in the forward `Array` -> `QBit` dispatch. Mirror that in the new reverse `QBit` -> `Array` path: dispatch `case 8` to `createQBitToArrayWrapper<Int8>` and select the `uint8_t` word in `convertQBitToArray` (ClickHouse's `UInt8` is `char8_t` and does not satisfy `std::countr_zero`), matching `convertArrayToQBit`. Without this, `CAST(vec AS Array(Int8))` for a valid `QBit(Int8, N)` reached the `default: UNREACHABLE()` branch. Extends test 04406 with `Int8` round trips, including negative and boundary values. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@groeneai, provide a fix for |
|
@alexey-milovidov STID 2508-3e7b is the chronic RefreshTask It is already being fixed by #108441 ("Stop refreshable MV gracefully on Keeper without MULTI_READ on ATTACH/restore"), which you approved on 2026-06-28. I confirmed the instance on this PR is exactly the cause that PR addresses:
#108441 moves the MULTI_READ / CREATE_IF_NOT_EXISTS check up front so it also covers the ATTACH/restore path: the view stops gracefully (stays Disabled, non-resumable) instead of the scheduling thread reaching the throw. This signature stops once it merges. |
…master Master added 04406_geojson_output_validation and 04406_nested_error_message_dimensional, which collide with the test prefix used for the QBit -> Array cast test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Merged the latest The two CI failures on the previous run are unrelated flakes, not caused by this change (a
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108072&sha=4cd05a2cd4852a53c23f10a490ed6a1c8d83877c&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 ( |
|
@alexey-milovidov The Fix already in progress and approved: #107438 (downgrades the benign ENOTCONN shutdown log to TRACE in CIDB (last 7d, exact test, |
Address review: the new reverse `QBit` -> `Array` cast added in this PR was user-visible but undocumented. Add a "Converting QBit to arrays" section to the `QBit` reference describing reconstruction of the original vector, conversion of the reconstructed elements to the requested array element type, the lossless round trip for `Int8`/`Float32`/`Float64` (and the `BFloat16` match), and that trailing padding elements are dropped when the dimension is not a multiple of 8. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Continued via Addressed the AI-Review " I did not touch the structured The earlier "need to add Merged latest CI: the only red was Pushed |
|
Continued via No further changes needed. The branch is up to date with CI (run for
I am not re-pushing (the branch is already at @groeneai, please take a look at the |
|
Continued via No further changes needed. The branch is The latest CI run (head
Ready to merge pending maintainer. @groeneai, the |
|
Picked this up via Verified the core dispatch is correct: Both CI reds are unrelated, known failures (so I re-ran the failed jobs rather than changing anything):
Did not re-merge Re-ran the failed jobs (run |
|
@alexey-milovidov The It is also not an intrinsic timeout. The recorded failure is the connection-pool packet desync: duration 1.76s, and the runner's own diagnosis reran it 55/55 green ("All reruns passed. The failure is not reproducible (likely a transient issue)"). So Already tracked and being fixed, no new issue or fix PR warranted:
The only other 00223 red in 60 days is #104415 (06-09, 0 master failures for this test in 90 days. Genuine 600s+ timeouts for 00223 only appear back in 2022 to 2024 on heavy sanitizer configs (debug/tsan/msan), not on any recent run. Net: the arm_binary red is covered by #93018 / #108854, the azure red is the host-OOM contention class. (The |
|
Continued via State: AI-Review ✅ Approve, zero unresolved review threads, CI: the previously-persistent The PR is ready; it is blocked only on a human approving review (@rienath was requested) and merge. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 62/67 (92.54%) · Uncovered code |
Support CAST from QBit to Array
CASTfrom aQBitto anArraywas not implemented — it failed withCAST AS Array can only be performed between same-dimensional Array, Map or String types. Only the forwardArray→QBitdirection existed.This adds the reverse conversion. The original vector is reconstructed from the bit-transposed representation using the existing untranspose kernel (
SerializationQBit::resolveUntransposeBitPlane), so anArray→QBit→Arrayround trip is lossless forFloat32andFloat64, and matches a directBFloat16conversion forBFloat16.The reconstructed array has the
QBit's element type and is then converted to the requested element type, so casts such asQBit(Float32, N)→Array(Float64)work too. The trailing padding elements that exist when the dimension is not a multiple of 8 are dropped.The change is purely additive in
createArrayWrapper(a new branch for aQBitsource); all otherArray-target casts are unaffected.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support
CASTfrom aQBitto anArray, reconstructing the original vector. This is the inverse of the existingArraytoQBitconversion.Documentation entry for user-facing changes
🤖 Generated with Claude Code