This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 b39eeeddb86 Add RegexUtils (#30058)
b39eeeddb86 is described below
commit b39eeeddb86ebb2ed56905f9199b04875c0e797d
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 7 22:52:53 2024 +0800
Add RegexUtils (#30058)
---
.../infra/util/regex/RegexUtils.java | 57 ++++++++++++++++++
.../infra/util/regex/RegexUtilsTest.java | 68 ++++++++++++++++++++++
.../handler/query/ShowSingleTableExecutor.java | 4 +-
.../sql/parser/sql/common/util/SQLUtils.java | 30 +---------
.../sql/parser/sql/common/util/SQLUtilsTest.java | 42 -------------
.../ral/queryable/ShowDistVariablesExecutor.java | 4 +-
.../distsql/rql/ShowLogicalTableExecutor.java | 4 +-
.../admin/executor/ShowDatabasesExecutor.java | 4 +-
.../handler/admin/executor/ShowTablesExecutor.java | 4 +-
9 files changed, 136 insertions(+), 81 deletions(-)
diff --git
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/regex/RegexUtils.java
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/regex/RegexUtils.java
new file mode 100644
index 00000000000..4634d852099
--- /dev/null
+++
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/regex/RegexUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.util.regex;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.regex.Pattern;
+
+/**
+ * Regex utils.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RegexUtils {
+
+ private static final Pattern SINGLE_CHARACTER_PATTERN =
Pattern.compile("([^\\\\])_|^_");
+
+ private static final Pattern SINGLE_CHARACTER_ESCAPE_PATTERN =
Pattern.compile("\\\\_");
+
+ private static final Pattern ANY_CHARACTER_PATTERN =
Pattern.compile("([^\\\\])%|^%");
+
+ private static final Pattern ANY_CHARACTER_ESCAPE_PATTERN =
Pattern.compile("\\\\%");
+
+ /**
+ * Convert like pattern to regex.
+ *
+ * @param pattern like pattern
+ * @return regex
+ */
+ public static String convertLikePatternToRegex(final String pattern) {
+ String result = pattern;
+ if (pattern.contains("_")) {
+ result =
SINGLE_CHARACTER_PATTERN.matcher(result).replaceAll("$1.");
+ result =
SINGLE_CHARACTER_ESCAPE_PATTERN.matcher(result).replaceAll("_");
+ }
+ if (pattern.contains("%")) {
+ result = ANY_CHARACTER_PATTERN.matcher(result).replaceAll("$1.*");
+ result =
ANY_CHARACTER_ESCAPE_PATTERN.matcher(result).replaceAll("%");
+ }
+ return result;
+ }
+}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/regex/RegexUtilsTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/regex/RegexUtilsTest.java
new file mode 100644
index 00000000000..d437838749d
--- /dev/null
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/regex/RegexUtilsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.util.regex;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class RegexUtilsTest {
+
+ @Test
+ void assertConvertLikePatternToRegexWhenEndWithPattern() {
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_"),
is("sharding."));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%"),
is("sharding.*"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%_"),
is("sharding.*."));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\_"),
is("sharding_"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\%"),
is("sharding%"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\%\\_"),
is("sharding%_"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_\\_"),
is("sharding._"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%\\%"),
is("sharding.*%"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_\\%"),
is("sharding.%"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\_%"),
is("sharding_.*"));
+ }
+
+ @Test
+ void assertConvertLikePatternToRegexWhenStartWithPattern() {
+ assertThat(RegexUtils.convertLikePatternToRegex("_sharding"),
is(".sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("%sharding"),
is(".*sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("%_sharding"),
is(".*.sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("\\_sharding"),
is("_sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("\\%sharding"),
is("%sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("\\%\\_sharding"),
is("%_sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("_\\_sharding"),
is("._sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("%\\%sharding"),
is(".*%sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("_\\%sharding"),
is(".%sharding"));
+ assertThat(RegexUtils.convertLikePatternToRegex("\\_%sharding"),
is("_.*sharding"));
+ }
+
+ @Test
+ void assertConvertLikePatternToRegexWhenContainsPattern() {
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_db"),
is("sharding.db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%db"),
is("sharding.*db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%_db"),
is("sharding.*.db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\_db"),
is("sharding_db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\%db"),
is("sharding%db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\%\\_db"),
is("sharding%_db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_\\_db"),
is("sharding._db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding%\\%db"),
is("sharding.*%db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding_\\%db"),
is("sharding.%db"));
+ assertThat(RegexUtils.convertLikePatternToRegex("sharding\\_%db"),
is("sharding_.*db"));
+ }
+}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
index 88c85941e66..2ac465f9f12 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java
@@ -22,10 +22,10 @@ import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTableStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import java.util.Arrays;
import java.util.Collection;
@@ -58,7 +58,7 @@ public final class ShowSingleTableExecutor implements
DistSQLQueryExecutor<ShowS
private Optional<Pattern> getPattern(final ShowSingleTableStatement
sqlStatement) {
return sqlStatement.getLikePattern().isPresent()
- ?
Optional.of(Pattern.compile(SQLUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get()),
Pattern.CASE_INSENSITIVE))
+ ?
Optional.of(Pattern.compile(RegexUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get()),
Pattern.CASE_INSENSITIVE))
: Optional.empty();
}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtils.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtils.java
index 84914583e0a..bd38d583599 100644
---
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtils.java
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtils.java
@@ -39,7 +39,6 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
-import java.util.regex.Pattern;
/**
* SQL utility class.
@@ -57,14 +56,6 @@ public final class SQLUtils {
private static final String EXCLUDED_CHARACTERS = "[]'\"";
- private static final Pattern SINGLE_CHARACTER_PATTERN =
Pattern.compile("([^\\\\])_|^_");
-
- private static final Pattern SINGLE_CHARACTER_ESCAPE_PATTERN =
Pattern.compile("\\\\_");
-
- private static final Pattern ANY_CHARACTER_PATTERN =
Pattern.compile("([^\\\\])%|^%");
-
- private static final Pattern ANY_CHARACTER_ESCAPE_PATTERN =
Pattern.compile("\\\\%");
-
/**
* Get exactly number value and type.
*
@@ -108,7 +99,7 @@ public final class SQLUtils {
*
* <p>remove special char for SQL expression</p>
*
- * @param value SQL expression
+ * @param value SQL expression
* @param reservedCharacters characters to be reserved
* @return exactly SQL expression
*/
@@ -270,23 +261,4 @@ public final class SQLUtils {
}
return result.trim();
}
-
- /**
- * Convert like pattern to regex.
- *
- * @param pattern like pattern
- * @return regex
- */
- public static String convertLikePatternToRegex(final String pattern) {
- String result = pattern;
- if (pattern.contains("_")) {
- result =
SINGLE_CHARACTER_PATTERN.matcher(result).replaceAll("$1.");
- result =
SINGLE_CHARACTER_ESCAPE_PATTERN.matcher(result).replaceAll("_");
- }
- if (pattern.contains("%")) {
- result = ANY_CHARACTER_PATTERN.matcher(result).replaceAll("$1.*");
- result =
ANY_CHARACTER_ESCAPE_PATTERN.matcher(result).replaceAll("%");
- }
- return result;
- }
}
diff --git
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilsTest.java
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilsTest.java
index e42168eab41..6c8571ffc3e 100644
---
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilsTest.java
+++
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilsTest.java
@@ -101,48 +101,6 @@ class SQLUtilsTest {
assertThat(SQLUtils.getExpressionWithoutOutsideParentheses(""),
is(""));
}
- @Test
- void assertConvertLikePatternToRegexWhenEndWithPattern() {
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_"),
is("sharding."));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%"),
is("sharding.*"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%_"),
is("sharding.*."));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\_"),
is("sharding_"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\%"),
is("sharding%"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\%\\_"),
is("sharding%_"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_\\_"),
is("sharding._"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%\\%"),
is("sharding.*%"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_\\%"),
is("sharding.%"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\_%"),
is("sharding_.*"));
- }
-
- @Test
- void assertConvertLikePatternToRegexWhenStartWithPattern() {
- assertThat(SQLUtils.convertLikePatternToRegex("_sharding"),
is(".sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("%sharding"),
is(".*sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("%_sharding"),
is(".*.sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("\\_sharding"),
is("_sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("\\%sharding"),
is("%sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("\\%\\_sharding"),
is("%_sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("_\\_sharding"),
is("._sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("%\\%sharding"),
is(".*%sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("_\\%sharding"),
is(".%sharding"));
- assertThat(SQLUtils.convertLikePatternToRegex("\\_%sharding"),
is("_.*sharding"));
- }
-
- @Test
- void assertConvertLikePatternToRegexWhenContainsPattern() {
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_db"),
is("sharding.db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%db"),
is("sharding.*db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%_db"),
is("sharding.*.db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\_db"),
is("sharding_db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\%db"),
is("sharding%db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\%\\_db"),
is("sharding%_db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_\\_db"),
is("sharding._db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding%\\%db"),
is("sharding.*%db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding_\\%db"),
is("sharding.%db"));
- assertThat(SQLUtils.convertLikePatternToRegex("sharding\\_%db"),
is("sharding_.*db"));
- }
-
@Test
void assertTrimSemiColon() {
assertThat(SQLUtils.trimSemicolon("SHOW DATABASES;"), is("SHOW
DATABASES"));
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
index 6c354ca4a93..c3d232e4bd2 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
@@ -27,12 +27,12 @@ import
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigura
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
+import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
import org.apache.shardingsphere.logging.util.LoggingUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import java.util.Arrays;
import java.util.Collection;
@@ -67,7 +67,7 @@ public final class ShowDistVariablesExecutor implements
DistSQLQueryExecutor<Sho
result.add(new
LocalDataQueryResultRow(DistSQLVariable.CACHED_CONNECTIONS.name().toLowerCase(),
connectionContext.getConnectionSize()));
addLoggingPropsRows(metaData, result);
if (sqlStatement.getLikePattern().isPresent()) {
- String pattern =
SQLUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get());
+ String pattern =
RegexUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get());
result = result.stream().filter(each -> Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE).matcher((String)
each.getCell(1)).matches()).collect(Collectors.toList());
}
return result.stream().sorted(Comparator.comparing(each ->
each.getCell(1).toString())).collect(Collectors.toList());
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
index 7a9537a935c..db848ca2b49 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowLogicalTableExecutor.java
@@ -25,8 +25,8 @@ import
org.apache.shardingsphere.infra.database.core.metadata.database.DialectDa
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import java.util.Collection;
import java.util.Collections;
@@ -55,7 +55,7 @@ public final class ShowLogicalTableExecutor implements
DistSQLQueryExecutor<Show
}
Collection<String> tables =
database.getSchema(schemaName).getAllTableNames();
if (sqlStatement.getLikePattern().isPresent()) {
- String pattern =
SQLUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get());
+ String pattern =
RegexUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get());
tables = tables.stream().filter(each -> Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE).matcher(each).matches()).collect(Collectors.toList());
}
return
tables.stream().map(LocalDataQueryResultRow::new).collect(Collectors.toList());
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutor.java
index c95d4b70ca8..995f73235f0 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutor.java
@@ -27,10 +27,10 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.ra
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
import java.sql.Types;
@@ -64,7 +64,7 @@ public final class ShowDatabasesExecutor implements
DatabaseAdminQueryExecutor {
private boolean checkLikePattern(final String databaseName) {
if (showDatabasesStatement.getFilter().isPresent()) {
- Optional<String> pattern =
showDatabasesStatement.getFilter().get().getLike().map(optional ->
SQLUtils.convertLikePatternToRegex(optional.getPattern()));
+ Optional<String> pattern =
showDatabasesStatement.getFilter().get().getLike().map(optional ->
RegexUtils.convertLikePatternToRegex(optional.getPattern()));
return !pattern.isPresent() || databaseName.matches(pattern.get());
}
return true;
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 f0dc75c3ccf..3a0374cd8f4 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
@@ -30,10 +30,10 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.me
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowTablesStatement;
import java.sql.Types;
@@ -99,7 +99,7 @@ public final class ShowTablesExecutor implements
DatabaseAdminQueryExecutor {
if (!showTablesStatement.getFilter().isPresent()) {
return result;
}
- Optional<String> pattern =
showTablesStatement.getFilter().get().getLike().map(optional ->
SQLUtils.convertLikePatternToRegex(optional.getPattern()));
+ 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;
}
}