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

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Related PR: #69388
   
   Partial backport of the independent CTE ordering repair in #69388 to 
branch-4.1. This branch does not contain the forwarded USING-key Alias 
implementation, so this PR leaves USING binding unchanged.
   
   A CTE can expose columns in the wrong order when its SELECT list repeats a 
source column with another column in between:
   
   ```sql
   WITH q(x,y,z) AS (
       SELECT a,b,a FROM (SELECT 1 AS a,10 AS b) t
   )
   SELECT * FROM q;
   ```
   
   The CTE producer has repeated ExprIds. Flattening the reverse 
producer-to-consumer multimap groups equal producer slots, so the outer star 
binds [x,z,y] instead of [x,y,z]. Positional consumers can consequently receive 
values in the wrong columns.
   
   Use the existing insertion-ordered consumer-to-producer map for output 
positions. Preserve that order when rebuilding mappings during nullability 
adjustment and variant subpath pruning. Other branch-native copy, pruning and 
type/expression rewrite paths already iterate ordered consumer entries.
   
   ### Release note
   
   Fix CTE result column order when the same source column appears more than 
once in its output.
   
   ### Check List (For Author)
   
   - Test: Unit Test
     - Reproduced the failure on unchanged branch-4.1 code: expected [x,y,z], 
actual [x,z,y].
     - 31 focused FE tests passed through run-fe-ut.sh: AnalyzeCTETest (25), 
LogicalCTEConsumerTest (3), and three CTE/nested/variant pruning cases from 
PruneNestedColumnTest. The pruning fixture was retried after a random HTTP-port 
collision at startup.
     - The new full-planner test checks the column names and computes the 
actual constant result (1,10,1) in FE. Direct consumer tests cover copies, 
pruning and nullable propagation.
     - FE server build: DISABLE_BUILD_UI=ON ./build.sh --fe -j4; integrated 
Checkstyle and git diff --check.
     - Local macOS validation uses JDK 17, Thrift 0.24.0 and a native ARM64 
grpc-java 1.34.0 generator built from official source. Toolchain/environment 
adjustments are excluded from the PR.
     - No BE data execution or full regression suite was run locally.
   - Behavior changed: Yes, repeated CTE source columns retain their original 
positions.
   - Does this need documentation: No.
   


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