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

   ### Background
   
   Nereids binds higher-order function bodies in a lambda scope and rewrites 
SQL subqueries into relational plans. Lambda parameters exist only while 
evaluating individual collection elements.
   
   ### What problem does this PR solve?
   
   Issue Number: close #70002
   Related PR: None
   PR Type: Bugfix
   
   Problem Summary:
   
   Subqueries inside lambda bodies can fail during planning with a null-pointer 
exception and an empty client error, or a misleading unknown-column error. 
Reject all subqueries in the body before binding and return `Subqueries are not 
supported in lambda expressions`. Subqueries outside the body, including those 
supplying array arguments, remain accepted.
   
   ### Details
   
   - **Frequency:** Deterministic for affected shapes such as `x IN (SELECT 
...)` and `EXISTS (... WHERE v = x)` inside a lambda.
   - **Root cause:** The lambda binder lacked a subquery legality check. 
Apply/Join rewriting can move predicates outside the scope that supplies the 
lambda parameter.
   - **Why existing tests missed it:** Existing function-binding tests cover 
nested captures and comparators, but not subqueries inside lambda bodies.
   - **Fix:** Check the unbound body for `SubqueryExpr` using the expression 
tree's cached type metadata, before binding, constant folding, or name 
resolution.
   - **Other paths and branches:** The shared entry covers array functions, map 
functions, comparators, nested lambdas, scalar subqueries, and IN/EXISTS with 
their negated forms. No release branch is changed.
   - **Behavior change:** Uncorrelated scalar subqueries that previously 
happened to work inside lambda bodies are also rejected. Ordinary IN lists and 
subqueries used as enclosing array arguments remain accepted.
   
   ### Testing
   
   Local validation passed before rebasing onto current master; all three 
changed files are byte-for-byte unchanged after the rebase.
   
   - `BindFunctionTest#testRejectSubqueriesInLambda` fails before the fix 
because the IN subquery is accepted.
   - `run-fe-ut.sh --run 
org.apache.doris.nereids.rules.analysis.BindFunctionTest,org.apache.doris.nereids.rules.analysis.AnalyzeSubQueryTest`:
 21 tests passed. New methods cover 16 rejected SQL shapes and four allowed 
shapes.
   - `mvn checkstyle:check -pl fe-core`: zero violations.
   - `build.sh --fe -j4`: passed; Checkstyle ran separately.
   - `run-regression-test.sh --run -d query_p0/sql_functions/array_functions -s 
test_lambda_subquery_rejected`: passed, covering 16 expected analysis errors 
and three successful EXPLAIN statements. Used the newly built FE and an 
existing local BE in an isolated cluster with the mutually supported 
`be_exec_version=10`.
   - `git diff --check`: passed.
   
   ### Release note
   
   Subqueries inside lambda bodies now return a clear unsupported-syntax error 
instead of planner errors or inconsistent acceptance. This includes 
uncorrelated scalar subqueries. Subqueries used outside the lambda body, such 
as array input arguments, remain supported.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Codex, GPT-6 Astra
   - Generated: Implementation, tests, and PR description.
   - Human review: Pending.
   
   


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