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 2021/10/22 15:46:58 UTC
[shardingsphere] branch master updated: Fixed: no data when using
alias in schemata table. (#13226)
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 407ff14 Fixed: no data when using alias in schemata table. (#13226)
407ff14 is described below
commit 407ff143a502414510a73fe93554accd6feb7631
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Fri Oct 22 10:46:02 2021 -0500
Fixed: no data when using alias in schemata table. (#13226)
* Fixed: no data when using alias in schemata table.
* Fixed: no data when using alias in schemata table.
---
.../AbstractSelectInformationExecutor.java | 30 ++++++++++++----------
.../SelectInformationSchemataExecutor.java | 9 ++++---
.../information/SelectInformationExecutorTest.java | 1 +
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
index f47162c..43b7ee0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
@@ -68,14 +68,16 @@ public abstract class AbstractSelectInformationExecutor implements DatabaseAdmin
for (String schemaName : schemaNames) {
getSourceData(schemaName, resultSet -> {
while (resultSet.next()) {
- Map<String, Object> row = new HashMap<>();
+ Map<String, Object> rowMap = new HashMap<>();
+ Map<String, String> aliasMap = new HashMap<>();
ResultSetMetaData metaData = resultSet.getMetaData();
for (int i = 1; i < metaData.getColumnCount() + 1; i++) {
- row.put(resultSet.getMetaData().getColumnLabel(i), resultSet.getString(i));
+ aliasMap.put(metaData.getColumnName(i), metaData.getColumnLabel(i));
+ rowMap.put(metaData.getColumnLabel(i), resultSet.getString(i));
}
- rowPostProcessing(schemaName, row);
- if (!row.isEmpty()) {
- getRows().addFirst(row);
+ rowPostProcessing(schemaName, rowMap, aliasMap);
+ if (!rowMap.isEmpty()) {
+ getRows().addFirst(rowMap);
}
}
return null;
@@ -103,11 +105,12 @@ public abstract class AbstractSelectInformationExecutor implements DatabaseAdmin
/**
* Get the source object of the row data.
- *
- * @param schemaName schema name
- * @param rows rows
+ *
+ * @param schemaName schema name
+ * @param rowMap row
+ * @param aliasMap alias
*/
- protected abstract void rowPostProcessing(String schemaName, Map<String, Object> rows);
+ protected abstract void rowPostProcessing(String schemaName, Map<String, Object> rowMap, Map<String, String> aliasMap);
private MergedResult createMergedResult() {
List<MemoryQueryResultDataRow> resultDataRows = rows.stream()
@@ -174,12 +177,13 @@ public abstract class AbstractSelectInformationExecutor implements DatabaseAdmin
/**
* Custom processing.
- *
- * @param schemaName schema name
- * @param rows row data
+ *
+ * @param schemaName schema name
+ * @param rowMap row
+ * @param aliasMap alias
*/
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rows) {
+ protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
index b1c16a3..06f84cc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
@@ -73,14 +73,15 @@ public final class SelectInformationSchemataExecutor extends DefaultSelectInform
}
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rows) {
+ protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
Set<String> catalogs = resource.getDataSources().keySet().stream().map(each -> resource.getDataSourcesMetaData().getDataSourceMetaData(each).getCatalog()).collect(Collectors.toSet());
- String rowValue = null == rows.get(SCHEMA_NAME) ? rows.getOrDefault(SCHEMA_NAME.toLowerCase(), "").toString() : rows.getOrDefault(SCHEMA_NAME, "").toString();
+ String alias = aliasMap.getOrDefault(SCHEMA_NAME, "");
+ String rowValue = rowMap.getOrDefault(alias, "").toString();
if (catalogs.contains(rowValue)) {
- rows.replace(SCHEMA_NAME, schemaName);
+ rowMap.replace(alias, schemaName);
} else {
- rows.clear();
+ rowMap.clear();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
index 80612a0..0bf17b4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
@@ -81,6 +81,7 @@ public final class SelectInformationExecutorTest {
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
List<String> keys = new ArrayList<>(mockMap.keySet());
for (int i = 0; i < keys.size(); i++) {
+ when(metaData.getColumnName(i + 1)).thenReturn(keys.get(i));
when(metaData.getColumnLabel(i + 1)).thenReturn(keys.get(i));
when(RESULT_SET.getString(i + 1)).thenReturn(mockMap.get(keys.get(i)));
}