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

   ### What problem does this PR solve?
   
   Problem Summary:
   
   When a table-generating function contains a scalar subquery, 
`NormalizeGenerate` inserts a `LogicalProject` to materialize the subquery 
result. That project exposed only the new scalar-subquery aliases and discarded 
every output from the original child. Consequently, a projection above the 
`LATERAL VIEW` could no longer resolve base-table columns. A generating 
expression that referenced both a base-table column and the scalar subquery 
also lost its input slot.
   
   For example, both of these valid forms failed analysis:
   
   ```sql
   SELECT b.id, e
   FROM base_table b
   LATERAL VIEW explode_numbers((SELECT MAX(n) FROM base_table)) t AS e;
   
   SELECT b.id, e
   FROM base_table b
   LATERAL VIEW explode_numbers(b.n + (SELECT MAX(n) FROM base_table)) t AS e;
   ```
   
   ### What is changed and how does it work?
   
   The materialization project now retains the original child outputs, in their 
existing order, before appending aliases for scalar-subquery results. This 
preserves the child slots and their expression IDs for both the generator and 
projections above it, while later projection pruning can still remove unused 
internal slots.
   
   Focused unit tests cover both dependencies: a base-table column consumed 
above the generate node, and a base-table column consumed inside the generating 
expression. A result regression covers the same two query shapes end to end.
   
   ### Release note
   
   Fix analysis failures for `LATERAL VIEW` generating functions that combine 
scalar subqueries with base-table columns.
   
   ### Check List (For Author)
   
   - Test:
     - Unit Test: `NormalizeGenerateTest` (2 tests)
     - Regression Test: `nereids_p0/test_generate_subquery_output`
     - Full FE build and Checkstyle
   - Behavior changed: Yes. Valid generating functions retain all required 
child slots during scalar-subquery normalization.
   - 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