Skip to content

Allow implicit type conversion in Array to QBit cast#91846

Merged
rienath merged 9 commits intomasterfrom
qbit-usability
Dec 16, 2025
Merged

Allow implicit type conversion in Array to QBit cast#91846
rienath merged 9 commits intomasterfrom
qbit-usability

Conversation

@rienath
Copy link
Copy Markdown
Member

@rienath rienath commented Dec 10, 2025

Previously, casting Array to QBit required the array element type to exactly match the QBit element type. For example:

CREATE TABLE test (qbit QBit(Float32, 3)) ENGINE = Memory;
INSERT INTO test SELECT [1, 2, 3];  -- Failed with TYPE_MISMATCH

Now array elements are implicitly converted to the target QBit element type using the standard type conversion infrastructure, consistent with how other type conversions work in ClickHouse. Here is an example of a few more queries that now work:

SELECT [1, 2, 3]::QBit(Float64, 3);                       -- Array(UInt8) → QBit(Float64, 3)
SELECT CAST([0.1, 1.1] AS QBit(BFloat16, 2));             -- Array(Float64) → QBit(BFloat16, 2)

and even

INSERT INTO test SELECT arrayMap(i -> i + number, range(3)) AS qbit FROM numbers(3);

Closes: #89663.

Changelog category (leave one):

  • Improvement

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

Allow implicit type conversion when casting Array to QBit. Integer and float arrays can now be inserted directly into QBit columns without explicit type casts.

Remove explicit type casts (toFloat32, toFloat64, toBFloat16) in test queries now that Array to QBit conversion handles implicit element type conversion automatically.
@rienath rienath requested a review from Copilot December 10, 2025 09:51
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Dec 10, 2025

Workflow [PR], commit [7884236]

Summary:

job_name test_name status info comment
Stateless tests (amd_msan, parallel) failure
02801_backup_native_copy FAIL cidb, issue ISSUE EXISTS
Stateless tests (amd_ubsan, parallel) failure
02346_text_index_parallel_replicas FAIL cidb, issue ISSUE EXISTS
AST fuzzer (amd_tsan) failure
Logical error: Unexpected return type from A. Expected B. Got C. Action: FAIL cidb, issue ISSUE EXISTS
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting in SelectWithUnionQuery: the query: FAIL cidb IGNORED
Performance Comparison (amd_release, master_head, 5/6) failure
Check Results failure IGNORED
Performance Comparison (amd_release, master_head, 6/6) failure
Check Results failure IGNORED
Unit tests (tsan) error issue ISSUE EXISTS

@clickhouse-gh clickhouse-gh bot added the pr-improvement Pull request with some product improvements label Dec 10, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables implicit type conversion when casting Array to QBit types in ClickHouse. Previously, array element types had to exactly match the target QBit element type, causing TYPE_MISMATCH errors. Now the standard type conversion infrastructure automatically converts array elements to the target type (e.g., Array(UInt8)QBit(Float64, 3)), making QBit columns easier to populate.

Key Changes:

  • Modified the createArrayToQBitWrapper function to apply type conversion to array elements before creating QBit values
  • Updated test files to remove explicit type conversions (like toFloat32(), toBFloat16()) that are now unnecessary
  • Changed expected error codes from TYPE_MISMATCH to SIZES_OF_ARRAYS_DONT_MATCH for dimension mismatches

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Functions/FunctionsConversion.h Implements implicit type conversion in Array→QBit cast by converting nested array elements before creating QBit
tests/queries/0_stateless/03375_l2_distance_transposed_partial_reads_pass.sql Removes explicit toBFloat16() conversions in test queries
tests/queries/0_stateless/03370_l2_distance_transposed_negative.sql.j2 Removes explicit type conversions from reference vectors in negative test cases
tests/queries/0_stateless/03369_l2_distance_transposed_variadic.sql Removes toFloat32() wrapper and adds clarifying comment about reference vector type requirements
tests/queries/0_stateless/03367_l2_distance_transposed_2.sql.j2 Removes explicit type conversions and updates error expectation
tests/queries/0_stateless/03367_l2_distance_transposed_2.reference.j2 Adds expected output line for newly working test case
tests/queries/0_stateless/03367_l2_distance_transposed_1.sql.j2 Removes explicit type conversions from reference vectors
tests/queries/0_stateless/03366_qbit_array_map_populate.sql Removes explicit type conversions in arrayMap expressions
tests/queries/0_stateless/03365_qbit_casts_as_from_array.sql Removes explicit type conversions in cast operations
tests/queries/0_stateless/03364_qbit_negative.sql Updates error expectation and removes type conversion
tests/queries/0_stateless/03364_qbit_negative.reference Adds expected output for newly working INSERT
tests/queries/0_stateless/03363_qbit_create_insert_select.sql Updates expected error codes from TYPE_MISMATCH to SIZES_OF_ARRAYS_DONT_MATCH

@rienath rienath requested a review from Copilot December 10, 2025 11:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

@pamarcos pamarcos requested a review from Copilot December 12, 2025 12:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

@pamarcos pamarcos self-assigned this Dec 12, 2025
@pamarcos pamarcos self-requested a review December 12, 2025 12:09
(1) Remove explicit copying of from/to_nested_type before lambda to avoid 'NOLINT' as we copy in lamba capture anyway, (2) move 'prepareUnpackDictionaries(..)' and creation of to_array_type outside lambda (larger capture, but computation)
We no longer need toBFloat16/toFloat32/toFloat64 functions for QBit to operate
@pamarcos
Copy link
Copy Markdown
Member

@rienath please merge master so that the CI runs the tests. After #92154 was merged, we should be good 👍

Copy link
Copy Markdown
Member Author

@rienath rienath left a comment

Choose a reason for hiding this comment

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

@pamarcos thanks for the review! I wasn't replying until I see that the CI is green to save your time :)

@rienath
Copy link
Copy Markdown
Member Author

rienath commented Dec 15, 2025

The only related failures are the performance tests. They fail because the script tries to run the new version of the test on master, which does not support type conversion, producing the following stack trace

Traceback (most recent call last):
  File "/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/./tests/performance/scripts/perf.py", line 329, in <module>
    t.join()
  File "/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/./tests/performance/scripts/perf.py", line 45, in join
    raise self.run_exception[1]
  File "/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/./tests/performance/scripts/perf.py", line 38, in run
    super().run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/./tests/performance/scripts/perf.py", line 317, in do_create
    connection.execute(q)
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/client.py", line 382, in execute
    rv = self.process_ordinary_query(
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/client.py", line 580, in process_ordinary_query
    return self.receive_result(with_column_types=with_column_types,
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/client.py", line 213, in receive_result
    return result.get_result()
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/result.py", line 50, in get_result
    for packet in self.packet_generator:
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/client.py", line 229, in packet_generator
    packet = self.receive_packet()
  File "/usr/local/lib/python3.10/dist-packages/clickhouse_driver/client.py", line 246, in receive_packet
    raise packet.exception
clickhouse_driver.errors.ServerException: Code: 53.
DB::Exception: Cannot convert from Array(Int64) to QBit(Float64, 100): while converting source column vec to destination column vec. 

@rienath rienath requested a review from pamarcos December 16, 2025 09:36
@rienath
Copy link
Copy Markdown
Member Author

rienath commented Dec 16, 2025

@rienath
Copy link
Copy Markdown
Member Author

rienath commented Dec 16, 2025

We usually don't backport improvements, but this one makes user experience much nicer and Christmas / New Year is soon. Let's make it a gift 🎁

@rienath rienath added this pull request to the merge queue Dec 16, 2025
@rienath rienath removed this pull request from the merge queue due to a manual request Dec 16, 2025
@rienath rienath added this pull request to the merge queue Dec 16, 2025
Merged via the queue into master with commit bc3e79d Dec 16, 2025
122 of 130 checks passed
@rienath rienath deleted the qbit-usability branch December 16, 2025 20:45
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Dec 16, 2025
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
Cherry pick #91846 to 25.10: Allow implicit type conversion in `Array` to `QBit` cast
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
Cherry pick #91846 to 25.11: Allow implicit type conversion in `Array` to `QBit` cast
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Dec 16, 2025
clickhouse-gh bot added a commit that referenced this pull request Dec 16, 2025
Backport #91846 to 25.10: Allow implicit type conversion in `Array` to `QBit` cast
clickhouse-gh bot added a commit that referenced this pull request Dec 16, 2025
Backport #91846 to 25.11: Allow implicit type conversion in `Array` to `QBit` cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎅 🎁 gift🎄 To make people wonder 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 v25.10-must-backport v25.11-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QBit doesn't accept array literals of compatible types in INSERT ... SELECT

5 participants