You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/08/15 03:11:22 UTC

(shardingsphere) branch master updated: Fix incorrect results for querying information_schema.SCHEMATA (#32511)

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

zhaojinchao 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 3f7bf029c8b Fix incorrect results for querying information_schema.SCHEMATA (#32511)
3f7bf029c8b is described below

commit 3f7bf029c8b5b461e36de681fe59d9a336399f7c
Author: Raigor <ra...@gmail.com>
AuthorDate: Thu Aug 15 11:11:16 2024 +0800

    Fix incorrect results for querying information_schema.SCHEMATA (#32511)
    
    * Fix incorrect results for querying information_schema.SCHEMATA
    
    * Fix checkstyle
---
 .../SelectInformationSchemataExecutor.java         | 28 +++++++++++++++++-----
 1 file changed, 22 insertions(+), 6 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 cda1e778d9d..09a1043251c 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
@@ -105,20 +105,36 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
         Map<String, String> defaultRowData = getTheDefaultRowData();
         SCHEMA_WITHOUT_DATA_SOURCE.forEach(each -> {
             Map<String, Object> row = new LinkedHashMap<>(defaultRowData);
-            row.replace(SCHEMA_NAME, each);
+            row.replace(schemaNameAlias, each);
             getRows().add(row);
         });
         SCHEMA_WITHOUT_DATA_SOURCE.clear();
     }
     
     private Map<String, String> getTheDefaultRowData() {
-        Map<String, String> result;
         Collection<ProjectionSegment> projections = sqlStatement.getProjections().getProjections();
         if (projections.stream().anyMatch(ShorthandProjectionSegment.class::isInstance)) {
-            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(each -> each.getValue().toUpperCase()).collect(Collectors.toMap(each -> each, each -> ""));
+            return Stream.of(CATALOG_NAME, SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME, SQL_PATH, DEFAULT_ENCRYPTION)
+                    .collect(Collectors.toMap(each -> each, each -> "", (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+        }
+        return getDefaultRowsFromProjections(projections);
+    }
+    
+    private Map<String, String> getDefaultRowsFromProjections(final Collection<ProjectionSegment> projections) {
+        Map<String, String> result = new LinkedHashMap<>(projections.size(), 1F);
+        for (ProjectionSegment each : projections) {
+            if (!each.getClass().isAssignableFrom(ColumnProjectionSegment.class)) {
+                continue;
+            }
+            if (((ColumnProjectionSegment) each).getAlias().isPresent()) {
+                String alias = ((ColumnProjectionSegment) each).getAlias().get().getValue();
+                if (((ColumnProjectionSegment) each).getColumn().getIdentifier().getValue().equalsIgnoreCase(SCHEMA_NAME)) {
+                    schemaNameAlias = alias;
+                }
+                result.put(alias, "");
+                continue;
+            }
+            result.put(((ColumnProjectionSegment) each).getColumn().getIdentifier().getValue().toUpperCase(), "");
         }
         return result;
     }