github-actions[bot] commented on code in PR #63040:
URL: https://github.com/apache/doris/pull/63040#discussion_r3258124413
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -306,14 +306,38 @@ 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();
+ AnalysisException thisScopeBindException = null;
+ List<? extends Expression> bounded;
+ try {
+ bounded = bindSlotByThisScope(unboundSlot);
+ } catch (AnalysisException e) {
+ if (bindSlotInOuterScope && outerScope.isPresent() &&
unboundSlot.getNameParts().size() > 1) {
+ bounded = ImmutableList.of();
+ thisScopeBindException = e;
+ } else {
+ throw e;
+ }
+ }
+ boolean foundInThisScope = !bounded.isEmpty();
// Currently only looking for symbols on the previous level.
- if (bindSlotInOuterScope && !foundInThisScope &&
outerScope.isPresent()) {
- boundedOpt = Optional.of(bindSlotByScope(unboundSlot,
outerScope.get()));
+ if (bindSlotInOuterScope && outerScope.isPresent()) {
+ if (!foundInThisScope) {
+ bounded = bindSlotByScope(unboundSlot, outerScope.get());
+ } else if (unboundSlot.getNameParts().size() > 1
+ && !hasExactQualifierMatch(unboundSlot, bounded)) {
+ // Current-scope nested-field fallback should not shadow a
correlated table alias,
+ // e.g. inner column `s` must not block outer reference
`s.grp`.
+ List<Expression> boundedInOuterScope =
bindExactSlotsByThisScope(unboundSlot, outerScope.get());
+ if (hasExactQualifierMatch(unboundSlot, boundedInOuterScope)) {
+ bounded = boundedInOuterScope;
Review Comment:
This still lets a current-scope nested-field fallback shadow an exact outer
table alias when the outer reference itself has nested fields. For example, if
the outer query has alias `s` with a struct/variant/map column `v`, and the
subquery has a local column named `s`, then `s.v.x` first binds in the current
scope as local column `s` with nested fields `v.x`. The outer lookup does find
alias `s` column `v`, but `bindNestedFields` returns an `Alias`, so
`hasExactQualifierMatch()` returns false and the code keeps the wrong
current-scope binding. The fix should recognize exact qualifier prefixes before
nested-field expansion, or otherwise treat the `Alias` produced from an exact
outer `s.v` binding as an exact match; please add coverage for a nested outer
reference such as `s.v.x` as well.
--
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]