You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/01/07 03:54:57 UTC
[shardingsphere] branch master updated: fix issue[14566]: TablesContext#findTableNameFromMetaData() can not find the correct table name for column names when column names are in upper case. #14575 (#14587)
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 d996d0a fix issue[14566]: TablesContext#findTableNameFromMetaData() can not find the correct table name for column names when column names are in upper case. #14575 (#14587)
d996d0a is described below
commit d996d0a33ba99bdd6cdecbfbb3b7726c87df3705
Author: setamv <se...@126.com>
AuthorDate: Fri Jan 7 11:54:10 2022 +0800
fix issue[14566]: TablesContext#findTableNameFromMetaData() can not find the correct table name for column names when column names are in upper case. #14575 (#14587)
* 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.
Co-authored-by: luowei <lu...@yuanian.com>
---
.../infra/binder/segment/table/TablesContext.java | 4 ++--
.../infra/binder/segment/table/TablesContextTest.java | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
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 2c2656d..1388e6d 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
@@ -34,7 +34,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
+import java.util.TreeSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -122,7 +122,7 @@ public final class TablesContext {
}
Map<String, String> result = new HashMap<>(columns.size(), 1);
result.putAll(findTableNameFromSQL(getOwnerColumnNames(columns)));
- Collection<String> columnNames = new LinkedHashSet<>();
+ Collection<String> columnNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
for (ColumnProjection each : columns) {
if (null == each.getOwner()) {
columnNames.add(each.getName());
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
index b652682..fd8f004 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.infra.binder.segment.table;
import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -30,6 +32,7 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
+import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
@@ -94,6 +97,20 @@ public final class TablesContextTest {
assertThat(actual.get("col"), is("table_1"));
}
+ @Test
+ public void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumnInUpperCase() {
+ SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", "TBL_1");
+ SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2");
+ TableMetaData tableMetaData = new TableMetaData("TABLE_1",
+ Arrays.asList(new ColumnMetaData("COL", 0, false, false, true)),
+ Collections.EMPTY_LIST);
+ 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 SimpleTableSegment createTableSegment(final String tableName, final String alias) {
SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(tableName)));
AliasSegment aliasSegment = new AliasSegment(0, 0, new IdentifierValue(alias));