github-actions[bot] commented on code in PR #67713:
URL: https://github.com/apache/doris/pull/67713#discussion_r3966559319
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -497,6 +502,36 @@ protected void couldNotFoundColumn(UnboundSlot
unboundSlot, String tableName) {
return lambdaAnalyzer.analyze(lambdaFunction, context);
}
+ /**
+ * Build the scope of a lambda body. The lambda arguments shadow the
same-named slots that are visible
+ * to the enclosing expression, and the enclosing scope becomes the outer
scope. Slot binding only looks
+ * one level up, so when this analyzer itself analyzes a lambda body
(nested high-order functions), the
+ * scope of this analyzer only holds the enclosing lambda arguments: merge
them into the new scope and keep
+ * the plan scope as the outer scope, so that the columns captured by the
nested lambda body stay bindable.
+ */
+ private Scope newLambdaScope(List<Slot> lambdaArgumentSlots) {
+ Scope enclosingScope = getScope();
+ if (!isLambdaBodyAnalyzer()) {
+ return new Scope(Optional.of(enclosingScope), lambdaArgumentSlots);
+ }
+ ImmutableList.Builder<Slot> slots =
ImmutableList.builderWithExpectedSize(
+ lambdaArgumentSlots.size() + enclosingScope.getSlots().size());
+ slots.addAll(lambdaArgumentSlots);
+ for (Slot enclosingArgument : enclosingScope.getSlots()) {
+ boolean shadowed = lambdaArgumentSlots.stream()
+ .anyMatch(argument ->
argument.getName().equalsIgnoreCase(enclosingArgument.getName()));
+ if (!shadowed) {
+ slots.add(enclosingArgument);
+ }
+ }
+ return new Scope(enclosingScope.getOuterScope(), slots.build());
Review Comment:
`array_sort` is registered with `ARRAY_COMPARATOR`, so this generic scope
flattening now also makes a nested comparator query capture bindable. For
example, with the PR's table, `array_map(a -> array_sort((x, y) -> if(flag,
if(x < y, -1, if(x > y, 1, 0)), 0), arr2), arr1)` binds `flag` and FE
serializes it as a captured `SlotRef`. But `ArraySortFunction::prepare` runs
`_set_comparator_argument_gap`, which rejects any captured slot reference; the
comparator block contains only `x`/`y` and has `parent_bindings_visible =
false`. This therefore changes the failure from FE analysis to BE fragment
preparation rather than making the nested high-order function executable.
Please either materialize comparator captures through FE/BE, or
exclude/validate `ARRAY_COMPARATOR` during analysis, and add an end-to-end
nested `array_sort` regression for the chosen behavior.
--
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]