CalvinKirs commented on code in PR #67438:
URL: https://github.com/apache/doris/pull/67438#discussion_r3915100542
##########
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 = bindSlotByRelationQualifierInThisScope(unboundSlot);
+ foundInThisScope = !bounded.isEmpty();
+ if (!foundInThisScope) {
+ bounded = bindSlotByRelationQualifier(unboundSlot,
outerScope.get());
Review Comment:
Fixed in c649dac66a7. Relation-only lookup now carries whether the qualifier
is occupied in the current query block. A local same-named relation alias with
a missing requested column blocks outer-scope lookup, while the complete local
binder still supports same-scope nested-field fallback. Added unit and
regression coverage for a local-column hit, local struct-field fallback, and a
local scalar-field error.
##########
regression-test/suites/query_p0/test_dereference.groovy:
##########
@@ -66,4 +66,116 @@ suite("test_dereference") {
sql "select s.a from test_dereference2"
exception "No such struct field 'a' in 's'"
}
-}
\ No newline at end of file
+
+ multi_sql """
+ drop table if exists test_correlated_dereference_outer;
+ drop table if exists test_correlated_dereference_inner_scalar;
+ drop table if exists test_correlated_dereference_inner_struct;
+ create table test_correlated_dereference_outer(
+ id int,
+ value int,
+ `@event_name` varchar(32),
+ payload struct<k:int>,
+ items array<struct<value:int>>
+ )
+ distributed by hash(id)
+ properties('replication_num'='1');
+
+ create table test_correlated_dereference_inner_scalar(
+ id int,
+ t1 int
+ )
+ distributed by hash(id)
+ properties('replication_num'='1');
+
+ create table test_correlated_dereference_inner_struct(
+ id int,
+ outer_alias struct<value:int>
+ )
+ distributed by hash(id)
+ properties('replication_num'='1');
+
+ insert into test_correlated_dereference_outer values
+ (1, 10, 'blocked', struct(1), array(struct(1), struct(2))),
+ (2, 20, 'kept', struct(2), array(struct(3)));
+ insert into test_correlated_dereference_inner_scalar values (1, 0);
+ insert into test_correlated_dereference_inner_struct values (1,
struct(10));
+ """
+
+ test {
+ sql """
+ select t1.id, t1.`@event_name`
+ from test_correlated_dereference_outer t1
+ where not exists (
+ select 1 from test_correlated_dereference_inner_scalar
inner_alias
+ where t1.`@event_name` = 'blocked'
+ )
+ order by t1.id
+ """
Review Comment:
Fixed in c649dac66a7. Converted all six deterministic success cases to named
order_qt cases, generated the snapshot with the regression runner, and verified
the suite against that snapshot. The three new qualifier-shadowing cases follow
the same convention where applicable.
--
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]