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/05/19 02:17:34 UTC
(shardingsphere) branch master updated: Fixes #31279, make the results of show tables in order (#31284)
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 8adaa700a04 Fixes #31279, make the results of show tables in order (#31284)
8adaa700a04 is described below
commit 8adaa700a04e0e50772253deb1053cee25db5e9e
Author: Raigor <ra...@gmail.com>
AuthorDate: Sun May 19 10:17:26 2024 +0800
Fixes #31279, make the results of show tables in order (#31284)
---
.../mysql/handler/admin/executor/ShowTablesExecutor.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
index 3a0374cd8f4..65ab2189309 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutor.java
@@ -39,6 +39,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQ
import java.sql.Types;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -83,7 +84,8 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
if (!systemDatabase.getSystemSchemas().contains(databaseName) && !ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete()) {
return new RawMemoryQueryResult(queryResultMetaData, Collections.emptyList());
}
- List<MemoryQueryResultDataRow> rows = getAllTableNames(databaseName).stream().map(each -> {
+ Collection<ShardingSphereTable> sortedTables = getTables(databaseName).stream().sorted(Comparator.comparing(ShardingSphereTable::getName)).collect(Collectors.toList());
+ List<MemoryQueryResultDataRow> rows = sortedTables.stream().map(each -> {
List<Object> rowValues = new LinkedList<>();
rowValues.add(each.getName());
if (showTablesStatement.isContainsFull()) {
@@ -94,12 +96,17 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
return new RawMemoryQueryResult(queryResultMetaData, rows);
}
- private Collection<ShardingSphereTable> getAllTableNames(final String databaseName) {
+ private Collection<ShardingSphereTable> getTables(final String databaseName) {
Collection<ShardingSphereTable> result = ProxyContext.getInstance().getContextManager().getDatabase(databaseName).getSchema(databaseName).getTables().values();
+ Optional<Pattern> likePattern = getLikePattern();
+ return likePattern.isPresent() ? result.stream().filter(each -> likePattern.get().matcher(each.getName()).matches()).collect(Collectors.toList()) : result;
+ }
+
+ private Optional<Pattern> getLikePattern() {
if (!showTablesStatement.getFilter().isPresent()) {
- return result;
+ return Optional.empty();
}
Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(optional -> RegexUtils.convertLikePatternToRegex(optional.getPattern()));
- return pattern.isPresent() ? result.stream().filter(each -> Pattern.compile(pattern.get(), Pattern.CASE_INSENSITIVE).matcher(each.getName()).matches()).collect(Collectors.toList()) : result;
+ return pattern.map(optional -> Pattern.compile(RegexUtils.convertLikePatternToRegex(optional), Pattern.CASE_INSENSITIVE));
}
}