Skip to content

Commit 4d9468c

Browse files
authored
[fix](subquery) Resolve correlated qualified columns before dereference (apache#67438)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: In a correlated subquery, a multipart reference can represent either a relation-qualified column (`table_alias.column`) or a nested-field dereference (`column.field`). Nereids previously searched the inner scope completely before checking the outer scope. If an inner table had a physical column with the same name as an outer table alias, the outer reference could therefore be interpreted as a nested field of that inner column. For scalar inner columns this raised a `No such field` analysis error. For complex inner columns it could bind successfully to the wrong expression and produce incorrect results. #### Example ```sql CREATE TABLE outer_events ( id INT, `@event_name` VARCHAR(32) ) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ("replication_num" = "1"); CREATE TABLE inner_events ( id INT, t1 INT ) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ("replication_num" = "1"); INSERT INTO outer_events VALUES (1, 'blocked'), (2, 'kept'); INSERT INTO inner_events VALUES (1, 0); SELECT t1.id, t1.`@event_name` FROM outer_events t1 WHERE NOT EXISTS ( SELECT 1 FROM inner_events inner_alias WHERE t1.`@event_name` = 'blocked' ) ORDER BY t1.id; ``` Before this fix, the outer alias `t1` conflicted with the physical inner column `inner_events.t1`. Nereids treated ``t1.`@event_name``` as a nested-field access on the inner scalar column and failed during analysis: ```text No such field '@event_name' in 't1' ``` After this fix, ``t1.`@event_name``` is correctly bound to the outer relation alias and the query returns: ```text +------+-------------+ | id | @event_name | +------+-------------+ | 2 | kept | +------+-------------+ ``` This change resolves relation-qualified columns in the current and outer scopes before falling back to first-part-as-column dereference. The relation-only phase follows each analyzer's complete local scope order before searching the outer scope, so custom HAVING and QUALIFY scopes preserve normal nearest-relation shadowing. Lambda lexical scope is preserved: in `array_map(x -> x.value, x.items)`, the first `x` inside the lambda resolves to the lambda argument while the second `x` resolves to the enclosing table alias. When an outer qualified reference contains nested fields, such as `outer_alias.payload.k`, the underlying `payload` slot is also recorded as a correlated slot. ### Release note Fix incorrect Nereids column binding when an outer table alias conflicts with an inner column name in a correlated subquery. ### Check List (For Author) - Test: Regression test / Unit Test - `./run-fe-ut.sh --run org.apache.doris.nereids.rules.analysis.TestDereference` - Result: 10 tests passed, 0 failures - Added `query_p0/test_dereference` regression coverage for scalar and complex inner columns, lambda lexical scope, outer nested-field correlation, reused inner/outer aliases in HAVING and QUALIFY, and local qualifier shadowing - `./run-regression-test.sh --run -d query_p0 -s test_dereference` - Result: suite passed against the generated snapshot - Behavior changed: Yes (relation-qualified correlated references now take priority over inner column-field dereference while preserving complete local-scope precedence) - Does this need documentation: No
1 parent cf1a553 commit 4d9468c

8 files changed

Lines changed: 752 additions & 70 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/Scope.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.doris.nereids.util.Utils;
2222

2323
import com.google.common.base.Suppliers;
24+
import com.google.common.collect.ImmutableSetMultimap;
2425
import com.google.common.collect.LinkedListMultimap;
2526
import com.google.common.collect.ListMultimap;
2627
import com.google.common.collect.Sets;
@@ -66,6 +67,7 @@ public class Scope {
6667
private final boolean buildNameToSlot;
6768
private final Supplier<ListMultimap<String, Slot>> nameToSlot;
6869
private final Supplier<ListMultimap<String, Slot>> nameToAsteriskSlot;
70+
private final Supplier<ImmutableSetMultimap<String, List<String>>> relationNameToQualifiers;
6971

7072
public Scope(List<Slot> slots) {
7173
this(Optional.empty(), slots);
@@ -87,6 +89,7 @@ public Scope(Optional<Scope> outerScope, List<Slot> slots, List<Slot> asteriskSl
8789
this.buildNameToSlot = slots.size() > 500;
8890
this.nameToSlot = buildNameToSlot ? Suppliers.memoize(this::buildNameToSlot) : null;
8991
this.nameToAsteriskSlot = buildNameToSlot ? Suppliers.memoize(this::buildNameToAsteriskSlot) : null;
92+
this.relationNameToQualifiers = Suppliers.memoize(this::buildRelationNameToQualifiers);
9093
this.asteriskSlots = Utils.fastToImmutableList(
9194
Objects.requireNonNull(asteriskSlots, "asteriskSlots can not be null"));
9295
}
@@ -107,6 +110,11 @@ public Set<Slot> getCorrelatedSlots() {
107110
return correlatedSlots;
108111
}
109112

113+
/** Find distinct relation qualifiers by relation name, ignoring case. */
114+
public Set<List<String>> findRelationQualifiersIgnoreCase(String relationName) {
115+
return relationNameToQualifiers.get().get(relationName.toUpperCase(Locale.ROOT));
116+
}
117+
110118
/** findSlotIgnoreCase */
111119
public List<Slot> findSlotIgnoreCase(String slotName, boolean all) {
112120
List<Slot> slots = all ? this.slots : this.asteriskSlots;
@@ -140,4 +148,15 @@ private ListMultimap<String, Slot> buildNameToAsteriskSlot() {
140148
}
141149
return map;
142150
}
151+
152+
private ImmutableSetMultimap<String, List<String>> buildRelationNameToQualifiers() {
153+
ImmutableSetMultimap.Builder<String, List<String>> builder = ImmutableSetMultimap.builder();
154+
for (Slot slot : slots) {
155+
if (!slot.getQualifier().isEmpty()) {
156+
List<String> qualifier = slot.getQualifier();
157+
builder.put(qualifier.get(qualifier.size() - 1).toUpperCase(Locale.ROOT), qualifier);
158+
}
159+
}
160+
return builder.build();
161+
}
143162
}

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java‎

Lines changed: 103 additions & 55 deletions
Large diffs are not rendered by default.

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java‎

Lines changed: 189 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
import java.util.ArrayList;
125125
import java.util.List;
126126
import java.util.Optional;
127+
import java.util.Set;
128+
import java.util.function.Supplier;
127129
import java.util.stream.Collectors;
128130
import javax.annotation.Nullable;
129131

@@ -312,14 +314,36 @@ public Expression visitElementAt(ElementAt elementAt, ExpressionRewriteContext c
312314
@Override
313315
public Expression visitUnboundSlot(UnboundSlot unboundSlot, ExpressionRewriteContext context) {
314316
Optional<Scope> outerScope = getScope().getOuterScope();
315-
Optional<List<? extends Expression>> boundedOpt = Optional.of(bindSlotByThisScope(unboundSlot));
316-
boolean foundInThisScope = !boundedOpt.get().isEmpty();
317+
List<? extends Expression> bounded = ImmutableList.of();
318+
boolean foundInThisScope = false;
319+
boolean canBindOuterScope = bindSlotInOuterScope && outerScope.isPresent();
320+
boolean relationQualifierOccupied = false;
321+
322+
// A multipart name can be either a relation-qualified column (t.col) or a nested field
323+
// reference (col.field). In a correlated subquery, try the relation-qualified interpretation
324+
// in both visible scopes first, so an inner column named "t" does not hide an outer alias "t".
325+
if (canBindOuterScope && shouldPrioritizeRelationQualifier()
326+
&& unboundSlot.getNameParts().size() > 1) {
327+
SlotBinding localRelationBinding = bindSlotByRelationQualifierInThisScope(unboundSlot);
328+
bounded = localRelationBinding.getBoundSlots();
329+
foundInThisScope = !bounded.isEmpty();
330+
if (!foundInThisScope) {
331+
relationQualifierOccupied = localRelationBinding.isRelationQualifierOccupied();
332+
}
333+
if (!foundInThisScope && !relationQualifierOccupied) {
334+
bounded = bindSlotsByRelationQualifier(unboundSlot, outerScope.get());
335+
}
336+
}
337+
338+
if (bounded.isEmpty()) {
339+
bounded = bindSlotByThisScope(unboundSlot);
340+
foundInThisScope = !bounded.isEmpty();
341+
}
317342
// Currently only looking for symbols on the previous level.
318-
if (bindSlotInOuterScope && !foundInThisScope && outerScope.isPresent()) {
319-
boundedOpt = Optional.of(bindSlotByScope(unboundSlot, outerScope.get()));
343+
if (canBindOuterScope && bounded.isEmpty() && !relationQualifierOccupied) {
344+
bounded = bindSlotByScope(unboundSlot, outerScope.get());
320345
}
321346
// it is heavy to deduplicate slots in scope. So we deduplicates bounded here
322-
List<? extends Expression> bounded = boundedOpt.get();
323347
if (bounded.size() > 1) {
324348
bounded = bounded.stream().distinct().collect(Collectors.toList());
325349
}
@@ -333,14 +357,15 @@ public Expression visitUnboundSlot(UnboundSlot unboundSlot, ExpressionRewriteCon
333357
return unboundSlot;
334358
case 1:
335359
Expression firstBound = bounded.get(0);
336-
if (!foundInThisScope && firstBound instanceof Slot
337-
&& !outerScope.get().getCorrelatedSlots().contains(firstBound)) {
360+
Set<Slot> inputSlots = firstBound.getInputSlots();
361+
if (!foundInThisScope
362+
&& !outerScope.get().getCorrelatedSlots().containsAll(inputSlots)) {
338363
if (currentPlan instanceof LogicalJoin) {
339364
throw new AnalysisException(
340365
"Unsupported correlated subquery with correlated slot in join conjuncts "
341366
+ currentPlan);
342367
}
343-
outerScope.get().getCorrelatedSlots().add((Slot) firstBound);
368+
outerScope.get().getCorrelatedSlots().addAll(inputSlots);
344369
}
345370
if (firstBound.getDataType() instanceof NestedColumnPrunable
346371
|| firstBound.getDataType().isVariantType()) {
@@ -456,6 +481,11 @@ private Expression analyzeLambdaFunction(Lambda lambda, Expression lambdaFunctio
456481
ExpressionAnalyzer lambdaAnalyzer = new ExpressionAnalyzer(currentPlan, new Scope(Optional.of(getScope()),
457482
boundedSlots), context == null ? null : context.cascadesContext,
458483
true, true) {
484+
@Override
485+
protected boolean shouldPrioritizeRelationQualifier() {
486+
return false;
487+
}
488+
459489
@Override
460490
protected void couldNotFoundColumn(UnboundSlot unboundSlot, String tableName) {
461491
throw new AnalysisException("Unknown lambda slot '"
@@ -466,6 +496,11 @@ protected void couldNotFoundColumn(UnboundSlot unboundSlot, String tableName) {
466496
return lambdaAnalyzer.analyze(lambdaFunction, context);
467497
}
468498

499+
/** Whether relation-qualified columns should be resolved across scopes before nested fields. */
500+
protected boolean shouldPrioritizeRelationQualifier() {
501+
return true;
502+
}
503+
469504
UnboundFunction preProcessUnboundFunction(UnboundFunction unboundFunction, ExpressionRewriteContext context) {
470505
// NOTICE: some trick code here. because for time arithmetic functions,
471506
// the first argument of them is TimeUnit, but is cannot distinguish with UnboundSlot in parser.
@@ -1165,17 +1200,27 @@ protected List<? extends Expression> bindSlotByThisScope(UnboundSlot unboundSlot
11651200
return bindSlotByScope(unboundSlot, getScope());
11661201
}
11671202

1203+
protected SlotBinding bindSlotByRelationQualifierInThisScope(UnboundSlot unboundSlot) {
1204+
return bindSlotByRelationQualifier(unboundSlot, getScope());
1205+
}
1206+
11681207
protected List<Expression> bindExactSlotsByThisScope(UnboundSlot unboundSlot, Scope scope) {
1169-
List<Expression> candidates = bindSlotByScope(unboundSlot, scope);
1208+
return bindExactSlotsByThisScope(unboundSlot, scope, false).getBoundSlots();
1209+
}
1210+
1211+
protected SlotBinding bindExactSlotsByThisScope(
1212+
UnboundSlot unboundSlot, Scope scope, boolean bindRelationQualifierOnly) {
1213+
SlotBinding binding = bindSlotByScope(unboundSlot, scope, bindRelationQualifierOnly);
1214+
List<Expression> candidates = binding.getBoundSlots();
11701215
if (candidates.size() == 1) {
1171-
return candidates;
1216+
return binding;
11721217
}
11731218
List<Expression> extractSlots = Utils.filterImmutableList(candidates, bound ->
11741219
bound instanceof Slot && unboundSlot.getNameParts().size() == ((Slot) bound).getQualifier().size() + 1
11751220
);
11761221
// we should return origin candidates slots if extract slots is empty,
11771222
// and then throw an ambiguous exception
1178-
return !extractSlots.isEmpty() ? extractSlots : candidates;
1223+
return binding.withBoundSlots(!extractSlots.isEmpty() ? extractSlots : candidates);
11791224
}
11801225

11811226
private List<Slot> addSqlIndexInfo(List<Slot> slots, Optional<Pair<Integer, Integer>> indexInSql) {
@@ -1214,12 +1259,128 @@ public List<Expression> bindSlotByScope(UnboundSlot unboundSlot, Scope scope) {
12141259
}
12151260
}
12161261

1262+
protected SlotBinding bindSlotByScope(
1263+
UnboundSlot unboundSlot, Scope scope, boolean bindRelationQualifierOnly) {
1264+
return bindRelationQualifierOnly
1265+
? bindSlotByRelationQualifier(unboundSlot, scope)
1266+
: new SlotBinding(bindSlotByScope(unboundSlot, scope), false);
1267+
}
1268+
1269+
/** Bind a multipart slot as a relation-qualified column, without treating its first part as a column. */
1270+
protected SlotBinding bindSlotByRelationQualifier(UnboundSlot unboundSlot, Scope scope) {
1271+
List<? extends Expression> bounded = bindSlotsByRelationQualifier(unboundSlot, scope);
1272+
return bounded.isEmpty()
1273+
? new SlotBinding(bounded,
1274+
() -> containsRelationQualifier(unboundSlot.getNameParts(), scope))
1275+
: new SlotBinding(bounded, false);
1276+
}
1277+
1278+
private List<? extends Expression> bindSlotsByRelationQualifier(UnboundSlot unboundSlot, Scope scope) {
1279+
List<String> nameParts = unboundSlot.getNameParts();
1280+
Optional<Pair<Integer, Integer>> idxInSql = unboundSlot.getIndexInSqlString();
1281+
List<? extends Expression> bounded;
1282+
switch (nameParts.size()) {
1283+
case 1:
1284+
bounded = ImmutableList.of();
1285+
break;
1286+
case 2:
1287+
bounded = bindExpressionByTableColumn(
1288+
unboundSlot, nameParts, idxInSql, scope, false);
1289+
break;
1290+
case 3:
1291+
bounded = bindExpressionByDbTableColumn(
1292+
unboundSlot, nameParts, idxInSql, scope, false);
1293+
break;
1294+
default:
1295+
bounded = bindExpressionByCatalogDbTableColumn(
1296+
unboundSlot, nameParts, idxInSql, scope, false);
1297+
break;
1298+
}
1299+
return bounded;
1300+
}
1301+
1302+
private boolean containsRelationQualifier(List<String> nameParts, Scope scope) {
1303+
int lastRelationNameIndex = Math.min(2, nameParts.size() - 2);
1304+
for (int relationNameIndex = 0; relationNameIndex <= lastRelationNameIndex; relationNameIndex++) {
1305+
for (List<String> qualifier
1306+
: scope.findRelationQualifiersIgnoreCase(nameParts.get(relationNameIndex))) {
1307+
String catalogName = extractCatalogName(qualifier);
1308+
int lowerCaseTableNames = resolveLowerCaseTableNames(catalogName);
1309+
int lowerCaseDatabaseNames = resolveLowerCaseDatabaseNames(catalogName);
1310+
if (nameParts.size() >= 4 && qualifier.size() >= 3
1311+
&& qualifier.get(qualifier.size() - 3).equalsIgnoreCase(nameParts.get(0))
1312+
&& compareDbNameIgnoreClusterName(qualifier.get(qualifier.size() - 2),
1313+
nameParts.get(1), lowerCaseDatabaseNames)
1314+
&& sameTableName(qualifier.get(qualifier.size() - 1),
1315+
nameParts.get(2), lowerCaseTableNames)) {
1316+
return true;
1317+
}
1318+
if (nameParts.size() >= 3 && qualifier.size() >= 2
1319+
&& compareDbNameIgnoreClusterName(qualifier.get(qualifier.size() - 2),
1320+
nameParts.get(0), lowerCaseDatabaseNames)
1321+
&& sameTableName(qualifier.get(qualifier.size() - 1),
1322+
nameParts.get(1), lowerCaseTableNames)) {
1323+
return true;
1324+
}
1325+
if (sameTableName(qualifier.get(qualifier.size() - 1),
1326+
nameParts.get(0), lowerCaseTableNames)) {
1327+
return true;
1328+
}
1329+
}
1330+
}
1331+
return false;
1332+
}
1333+
1334+
/** Relation-qualified binding candidates and whether that qualifier exists in the searched scope. */
1335+
protected static class SlotBinding {
1336+
private final List<Expression> boundSlots;
1337+
private final Supplier<Boolean> relationQualifierOccupied;
1338+
1339+
protected SlotBinding(List<? extends Expression> boundSlots, boolean relationQualifierOccupied) {
1340+
this(boundSlots, () -> relationQualifierOccupied);
1341+
}
1342+
1343+
private SlotBinding(List<? extends Expression> boundSlots, Supplier<Boolean> relationQualifierOccupied) {
1344+
this.boundSlots = ImmutableList.copyOf(boundSlots);
1345+
this.relationQualifierOccupied = relationQualifierOccupied;
1346+
}
1347+
1348+
protected List<Expression> getBoundSlots() {
1349+
return boundSlots;
1350+
}
1351+
1352+
protected boolean isRelationQualifierOccupied() {
1353+
return relationQualifierOccupied.get();
1354+
}
1355+
1356+
protected SlotBinding firstOrEmpty() {
1357+
return boundSlots.isEmpty()
1358+
? this
1359+
: new SlotBinding(ImmutableList.of(boundSlots.get(0)), relationQualifierOccupied);
1360+
}
1361+
1362+
private SlotBinding withBoundSlots(List<? extends Expression> boundSlots) {
1363+
return new SlotBinding(boundSlots, relationQualifierOccupied);
1364+
}
1365+
1366+
protected SlotBinding withQualifierOccupancyFrom(SlotBinding other) {
1367+
return new SlotBinding(boundSlots,
1368+
() -> relationQualifierOccupied.get() || other.relationQualifierOccupied.get());
1369+
}
1370+
}
1371+
12171372
private List<? extends Expression> bindExpressionByCatalogDbTableColumn(
12181373
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql, Scope scope) {
1374+
return bindExpressionByCatalogDbTableColumn(unboundSlot, nameParts, idxInSql, scope, true);
1375+
}
1376+
1377+
private List<? extends Expression> bindExpressionByCatalogDbTableColumn(
1378+
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql,
1379+
Scope scope, boolean fallbackToColumn) {
12191380
List<Slot> slots = bindSingleSlotByCatalog(
12201381
nameParts.get(0), nameParts.get(1), nameParts.get(2), nameParts.get(3), scope);
12211382
if (slots.isEmpty()) {
1222-
return bindExpressionByDbTableColumn(unboundSlot, nameParts, idxInSql, scope);
1383+
return bindExpressionByDbTableColumn(unboundSlot, nameParts, idxInSql, scope, fallbackToColumn);
12231384
} else if (slots.size() > 1) {
12241385
return addSqlIndexInfo(slots, idxInSql);
12251386
}
@@ -1238,9 +1399,15 @@ private List<? extends Expression> bindExpressionByCatalogDbTableColumn(
12381399

12391400
private List<? extends Expression> bindExpressionByDbTableColumn(
12401401
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql, Scope scope) {
1402+
return bindExpressionByDbTableColumn(unboundSlot, nameParts, idxInSql, scope, true);
1403+
}
1404+
1405+
private List<? extends Expression> bindExpressionByDbTableColumn(
1406+
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql,
1407+
Scope scope, boolean fallbackToColumn) {
12411408
List<Slot> slots = bindSingleSlotByDb(nameParts.get(0), nameParts.get(1), nameParts.get(2), scope);
12421409
if (slots.isEmpty()) {
1243-
return bindExpressionByTableColumn(unboundSlot, nameParts, idxInSql, scope);
1410+
return bindExpressionByTableColumn(unboundSlot, nameParts, idxInSql, scope, fallbackToColumn);
12441411
} else if (slots.size() > 1) {
12451412
return addSqlIndexInfo(slots, idxInSql);
12461413
}
@@ -1259,9 +1426,17 @@ private List<? extends Expression> bindExpressionByDbTableColumn(
12591426

12601427
private List<? extends Expression> bindExpressionByTableColumn(
12611428
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql, Scope scope) {
1429+
return bindExpressionByTableColumn(unboundSlot, nameParts, idxInSql, scope, true);
1430+
}
1431+
1432+
private List<? extends Expression> bindExpressionByTableColumn(
1433+
UnboundSlot unboundSlot, List<String> nameParts, Optional<Pair<Integer, Integer>> idxInSql,
1434+
Scope scope, boolean fallbackToColumn) {
12621435
List<Slot> slots = bindSingleSlotByTable(nameParts.get(0), nameParts.get(1), scope);
12631436
if (slots.isEmpty()) {
1264-
return bindExpressionByColumn(unboundSlot, nameParts, idxInSql, scope);
1437+
return fallbackToColumn
1438+
? bindExpressionByColumn(unboundSlot, nameParts, idxInSql, scope)
1439+
: ImmutableList.of();
12651440
} else if (slots.size() > 1) {
12661441
return addSqlIndexInfo(slots, idxInSql);
12671442
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.nereids.analyzer;
19+
20+
import org.apache.doris.nereids.trees.expressions.ExprId;
21+
import org.apache.doris.nereids.trees.expressions.SlotReference;
22+
import org.apache.doris.nereids.types.IntegerType;
23+
24+
import com.google.common.collect.ImmutableList;
25+
import org.junit.jupiter.api.Assertions;
26+
import org.junit.jupiter.api.Test;
27+
28+
import java.util.List;
29+
30+
class ScopeTest {
31+
32+
@Test
33+
void testFindRelationQualifiersIgnoreCase() {
34+
List<String> qualifier1 = ImmutableList.of("internal", "db", "t1");
35+
List<String> qualifier2 = ImmutableList.of("internal", "db", "t2");
36+
Scope scope = new Scope(ImmutableList.of(
37+
new SlotReference(new ExprId(1), "c1", IntegerType.INSTANCE, true, qualifier1),
38+
new SlotReference(new ExprId(2), "c2", IntegerType.INSTANCE, true, qualifier1),
39+
new SlotReference(new ExprId(3), "c1", IntegerType.INSTANCE, true, qualifier2),
40+
new SlotReference(new ExprId(4), "unqualified", IntegerType.INSTANCE, true, ImmutableList.of())));
41+
42+
Assertions.assertEquals(ImmutableList.of(qualifier1),
43+
ImmutableList.copyOf(scope.findRelationQualifiersIgnoreCase("T1")));
44+
Assertions.assertEquals(ImmutableList.of(qualifier2),
45+
ImmutableList.copyOf(scope.findRelationQualifiersIgnoreCase("t2")));
46+
Assertions.assertTrue(scope.findRelationQualifiersIgnoreCase("unqualified").isEmpty());
47+
}
48+
}

0 commit comments

Comments
 (0)