Repository navigation
Conversation
…mon type
`addConvertingToCommonHeaderActionsIfNeeded` skipped a UNION / INTERSECT / EXCEPT branch whose header
passed `blocksHaveEqualStructure`, and `makeConvertingActions` adds no CAST between `equals` types.
`IDataType::equals` ignores a `Decimal` precision and a `DateTime` / `DateTime64` time zone (also one
captured from `session_timezone` by a bare `DateTime`), so such a branch kept its own type while the
analyzer and the union header announced the common one:
- `Decimal(35, 7)` + `UInt32` branches: analyzer `Decimal(38, 7)`, the first branch emits
`Decimal(35, 7)`. The Variant adaptor rebuilds `plus(Int64, Decimal(35, 7))` from the runtime type,
gets `Decimal(35, 7)`, which is not an alternative of the declared
`Variant(Decimal(38, 7), Float64)`: LOGICAL_ERROR (STID 1927-5bc8, AST fuzzer), `Code: 49` on release
builds.
- `DateTime('UTC')` + `DateTime('Asia/Tokyo')`: `toHour` returns 0 and 9 for the same instant.
- `Decimal(5, 2)` + `UInt8`: the client receives `Decimal(5, 2)` instead of `Decimal(9, 2)`.
Each branch column that is `equals` to the common type but not the same type object now gets a target
type from a paired walk (`replaceNestedTypesInPair`) over the branch and common types: a `Decimal` leaf
adopts the common precision, a `DateTime` / `DateTime64` leaf the common zone unless name and captured
zone already match, and any other difference refuses the walk, keeping the branch's type for the whole
column (custom names such as `Bool`, aggregate states, `Dynamic` parameters). A top-level `Variant` is
kept, since a CAST to a `Variant` matches alternatives by name. The converter receives the per-branch
target header, and an explicit CAST by type object is added for every adopted column, because
`makeConvertingActions` casts neither `equals` types nor a same-name zone difference.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unsorted-`Variant` refusal in `getBranchTargetType` also refused `Geometry`, a custom-named `Variant` with a fixed discriminator order, so `Tuple(Geometry, Decimal(35, 7))` UNION ALL `Tuple(Geometry, UInt32)` kept `Decimal(35, 7)` while the analyzer announced `Decimal(38, 7)`. The paired walk only ever produces the common type's names in the common type's order, so the refusal had no case of its own: remove it. Tests: a `Tuple(Geometry, Decimal)` case and a `DateTime64` time-zone case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds, head 28fbc9c): 2 findings fixed, 1 noted
Round 2 on the fixed head: no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261106-015000 |
|
cc @novikd @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [de239cb] Summary: ✅
AI ReviewSummaryPR #129666 normalizes Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
…anch
`replaceNestedTypesInPair` treats `JSON` as a leaf, but `DataTypeObject::equals`
compares the typed paths with `equals`, so a branch of type
`JSON(p Decimal(5, 2))` matched a common `JSON(p Decimal(9, 2))` and kept its own
type: the result header said `Decimal(5, 2)`, `JSONAllPathsWithTypes` reported
`Decimal(5, 2)` for that branch's rows, and `toString` of a
`JSON(t DateTime('Asia/Tokyo'))` branch rendered the instant in Tokyo time under
a `JSON(t DateTime('UTC'))` column.
The leaf callback now walks the typed paths of an `equals` JSON pair with the
same rules (paths line up by position because an `equals` pair has the same
paths) and rebuilds the branch type through `cloneWithChildren`, which keeps the
other JSON parameters. The `KeyCondition` caller of `replaceNestedTypesInPair`
is unchanged.
Found by the AI review on ClickHouse#129666.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118399&sha=4c7f1dc0fc711071ed57fe2fa869fef475d00838&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
Related: #129642
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
UNION,INTERSECTandEXCEPTreturning a branch's ownDecimalprecision orDateTimetime zone instead of the common type. This gave wrong results of time-zone-dependent functions such astoHour, a wrong result column type, and aCannot convert nested result of functionexception when aVariantresult was computed over such a union.Description
On v26.10.2.103-stable,
SELECT toHour(x) FROM (SELECT materialize(toDateTime(1767225600, 'UTC')) AS x UNION ALL SELECT materialize(toDateTime(1767225600, 'Asia/Tokyo')))returns0and9for the same instant, anda + bover(Int64, Decimal(35, 7))UNION ALL(Float64, UInt32)fails withCode: 49 ... Cannot convert nested result of function plus(a LOGICAL_ERROR that aborted the AST fuzzer server, report above). Same on 26.8 and 26.3.IDataType::equalsignores aDecimalprecision and aDateTime/DateTime64time zone, andaddConvertingToCommonHeaderActionsIfNeededskipped a branch whose header wasequalsto the common one (makeConvertingActionsadds no CAST betweenequalstypes either). Such a branch kept its own type while the analyzer and the union header announced the common one.Now each branch column that is
equalsto the common type but not identical to it gets a target type built withreplaceNestedTypesInPair: aDecimalleaf takes the common precision, aDateTime/DateTime64leaf the common zone (including a zone a bareDateTimecaptured fromsession_timezone), also inside containers and in the typed paths ofJSON, and an explicit CAST to it is added. A leaf that would need a value conversion rather than a relabel (BooloverUInt8, a differently named aggregate state) and a top-levelVariantkeep today's behaviour.The same LOGICAL_ERROR through a
Mergetable is fixed by #129642.Validation: new test
05556_set_operation_branch_type_equal_by_equals: every case fails or aborts on master and passes with the fix, 50/50 with randomized settings. 969 stateless tests matching union, intersect, except, variant, decimal, datetime or timezone give identical results with and without the fix.Workflow [PR]
Sync PR [sync-upstream/pr/129666]