Gabriel39 opened a new pull request, #71224:
URL: https://github.com/apache/doris/pull/71224

   ### Background
   
   Iceberg V3 spatial columns can appear inside ARRAY, MAP and STRUCT values. 
Doris checks their spatial identity before binding a connector write and can 
assign the destination spatial type to proven NULL leaves. Derived tables and 
CTEs expose these constructed values through slots.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #69032 (introduced the bug)
   PR Type: Bugfix
   
   Problem Summary:
   
   INSERT SELECT rejects containers with a runtime ordinary field and a NULL 
spatial field when a derived table or CTE forwards the container. The direct 
constructor form succeeds. Retag the NULL leaves at their producer and forward 
a separate spatial output, preserving the original outputs and sharing runtime 
inputs with ordinary consumers; the additional code handles CTE 
producer/consumer mappings and tests these boundaries.
   
   ```sql
   INSERT INTO spatial_target(payload)
   SELECT payload FROM (
       SELECT named_struct('k', id, 'shape', CAST(NULL AS INT)) payload FROM 
source_table
   ) q;
   ```
   
   ### Details
   
   - **Change map:** Production +218/-4 lines in two files, tests +397/-2 lines 
in two files, and 28 generated result lines. Most of the diff is test coverage.
   
   | Part | Purpose | Changed lines |
   | --- | --- | --- |
   | Write normalization | Preserve producer inputs and original outputs while 
forwarding spatial outputs through CTE scopes and UNION ALL | 211 |
   | CTE anchoring | Use the final cached producer after sink binding adds 
outputs | 11 |
   
   - **Frequency:** Always when a forwarded constructor has runtime ordinary 
siblings and an implicit NULL leaf requiring a spatial destination type, as in 
the example.
   - **Root cause:** `ConnectorSpatialWriteNormalizer` resolves the inner 
constructor for validation, but its existing in-place retagging only examines 
the outer projection. The forwarded slot therefore retains its INT leaf, and 
whole-container sink coercion rejects INT-to-spatial conversion. An enclosing 
CTE anchor also hides UNION ALL branch normalization; resolving only the 
innermost name loses bound outer lineage when names are shadowed.
   - **Why existing tests missed it:** `ConnectorSpatialWriteNormalizerTest` 
covers direct runtime constructors and constant CTE provenance separately. 
`test_iceberg_spatial_v3` covers direct SELECT/VALUES/MERGE writes, but neither 
layer combined runtime siblings with derived-table or CTE forwarding. Update 
the existing MAP sort-dependency test to verify original slot/type/order 
preservation with the new independent output.
   - **Fix:** Append the typed constructor output in its original scope, reuse 
runtime leaf inputs without duplicating volatile evaluations, and propagate the 
fresh slot through forwarding projections and row-preserving wrappers. Preserve 
all original CTE outputs/mappings anchor the final cached producer after sink 
binding, and retain outer bindings by CTE id.
   - **Other paths and branches:** Both GEOMETRY and GEOGRAPHY, including 
nested ARRAY/MAP/STRUCT values, use the common bound connector-sink path. 
Existing direct and MERGE paths remain covered; joins, DISTINCT and recursive 
unions remain proof barriers. The introducing normalizer is absent from 
branch-3.1, branch-4.0, branch-4.1 and branch-4.2; this fixes unreleased master.
   
   ### Testing
   
   - Locally, the new forwarding test fails on merged master with 
STRUCT<k:INT,shape:INT> instead of the destination GEOMETRY leaf; all 131 tests 
in six related FE classes pass with the fix.
   - Locally, `test_iceberg_spatial_v3` passes generation and normal comparison 
on the current FE package and an ASAN BE: 18 forwarding rows across six 
derived/CTE forms, both spatial types and nested containers; shared volatile 
CTE values stay consistent across UNION ALL branches; invalid values/casts 
still fail. Existing expected results are unchanged.
   - All 16 original planning probes pass, including the eight previously 
rejected forms; the shadowed-name probe also changes from rejection to 
successful planning.
   
   ### Notes for Reviewers
   
   The original producer output must remain available to shared CTE consumers 
and sort/filter dependencies. Reconstructing fields through accessors would 
widen required nested-field nullability; the output added at the producer 
preserves it.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: OpenAI Codex (GPT-6)
   - Generated: Code, tests and this description
   - Human review: not stated
   


-- 
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