Repository navigation
Conversation
…_common_type The literal gets the type `Array(Variant(...))`, but when the planner named the constant it computed the type of its value again with `FieldToDataType`, which throws for elements without a common type. `ConstantNode::toASTImpl` already treats that case as needing a `_CAST`; move that decision into `ConstantNode::valueRequiresCastCall` and use it in the planner too, so the name also matches the AST sent to remote servers.
…xception Instead of catching the exception of `FieldToDataType` for elements without a common type, use the `LeastSupertypeOnError::Variant` policy: such elements get a `Variant`, other values the same type as before. An array always needs the cast (`requiresCastCall`), so mixed-type arrays still get it.
|
Workflow [PR], commit [50f915b] Summary: ✅
AI ReviewSummaryThe PR fixes Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units82 translation units recompiled, 675 s compile time in total, 82 of them have a recent master baseline. |
With
use_variant_as_common_type = 1, an array whose elements have no common type is anArray(Variant(...)). This works with thearrayfunction, but the same array written as a literal failed:That is the example from the documentation of the setting (
docs/guides/clickhouse/working-with-arrays.mdx), which fails on the current master build (26.11.1.515).QueryTreeBuildergives the literal theArray(Variant(...))type, butcalculateActionNodeNameWithCastIfNeededin the planner computes the type of the constant's value again withFieldToDataType(to decide whether the name needs a_CAST), and that throws for elements without a common type.ConstantNode::toASTImplmakes the same decision and already treats "can't determine the type of the value" as "needs a cast". This PR moves that decision intoConstantNode::valueRequiresCastCalland uses it in both places, so the planner no longer throws and the action name keeps matching the AST that is sent to remote servers.05451_variant_common_type_array_literalhas the two examples from the documentation and the same literal throughremote. The reference is what the current master build returns for the same arrays built with thearrayfunction (checked on a local server, also throughremote). I could not build ClickHouse locally, so CI is the first run of the fix itself.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
NO_COMMON_TYPEfor an array literal with elements of different types (for example[1, 'a']) whenuse_variant_as_common_typeis enabled; it is now anArray(Variant(...)), as the same array built with thearrayfunction.Workflow [PR]
Sync PR [sync-upstream/pr/127452]