github-actions[bot] commented on code in PR #67438:
URL: https://github.com/apache/doris/pull/67438#discussion_r3912124314
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -309,14 +309,30 @@ public Expression visitElementAt(ElementAt elementAt,
ExpressionRewriteContext c
@Override
public Expression visitUnboundSlot(UnboundSlot unboundSlot,
ExpressionRewriteContext context) {
Optional<Scope> outerScope = getScope().getOuterScope();
- Optional<List<? extends Expression>> boundedOpt =
Optional.of(bindSlotByThisScope(unboundSlot));
- boolean foundInThisScope = !boundedOpt.get().isEmpty();
+ List<? extends Expression> bounded = ImmutableList.of();
+ boolean foundInThisScope = false;
+ boolean canBindOuterScope = bindSlotInOuterScope &&
outerScope.isPresent();
+
+ // A multipart name can be either a relation-qualified column (t.col)
or a nested field
+ // reference (col.field). In a correlated subquery, try the
relation-qualified interpretation
+ // in both visible scopes first, so an inner column named "t" does not
hide an outer alias "t".
+ if (canBindOuterScope && unboundSlot.getNameParts().size() > 1) {
+ bounded = bindSlotByRelationQualifier(unboundSlot, getScope());
+ foundInThisScope = !bounded.isEmpty();
+ if (!foundInThisScope) {
+ bounded = bindSlotByRelationQualifier(unboundSlot,
outerScope.get());
+ }
Review Comment:
An outer relation-qualified nested path can return an
`Alias(ElementAt(...))`, but the correlation bookkeeping below only registers
`firstBound` when it is a `Slot` (lines 349-356). With outer alias `t(payload
STRUCT<k:INT>)`, an inner conflicting column `t`, and `WHERE t.payload.k = 1`,
this probe selects the outer Alias yet leaves `Scope.correlatedSlots` empty.
`SubExprAnalyzer` then exports an empty correlation list and `SubqueryToApply`
builds an uncorrelated Apply even though the right plan reads the outer slot
(or rejects it later). Please propagate the underlying outer input slot(s) for
Alias/nested results and add a STRUCT/VARIANT conflict test that asserts the
Apply correlation.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -309,14 +309,30 @@ public Expression visitElementAt(ElementAt elementAt,
ExpressionRewriteContext c
@Override
public Expression visitUnboundSlot(UnboundSlot unboundSlot,
ExpressionRewriteContext context) {
Optional<Scope> outerScope = getScope().getOuterScope();
- Optional<List<? extends Expression>> boundedOpt =
Optional.of(bindSlotByThisScope(unboundSlot));
- boolean foundInThisScope = !boundedOpt.get().isEmpty();
+ List<? extends Expression> bounded = ImmutableList.of();
+ boolean foundInThisScope = false;
+ boolean canBindOuterScope = bindSlotInOuterScope &&
outerScope.isPresent();
+
+ // A multipart name can be either a relation-qualified column (t.col)
or a nested field
+ // reference (col.field). In a correlated subquery, try the
relation-qualified interpretation
+ // in both visible scopes first, so an inner column named "t" does not
hide an outer alias "t".
+ if (canBindOuterScope && unboundSlot.getNameParts().size() > 1) {
Review Comment:
This relation-first branch also runs in lambda analyzers, not only
correlated subqueries. `analyzeLambdaFunction` creates a lexical scope
containing the lambda `ArrayItemSlot` and sets `bindSlotInOuterScope=true`
(lines 469-472). For `SELECT array_map(x -> x.value, arr) FROM t x` where `arr`
is ARRAY<STRUCT<value:INT>> and `x.value` is a scalar column, the local
relation probe misses the lambda slot, then this outer probe binds the parent
`x.value` before `bindSlotByThisScope` can dereference the lambda argument.
Every element returns the outer scalar (and the parent scope is marked
correlated) instead of `ElementAt(x, 'value')`. Please preserve lexical
lambda-slot precedence or disable this pass for lambda analyzers, and add a
colliding-alias lambda regression test.
--
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]