Skip to content

Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source#97413

Merged
alexey-milovidov merged 2 commits intomasterfrom
fix-qbit-nullable-source-crash
Feb 23, 2026
Merged

Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source#97413
alexey-milovidov merged 2 commits intomasterfrom
fix-qbit-nullable-source-crash

Conversation

@alexey-milovidov
Copy link
Member

@alexey-milovidov alexey-milovidov commented Feb 19, 2026

Summary

  • Fix LOGICAL_ERROR exception in convertArrayToQBit when nullable_source wraps a different column type (e.g., ColumnTuple instead of ColumnArray)
  • The bug occurs when casting types like Nullable(Tuple(Array(Variant(...)), String)) to Nullable(Tuple(QBit(BFloat16, N), String)) — the outer nullable_source wraps the Tuple, but convertArrayToQBit uses getNestedColumnPtr expecting an Array
  • Fix: stop propagating nullable_source in createArrayToQBitWrapper, matching the pattern already used by createArrayWrapper

BuzzHouse CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=58b9b010eb7d1210b0c0ec88118ab153a9db0f4d&name_0=MasterCI&name_1=BuzzHouse%20%28arm_asan%29

Test plan

  • Added regression test 03926_qbit_cast_from_nullable_array exercising nullable Tuple with Array-to-QBit conversion
  • Build passes
  • CI passes

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

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

Fix LOGICAL_ERROR exception in Array-to-QBit conversion when nullable_source from an outer Tuple wrapper replaces the converted array column with a mismatched column type. Closes #97389.

🤖 Generated with Claude Code

@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Feb 19, 2026

Workflow [PR], commit [fd75b84]

Summary:

@clickhouse-gh clickhouse-gh bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 19, 2026
@alexey-milovidov alexey-milovidov changed the title Fix exception in Array-to-QBit conversion with nullable source Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source Feb 19, 2026
@@ -0,0 +1,29 @@
-- Regression test: casting Array(Tuple(Array(...), ...)) to Array(Tuple(QBit(...), ...))
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it reproduces the issue.

template <typename FloatType>
static ColumnPtr convertArrayToQBit(
ColumnsWithTypeAndName & arguments, const DataTypePtr &, const ColumnNullable * nullable_source, size_t n, size_t size)
ColumnsWithTypeAndName & arguments, const DataTypePtr &, const ColumnNullable * /* nullable_source */, size_t n, size_t size)
Copy link
Member

Choose a reason for hiding this comment

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

Yes, the fix is on the right path.

The remaining issue is that we need nullable_source to skip rows where we have NULL. For example,

SELECT CAST(
    [NULL::Nullable(Tuple(Array(Float64), String))],
    'Array(Nullable(Tuple(QBit(BFloat16, 3), String)))'
);

In PR, now throws with:

Code: 190. DB::Exception: Array arguments must have size 3 for QBit conversion, got 0: In scope SELECT CAST([CAST(NULL, 'Nullable(Tuple(Array(Float64), String))')], 'Array(Nullable(Tuple(QBit(BFloat16, 3), String)))'). (SIZES_OF_ARRAYS_DONT_MATCH)

But it should return NULL.

We have to use nullable_source to get the null map data and only try to convert array to QBit for non-null rows in convertArrayToQBit.

We can also add the following query for proper validation of the logic:

SELECT
    CAST(v, 'Array(Nullable(Tuple(QBit(BFloat16, 3), String)))') AS converted
FROM VALUES(
    'v Array(Nullable(Tuple(Array(Float64), String)))',
    [([1.0, 2.0, 3.0], 'hello')],
    [NULL]
);

It should return:

[([1,2,3],'hello')]
[NULL]

@nihalzp nihalzp added v26.1-must-backport and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 20, 2026
@nihalzp nihalzp self-assigned this Feb 20, 2026
@CLAassistant
Copy link

CLAassistant commented Feb 22, 2026

CLA assistant check
All committers have signed the CLA.

alexey-milovidov and others added 2 commits February 22, 2026 21:18
…ong column type

The `createArrayToQBitWrapper` was incorrectly propagating the outer
`nullable_source` pointer into `convertArrayToQBit`, which then replaced
the properly converted `ColumnArray` with the nested column from the
original `nullable_source`. When converting through a Tuple wrapper (e.g.,
`Nullable(Tuple(Array(Variant(...)), String))` to
`Nullable(Tuple(QBit(BFloat16, N), String))`), the outer `nullable_source`
wraps the entire Tuple, so `getNestedColumnPtr` returns a `ColumnTuple`
instead of a `ColumnArray`, causing a `LOGICAL_ERROR` exception.

Fix: stop propagating `nullable_source` in `createArrayToQBitWrapper`,
matching the pattern already used by `createArrayWrapper` (line 4749).

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=58b9b010eb7d1210b0c0ec88118ab153a9db0f4d&name_0=MasterCI&name_1=BuzzHouse%20%28arm_asan%29

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When converting `Nullable(Tuple(Array(Float64), ...))` to
`Nullable(Tuple(QBit(BFloat16, N), ...))`, the Nullable stripping
produces default (empty) arrays for NULL rows. These empty arrays
don't match the expected QBit dimension, causing a
`SIZES_OF_ARRAYS_DONT_MATCH` exception.

Fix: pass `nullable_source` through to `convertArrayToQBit` and use
its null map to skip both the size validation and bit transposition
for NULL rows. The result for those rows is masked by NULL anyway.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexey-milovidov alexey-milovidov force-pushed the fix-qbit-nullable-source-crash branch 2 times, most recently from abe9fa3 to fd75b84 Compare February 22, 2026 22:43
@alexey-milovidov alexey-milovidov added this pull request to the merge queue Feb 23, 2026
Merged via the queue into master with commit 018db24 Feb 23, 2026
148 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-qbit-nullable-source-crash branch February 23, 2026 04:09
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 23, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Feb 23, 2026
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
Cherry pick #97413 to 25.11: Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
…n Array-to-QBit conversion with nullable source
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
Cherry pick #97413 to 25.12: Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
…n Array-to-QBit conversion with nullable source
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
Cherry pick #97413 to 26.1: Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source
robot-clickhouse added a commit that referenced this pull request Feb 23, 2026
… Array-to-QBit conversion with nullable source
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 23, 2026
clickhouse-gh bot added a commit that referenced this pull request Feb 23, 2026
Backport #97413 to 26.1: Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source
Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Feb 24, 2026
…-source-crash

Related to Nullable Tuples: Fix exception in Array-to-QBit conversion with nullable source
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-critical-bugfix 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.1-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: Unexpected column type A for Array source when converting to QBit (STID: 4185-55b7)

6 participants