zhengshiJ commented on code in PR #11454:
URL: https://github.com/apache/doris/pull/11454#discussion_r961245073
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/Scope.java:
##########
@@ -18,28 +18,59 @@
package org.apache.doris.nereids.rules.analysis;
import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SubqueryExpr;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
/**
* The slot range required for expression analyze.
+ *
+ * slots: The symbols used at this level are stored in slots.
+ * outerScope: The scope information corresponding to the parent is stored in
outerScope.
+ * ownerSubquery: The subquery corresponding to ownerSubquery.
+ * subqueryToOuterCorrelatedSlots: The slots correlated in the subquery,
+ * only the slots that cannot be resolved at
this level.
+ *
+ * eg:
+ * t1(k1, v1) / t2(k2, v2)
+ * select * from t1 where t1.k1 = (select sum(k2) from t2 where t1.v1 = t2.v2);
+ *
+ * When analyzing subquery:
+ *
+ * slots: k2, v2;
+ * outerScope:
+ * slots: k1, v1;
+ * outerScope: Optional.empty();
+ * ownerSubquery: Optionsl.empty();
+ * subqueryToOuterCorrelatedSlots: empty();
+ * ownerSubquery: subquery((select sum(k2) from t2 where t1.v1 = t2.v2));
+ * subqueryToOuterCorrelatedSlots: (subquery, v1);
*/
public class Scope {
private final Optional<Scope> outerScope;
private final List<Slot> slots;
- public Scope(Optional<Scope> outerScope, List<Slot> slots) {
+ private final Optional<SubqueryExpr> ownerSubquery;
+ private Map<SubqueryExpr, List<Slot>> subqueryToOuterCorrelatedSlots;
Review Comment:
done
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -183,18 +191,29 @@ public Expression visitUnboundAlias(UnboundAlias
unboundAlias, Void context) {
@Override
public Slot visitUnboundSlot(UnboundSlot unboundSlot, Void context) {
- Optional<List<Slot>> boundedOpt = getScope()
- .toScopeLink() // Scope Link from inner scope to outer
scope
- .stream()
- .map(scope -> bindSlot(unboundSlot, scope.getSlots()))
- .filter(slots -> !slots.isEmpty())
- .findFirst();
+ Optional<List<Slot>> boundedOpt =
Optional.of(bindSlot(unboundSlot, getScope().getSlots()));
+ boolean foundInThisScope = !boundedOpt.get().isEmpty();
+ // Currently only looking for symbols on the previous level.
+ if (!foundInThisScope && getScope().getOuterScope().isPresent()) {
+ boundedOpt = Optional.of(bindSlot(unboundSlot,
+ getScope()
+ .getOuterScope()
+ .get()
+ .getSlots()));
+ }
if (!boundedOpt.isPresent()) {
throw new AnalysisException("Cannot resolve " +
unboundSlot.toString());
}
List<Slot> bounded = boundedOpt.get();
switch (bounded.size()) {
case 1:
+ if (!foundInThisScope) {
+ SubqueryExpr subquery =
getScope().getOuterScope().get().getSubquery().get();
+ List<Slot> slots =
getScope().getOuterScope().get().getCorrelatedSlots(subquery) == null
Review Comment:
done
--
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]