@@ -153,9 +153,49 @@ public boolean visit(SQLJoinTableSource x) {
153153 inOuterJoin = false ;
154154 break ;
155155 }
156- boolean result = super .visit (x );
156+
157+ SQLTableSource left = x .getLeft (), right = x .getRight ();
158+
159+ left .accept (this );
160+ right .accept (this );
161+
162+ SQLExpr condition = x .getCondition ();
163+ if (condition != null ) {
164+ condition .accept (this );
165+ }
166+
167+ if (x .getUsing ().size () > 0 &&
168+ left instanceof SQLExprTableSource && right instanceof SQLExprTableSource ) {
169+ SQLExpr leftExpr = ((SQLExprTableSource ) left ).getExpr ();
170+ SQLExpr rightExpr = ((SQLExprTableSource ) right ).getExpr ();
171+
172+ for (SQLExpr expr : x .getUsing ()) {
173+ if (expr instanceof SQLIdentifierExpr ) {
174+ String name = ((SQLIdentifierExpr ) expr ).getName ();
175+ /*
176+ when the shard1 a join shard2 b using(id)
177+ the intermediate condition should be a.id = b.id instead of shard1.id = shard2.id
178+ */
179+ SQLPropertyExpr leftPropExpr = new SQLPropertyExpr (leftExpr , name );
180+ if (left .getAlias () != null ) {
181+ leftPropExpr .setOwner (left .getAlias ());
182+ }
183+ SQLPropertyExpr rightPropExpr = new SQLPropertyExpr (rightExpr , name );
184+ if (right .getAlias () != null ) {
185+ rightPropExpr .setOwner (right .getAlias ());
186+ }
187+
188+ leftPropExpr .setResolvedTableSource (left );
189+ rightPropExpr .setResolvedTableSource (right );
190+
191+ SQLBinaryOpExpr usingCondition = new SQLBinaryOpExpr (leftPropExpr , SQLBinaryOperator .Equality , rightPropExpr );
192+ usingCondition .accept (this );
193+ }
194+ }
195+ }
196+
157197 inOuterJoin = false ;
158- return result ;
198+ return false ;
159199 }
160200
161201 @ Override
@@ -229,6 +269,7 @@ public boolean visit(SQLBetweenExpr x) {
229269 return true ;
230270 }
231271
272+
232273 @ Override
233274 public boolean visit (SQLBinaryOpExpr x ) {
234275 if (isUnaryParentEffect (x )) return true ;
0 commit comments