setamv opened a new issue #14611: URL: https://github.com/apache/shardingsphere/issues/14611
## Bug Report **For English only**, other languages will not accept. Before report a bug, make sure you have: - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues). - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview). Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will **close it**. Please answer these questions before submitting your issue. Thanks! ### Which version of ShardingSphere did you use? 5.0.1-SNAPSHOT ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-JDBC ### Expected behavior no exception would be thrown while call `ShardingRule#isAllBindingTables()` ### Actual behavior ShardingRule#isAllBindingTables() throws NullPointerException when the SQL is as follows: ``` SELECT LOG.USER_ID, SUB.UID FROM LOGIC_TABLE AS LOG JOIN SUB_LOGIC_TABLE AS SUB ON LOG.USER_ID = UID WHERE LOG.ORDER_ID = 1 ``` Attention: the table names and column names are in upper case in SQL and there is no table name alias in join condition of `UID` ### Reason analyze (If you can)  ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. I write a test case in `org.apache.shardingsphere.sharding.rule.ShardingRuleTest` as follows: ``` @Test public void assertIsAllBindingTableWithJoinQueryWithDatabaseJoinConditionInUpperCaseAndNoOwner() { ColumnSegment leftDatabaseJoin = createColumnSegment("USER_ID", "LOGIC_TABLE"); ColumnSegment rightDatabaseJoin = createColumnSegment("UID", null); BinaryOperationExpression condition = createBinaryOperationExpression(leftDatabaseJoin, rightDatabaseJoin, EQUAL); JoinTableSegment joinTable = mock(JoinTableSegment.class); when(joinTable.getCondition()).thenReturn(condition); MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class); when(selectStatement.getFrom()).thenReturn(joinTable); SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement); when(sqlStatementContext.isContainsJoinQuery()).thenReturn(true); Collection<SimpleTableSegment> tableSegments = Arrays.asList( new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("LOGIC_TABLE"))), new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("SUB_LOGIC_TABLE"))) ); TablesContext tablesContext = new TablesContext(tableSegments, Collections.EMPTY_MAP); when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.getAllColumnNames("LOGIC_TABLE")).thenReturn(Arrays.asList("user_id", "order_id")); when(schema.getAllColumnNames("SUB_LOGIC_TABLE")).thenReturn(Arrays.asList("uid", "order_id")); assertFalse(createMaximumShardingRule().isAllBindingTables(schema, sqlStatementContext, Arrays.asList("LOGIC_TABLE", "SUB_LOGIC_TABLE"))); } ``` and the result is as follows: ``` java.lang.NullPointerException at org.apache.shardingsphere.sharding.rule.ShardingRule.findTableRule(ShardingRule.java:231) at org.apache.shardingsphere.sharding.rule.ShardingRule.getJoinConditionTables(ShardingRule.java:615) at org.apache.shardingsphere.sharding.rule.ShardingRule.isJoinConditionContainsShardingColumns(ShardingRule.java:593) at org.apache.shardingsphere.sharding.rule.ShardingRule.isAllBindingTables(ShardingRule.java:303) at org.apache.shardingsphere.sharding.rule.ShardingRuleTest.assertIsAllBindingTableWithJoinQueryWithDatabaseJoinConditionInUpperCaseAndNoOwner(ShardingRuleTest.java:515) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) ``` ### Example codes for reproduce this issue (such as a github link). -- 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]
