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

   Breakwater-GitHub-Analysis-Slot: slot_69d75b8c6c1a
   
   The source supports treating this as a correctness bug in FE translation, 
with two downstream effects: an unsupported nested capture escapes validation, 
and alias reconstruction changes the comparator expression. Suggested 
ownership: Nereids/expression translation, with BE lambda regression coverage. 
The issue currently has no labels.
   
   I inspected local source snapshots of `master` at 
`2a4191c1dc94e789e1725d6cb345f46c31a17272` and `branch-4.1` at 
`5fc51d21256d598dc89afe5732550b62baeac4a9`. Both contain the missing rename. 
This is source verification; I have not independently executed the SQL or 
tested the proposed patch, and these snapshots do not establish the latest 
branch-tip status.
   
   **Verified mechanism**
   
   - `visitArraySort` copies the first `ColumnRefExpr` and changes only its 
column ID. The copy constructor preserves its name. Consequently, references to 
`y` carry `(name=x, id=1)`, while references to `x` carry `(name=x, id=0)`. The 
lambda declaration itself still retains `x,y`; the corruption is in the 
references. See 
[translator](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java#L615-L619)
 and [copy 
constructor](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/fe/fe-catalog/src/main/java/org/apache/doris/analysis/ColumnRefExpr.java#L36-L40).
   - The BE nested-capture guard accepts a reference whose name belongs to an 
enclosing nested lambda before checking whether it captures a comparator 
argument. Thus the incorrectly named `y` matches the inner `x`. Runtime name 
resolution also selects that inner binding. For the supplied non-null integers, 
this explains why `x < y` becomes an effective self-comparison and the 
comparator returns `1`. This supports the reported wrong result; the exact 
returned order remains a runtime observation from the report. See [capture 
guard](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/be/src/exprs/lambda_function/varray_sort_function.cpp#L374-L397)
 and [reference 
resolution](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/be/src/exprs/vcolumn_ref.h#L122-L139).
   - Alias creation stores the translated expression. Reconstruction renders 
that expression as SQL and reparses it; `ColumnRefExpr` SQL rendering uses the 
name, losing the distinction supplied by IDs. The example therefore becomes 
comparisons of `x` with itself and returns zero for non-null values. See [alias 
creation](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateFunctionCommand.java#L1197-L1200),
 [SQL 
rendering](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/fe/fe-core/src/main/java/org/apache/doris/analysis/ExprToSqlVisitor.java#L214-L217),
 and [alias 
reconstruction](https://github.com/apache/doris/blob/2a4191c1dc94e789e1725d6cb345f46c31a17272/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/AliasUdf.java#L102-L110).
   
   **Recommended next step**
   
   The proposed `column2.setName(arrayItemReference.getName())` addresses the 
verified metadata defect. Keep IDs `0/1` and the existing positional comparator 
frame. Update the misleading “just a placeholder” comment as well. Validate the 
patch on both target branches before selecting backports.
   
   Please include regression coverage for:
   
   1. The reported nested-shadowing query failing with the capture error naming 
`y`; also capture of `x`, and legal nested shadowing without comparator capture.
   2. A flat comparator sorting correctly in a plain query and in a newly 
created alias, including duplicate values and an alias reload/reconstruction 
check.
   3. FE translation preserving distinct reference names and IDs. Existing BE 
capture tests construct expression nodes directly, so they cannot alone catch 
this FE translation defect.
   
   The fix affects newly translated expressions; it does not repair already 
persisted alias bodies. Recreate affected aliases from their original intended 
DDL after upgrading. Until then, use an inline flat comparator, or ordinary 
`array_sort(arr)` for the ascending integer example.
   
   **Remaining evidence needed**
   
   Please provide the exact FE and BE build commits and before/after SQL 
outputs on the patched build, including the alias's rendered definition. No 
profile or broad log bundle is needed to establish this source defect. Also 
clarify the related-issue link: #68977 currently points to a cloud load/storage 
tracking issue, rather than a lambda issue. The supplied reproductions are 
otherwise sufficient to proceed with a focused PR.
   


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