You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/04/25 01:27:27 UTC
[shardingsphere] branch master updated: Fix npe in mysql query system with lowercase table column names (#25310)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 f39949294ce Fix npe in mysql query system with lowercase table column names (#25310)
f39949294ce is described below
commit f39949294ce851e0b197d38681f0bd103a73ae9a
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Tue Apr 25 09:27:08 2023 +0800
Fix npe in mysql query system with lowercase table column names (#25310)
* Fixed #25309
* for checkstyle
---
.../information/SelectInformationSchemataExecutor.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
index 134c764ae59..cea058ebcd7 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
@@ -26,14 +26,14 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnPr
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -74,7 +74,8 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
private void removeDuplicatedRow() {
if (queryDatabase) {
- Collection<Map<String, Object>> reservedRow = getRows().stream().collect(Collectors.groupingBy(each -> each.get(schemaNameAlias), Collectors.toCollection(LinkedList::new)))
+ Collection<Map<String, Object>> reservedRow = getRows().stream()
+ .collect(Collectors.groupingBy(each -> Optional.ofNullable(each.get(schemaNameAlias)), Collectors.toCollection(LinkedList::new)))
.values().stream().map(LinkedList::getFirst).collect(Collectors.toList());
reservedRow.forEach(each -> getRows().removeIf(row -> !getRows().contains(each)));
}
@@ -111,7 +112,7 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
}
Map<String, String> defaultRowData = getTheDefaultRowData();
SCHEMA_WITHOUT_DATA_SOURCE.forEach(each -> {
- Map<String, Object> row = new HashMap<>(defaultRowData);
+ Map<String, Object> row = new LinkedHashMap<>(defaultRowData);
row.replace(SCHEMA_NAME, each);
getRows().add(row);
});
@@ -124,7 +125,8 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
if (projections.stream().anyMatch(each -> each instanceof ShorthandProjectionSegment)) {
result = Stream.of(CATALOG_NAME, SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME, SQL_PATH, DEFAULT_ENCRYPTION).collect(Collectors.toMap(each -> each, each -> ""));
} else {
- result = projections.stream().map(each -> ((ColumnProjectionSegment) each).getColumn().getIdentifier()).map(IdentifierValue::getValue).collect(Collectors.toMap(each -> each, each -> ""));
+ result = projections.stream().map(each -> ((ColumnProjectionSegment) each).getColumn().getIdentifier())
+ .map(each -> each.getValue().toUpperCase()).collect(Collectors.toMap(each -> each, each -> ""));
}
return result;
}