cjj2010 commented on code in PR #4926:
URL: https://github.com/apache/calcite/pull/4926#discussion_r3270889831


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -3135,7 +3135,11 @@ private void registerQuery(
           forceNullable);
       operands = call.getOperandList();
       for (int i = 0; i < operands.size(); i++) {
-        registerOperandSubQueries(parentScope, call, i);
+        // Use lambdaScope for the expression body (operand 1) so that
+        // nested lambdas can resolve outer lambda parameters via the
+        // scope chain, rather than treating them as table column names.
+        registerOperandSubQueries(
+            i == 1 ? lambdaScope : parentScope, call, i);

Review Comment:
   > Why do we need two lines? Do we actually need registerOperandSubQueries 
for the parameters, is it even possible for a parameter to be a `SubQuery`?
   > 
   > I think this could be simplified from:
   > 
   > ```
   > for (int i = 0; i < operands.size(); i++) { 
   >   registerOperandSubQueries(
   >             i == 1 ? lambdaScope : parentScope, call, i);
   > ```
   > 
   > to just:
   > 
   > ```
   > // To make it easier to understand code
   > int expressionOperand = 1
   > registerOperandSubQueries(lambdaScope, call, expressionOperand)
   > ```
   > 
   > ?
   
   like this:
         // Register the parameter list under the parent scope
         // (parameters are visible to the lambda body, not the other way 
around).
         registerOperandSubQueries(parentScope, call, 0);
         // Register the expression body under the lambda scope so that
         // nested lambdas can resolve outer lambda parameters via the
         // scope chain, rather than treating them as table column names.
         registerOperandSubQueries(lambdaScope, call, 1);



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

Reply via email to