Allow implicit type conversion in Array to QBit cast#91846
Conversation
Remove explicit type casts (toFloat32, toFloat64, toBFloat16) in test queries now that Array to QBit conversion handles implicit element type conversion automatically.
|
Workflow [PR], commit [7884236] Summary: ❌
|
There was a problem hiding this comment.
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
createArrayToQBitWrapperfunction to apply type conversion to array elements before creatingQBitvalues - Updated test files to remove explicit type conversions (like
toFloat32(),toBFloat16()) that are now unnecessary - Changed expected error codes from
TYPE_MISMATCHtoSIZES_OF_ARRAYS_DONT_MATCHfor 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 |
(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
|
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. |
Stateless tests (amd_msan, parallel) Stateless tests (amd_ubsan, parallel)
Performance tests are giving expected errors as mentioned earlier |
|
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 🎁 |
Cherry pick #91846 to 25.10: Allow implicit type conversion in `Array` to `QBit` cast
Cherry pick #91846 to 25.11: Allow implicit type conversion in `Array` to `QBit` cast
Backport #91846 to 25.10: Allow implicit type conversion in `Array` to `QBit` cast
Backport #91846 to 25.11: Allow implicit type conversion in `Array` to `QBit` cast
Previously, casting
ArraytoQBitrequired the array element type to exactly match theQBitelement type. For example:Now array elements are implicitly converted to the target
QBitelement 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:and even
Closes: #89663.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow implicit type conversion when casting
ArraytoQBit. Integer and float arrays can now be inserted directly intoQBitcolumns without explicit type casts.