setamv opened a new issue #14566:
URL: https://github.com/apache/shardingsphere/issues/14566


   ## 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?
   master (5.0.1-SNAPSHOT)
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   
   ### Actual behavior
   
org.apache.shardingsphere.infra.binder.segment.table.TablesContext#findTableNameFromMetaData()
 can find the correct table name for column names.
   ### Reason analyze (If you can)
   
![微信图片_20220106163452](https://user-images.githubusercontent.com/20662392/148355642-1971b082-24a8-4a8b-a36b-d92d0faf33e5.png)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   I wrote a test case in 
`org.apache.shardingsphere.infra.binder.segment.table.TablesContextTest` as 
follows:
   ```
   @Test
   public void 
assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumnInUpperCase()
 {
        // When the sql is "SELECT * FROM TABLE_1 AS TBL_1 JOIN TABLE_2 AS 
TBL_2 ON COL_IN_TBL1 = TBL_2.COL"
        // The table name in table segment will be the same case in SQL which 
is in uppercase
        SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", 
"TBL_1");
        SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", 
"TBL_2");
        TableMetaData tableMetaData = createTableMetaData("TABLE_1", 
Arrays.asList("COL"));
        ShardingSphereSchema schema = new 
ShardingSphereSchema(Arrays.asList(tableMetaData).stream().collect(Collectors.toMap(TableMetaData::getName,
 v -> v)));
        ColumnProjection columnProjection = createColumnProjection(null, "COL", 
null);
        Map<String, String> actual = new 
TablesContext(Arrays.asList(tableSegment1, 
tableSegment2)).findTableName(Collections.singletonList(columnProjection), 
schema);
        assertFalse(actual.isEmpty());
        assertThat(actual.get("col"), is("TABLE_1"));
   }
   
   private TableMetaData createTableMetaData(String tableName, List<String> 
columnNames) {
        return new TableMetaData(
                        tableName,
                        columnNames.stream().map(colName -> new 
ColumnMetaData(colName, 0, false, false, true)).collect(Collectors.toList()),
                        Collections.EMPTY_LIST);
   }
   ```
   and the test result is :
   ```
   
   java.lang.AssertionError
        at org.junit.Assert.fail(Assert.java:86)
        at org.junit.Assert.assertTrue(Assert.java:41)
        at org.junit.Assert.assertFalse(Assert.java:64)
        at org.junit.Assert.assertFalse(Assert.java:74)
        at 
org.apache.shardingsphere.infra.binder.segment.table.TablesContextTest.assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumnInUpperCase(TablesContextTest.java:109)
        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]


Reply via email to