This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new efffef2  fix issue[14611] and add test case: 
ShardingRule#isAllBindingTables() throws NullPointerException when table names 
and column names are in upper case in SQL (#14615)
efffef2 is described below

commit efffef2ccfcefec54bc214cbd603957c8b97d18c
Author: setamv <[email protected]>
AuthorDate: Fri Jan 7 21:14:32 2022 +0800

    fix issue[14611] and add test case: ShardingRule#isAllBindingTables() 
throws NullPointerException when table names and column names are in upper case 
in SQL (#14615)
    
    * fix issue[14566]: TablesContext#findTableNameFromMetaData() can not find 
the correct table name for column names when column names are in upper case.
    
    * fix issue[14566]: TablesContext#findTableNameFromMetaData() can not find 
the correct table name for column names when column names are in upper case.
    
    * keep indents consistent with the previous one.
    
    * fix issue[14611] and add test case: ShardingRule#isAllBindingTables() 
throws NullPointerException when table names and column names are in upper case 
in SQL
    
    * remove useless testcase.
    
    Co-authored-by: luowei <[email protected]>
---
 .../sharding/rule/ShardingRuleTest.java            | 27 ++++++++++++++++++++++
 .../infra/binder/segment/table/TablesContext.java  |  2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 5d18209..763d63b 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.sharding.rule;
 
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
+import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
@@ -40,6 +41,8 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOp
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
 import org.junit.Test;
@@ -484,6 +487,30 @@ public final class ShardingRuleTest {
     }
     
     @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")));
+    }
+    
+    @Test
     public void 
assertIsAllBindingTableWithJoinQueryWithDatabaseTableJoinCondition() {
         ColumnSegment leftDatabaseJoin = createColumnSegment("user_id", 
"logic_Table");
         ColumnSegment rightDatabaseJoin = createColumnSegment("user_id", 
"sub_Logic_Table");
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
index 1388e6d..927451f 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
@@ -120,7 +120,7 @@ public final class TablesContext {
             }
             return result;
         }
-        Map<String, String> result = new HashMap<>(columns.size(), 1);
+        Map<String, String> result = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         result.putAll(findTableNameFromSQL(getOwnerColumnNames(columns)));
         Collection<String> columnNames = new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
         for (ColumnProjection each : columns) {

Reply via email to