Doris-Breakwater commented on issue #71153:
URL: https://github.com/apache/doris/issues/71153#issuecomment-7273387508

   Source review confirms a backend type mismatch for the encoded Variant V2 to 
`ARRAY<VARIANT>` cast on `master` (`1e5b268a591`) and `branch-4.1` 
(`7b801cd6c38`). A block can contain rows and still contribute zero array 
elements. For encoded inputs `NULL`, `[]`, and `7`, the collector records three 
outer rows with zero-length ranges. The Variant leaf receives an empty null 
map, so `apply_forced_nulls` returns the bare `ColumnVariantV2`. 
`finalize_collected_node` passes that column to `ColumnArray::create` and wraps 
the outer array. `DataTypeArray::check_column` checks the child against its 
declared nullable type even when the child has zero rows. That explains the 
mismatch in the reported projection stack. [Master collector and 
finalizer](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/exprs/function/cast/variant_v2/cast_variant_to_array.cpp#L57-L116)
 · [4.1 
finalizer](https://github.com/apache/doris/blob/7b801cd6c3802e866c298800b92c4eb2b08f68c5
 /be/src/exprs/function/cast/variant_v2/cast_variant_to_array.cpp#L114-L137) · 
[Empty-map 
handling](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/exprs/function/cast/variant_v2/cast_variant_to_scalar.cpp#L569-L595)
 · [Array type 
check](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/core/data_type/data_type_array.cpp#L52-L67)
   
   The zero-element paths for `STRING`, `JSONB`, and `INT` already produce a 
nullable child on both reviewed revisions. `STRING` delegates the empty input 
to scalar assembly, `INT` uses scalar assembly directly, and the `JSONB` 
converter wraps its result explicitly. Those targets are useful controls for 
the regression test. If any of them fails, please share its exact build SHA and 
error so that path can be traced separately. [String 
conversion](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/exprs/function/cast/variant_v2/cast_variant_to_string.cpp#L222-L233)
 · [Scalar 
assembly](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/exprs/function/cast/variant_v2/cast_variant_to_scalar.cpp#L379-L433)
 · [JSONB 
conversion](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/exprs/function/cast/variant_v2/cast_variant_to_jsonb.cpp#L83-L103)
   
   Please open the PR with the proposed `make_nullable(child)` immediately 
before array construction. It adds an empty null map to a zero-row Variant 
child and preserves an existing nullable child. In the BE test, assert 
`make_nullable(target)->check_column(*result).ok()` for `NULL`, `[]`, and `7`, 
and check that the row results are SQL `NULL`, `[]`, and SQL `NULL`. A batch 
with a nonempty array gives a control, and `[[]]` cast to 
`ARRAY<ARRAY<VARIANT>>` covers a zero-element leaf below a nonempty outer 
array. Once CI verifies the fix, consider a `branch-4.1` backport. [Column 
wrapper](https://github.com/apache/doris/blob/1e5b268a591eb2e97079ceb40fd8db14222d0cac/be/src/core/column/column_nullable.cpp#L710-L723)
   
   This is a source-level diagnosis. For an end-to-end regression test of the 
repeated-cast query, please include the exact failing FE/BE build, minimal 
`CREATE TABLE` and `INSERT` statements, and the `EXPLAIN` output showing the 
intermediate projection.
   
   Breakwater-GitHub-Analysis-Slot: slot_b532731c9dcb
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to