CalvinKirs commented on code in PR #67438:
URL: https://github.com/apache/doris/pull/67438#discussion_r3912982072
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -309,14 +310,31 @@ 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 && shouldPrioritizeRelationQualifier()
+ && unboundSlot.getNameParts().size() > 1) {
+ bounded = bindSlotByRelationQualifier(unboundSlot, getScope());
+ foundInThisScope = !bounded.isEmpty();
+ if (!foundInThisScope) {
+ bounded = bindSlotByRelationQualifier(unboundSlot,
outerScope.get());
Review Comment:
Fixed in 9fdbf32e60c. The relation-only phase now dispatches through
bindSlotByRelationQualifierInThisScope, and every custom binder reuses its
existing complete local-scope order in relation-only mode before the analyzer
probes outerScope. This keeps the nearest inner relation ahead of an outer
alias in HAVING/QUALIFY while retaining the original correlated-reference fix.
I added reused-alias HAVING and QUALIFY unit/regression coverage;
TestDereference now passes 7 tests with 0 failures.
--
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]