zhengshiJ commented on code in PR #11454:
URL: https://github.com/apache/doris/pull/11454#discussion_r961267219
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java:
##########
@@ -146,4 +150,55 @@ public static String toSqlString(String planName,
Object... variables) {
return stringBuilder.append(" )").toString();
}
+
+ /**
+ * See if there are correlated columns in a subquery expression.
+ */
+ public static boolean containCorrelatedSlot(List<Expression>
correlatedSlots, Expression expr) {
+ if (correlatedSlots.isEmpty() || expr == null) {
+ return false;
+ }
+ if (expr instanceof SlotReference) {
+ return correlatedSlots.contains(expr);
+ }
+ for (Expression child : expr.children()) {
+ if (containCorrelatedSlot(correlatedSlots, child)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get the correlated columns that belong to the subquery,
+ * that is, the correlated columns that can be resolved within the
subquery.
+ * eg:
+ * select * from t1 where t1.a = (select sum(t2.b) from t2 where t1.c =
t2.d));
+ * correlatedPredicates : t1.c = t2.d
+ * correlatedSlots : t1.c
+ * return t2.d
+ */
+ public static List<Expression> getCorrelatedSlots(List<Expression>
correlatedPredicates,
+ List<Expression> correlatedSlots) {
+ List<Expression> slots = new ArrayList<>();
+ correlatedPredicates.stream().forEach(predicate -> {
+ BinaryExpression binaryExpression = (BinaryExpression) predicate;
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]