@@ -161,18 +161,12 @@ public RexNode visitQualifiedName(QualifiedName node, CalcitePlanContext context
161161 if (parts .size () == 1 ) {
162162 // Handle the case of `id = cid`
163163 try {
164- // TODO what if there is join clause in InSubquery in join condition
165- // for subquery in join condition
166- return context .relBuilder .field (parts .get (0 ));
167- } catch (IllegalArgumentException e ) {
168- try {
169- return context .relBuilder .field (2 , 0 , parts .get (0 ));
170- } catch (IllegalArgumentException ee ) {
171- return context .relBuilder .field (2 , 1 , parts .get (0 ));
172- }
164+ return context .relBuilder .field (2 , 0 , parts .getFirst ());
165+ } catch (IllegalArgumentException ee ) {
166+ return context .relBuilder .field (2 , 1 , parts .getFirst ());
173167 }
174- } else if (parts .size ()
175- == 2 ) { // Handle the case of `t1.id = t2.id` or `alias1.id = alias2.id`
168+ } else if (parts .size () == 2 ) {
169+ // Handle the case of `t1.id = t2.id` or `alias1.id = alias2.id`
176170 return context .relBuilder .field (2 , parts .get (0 ), parts .get (1 ));
177171 } else if (parts .size () == 3 ) {
178172 throw new UnsupportedOperationException ("Unsupported qualified name: " + node );
@@ -184,7 +178,7 @@ public RexNode visitQualifiedName(QualifiedName node, CalcitePlanContext context
184178 return context .relBuilder .field (qualifiedName );
185179 } else if (node .getParts ().size () == 2 ) {
186180 List <String > parts = node .getParts ();
187- return context .relBuilder .field (1 , parts .get (0 ), parts .get (1 ));
181+ return context .relBuilder .field (parts .get (0 ), parts .get (1 ));
188182 } else if (currentFields .stream ().noneMatch (f -> f .startsWith (qualifiedName ))) {
189183 return context .relBuilder .field (qualifiedName );
190184 }
@@ -262,9 +256,20 @@ public RexNode visitFunction(Function node, CalcitePlanContext context) {
262256 @ Override
263257 public RexNode visitInSubquery (InSubquery node , CalcitePlanContext context ) {
264258 List <RexNode > nodes = node .getChild ().stream ().map (child -> analyze (child , context )).toList ();
259+ // clear and store the outer state
260+ boolean isResolvingJoinConditionOuter = context .isResolvingJoinCondition ();
261+ if (isResolvingJoinConditionOuter ) {
262+ context .setResolvingJoinCondition (false );
263+ }
265264 UnresolvedPlan subquery = node .getQuery ();
265+
266266 RelNode subqueryRel = subquery .accept (planVisitor , context );
267+ // pop the inner plan
267268 context .relBuilder .build ();
269+ // restore to the previous state
270+ if (isResolvingJoinConditionOuter ) {
271+ context .setResolvingJoinCondition (true );
272+ }
268273 try {
269274 return context .relBuilder .in (subqueryRel , nodes );
270275 // TODO
0 commit comments