luoyuxia commented on code in PR #18920:
URL: https://github.com/apache/flink/pull/18920#discussion_r907306298


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserBaseSemanticAnalyzer.java:
##########
@@ -1862,6 +1867,65 @@ public static RelNode genValues(
                 rows);
     }
 
+    // traverse the given node to find all correlated variables
+    public static Set<CorrelationId> getVariablesSet(RexNode rexNode) {
+        Set<CorrelationId> correlationVariables = new HashSet<>();
+        if (rexNode instanceof RexSubQuery) {
+            RexSubQuery rexSubQuery = (RexSubQuery) rexNode;
+            // we expect correlated variables in Filter only for now.
+            // also check case where operator has o inputs .e.g TableScan
+            if (rexSubQuery.rel.getInputs().isEmpty()) {
+                return correlationVariables;
+            }
+            RelNode input = rexSubQuery.rel.getInput(0);
+            while (input != null
+                    && !(input instanceof LogicalFilter)
+                    && input.getInputs().size() >= 1) {
+                // we don't expect corr vars within UNION for now
+                if (input.getInputs().size() > 1) {
+                    if (input instanceof LogicalJoin) {
+                        correlationVariables.addAll(
+                                findCorrelatedVar(((LogicalJoin) 
input).getCondition()));
+                    }
+                    return correlationVariables;

Review Comment:
   Make sense. To validate the case meet in here like LogicalUnion, I try with 
the following sql:
   `select * from src x where exists (
       select * from src y
       where y.key = x.key
       union all
       select * from src z
       where z.key = x.key
   );`
   
   It will fail with throwing exceptioin: `Invalid table alias or column 
reference 'x': (possible column names are: key, value)`
   
   Seems there exist some problem in parse phase.I add a todo for throwing 
exception in here. Maybe it should be fix in another pr.



-- 
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]

Reply via email to