This is an automated email from the ASF dual-hosted git repository.
jiangmaolin 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 09004d58330 Improve show logical tables, add table type to result set
(#32626)
09004d58330 is described below
commit 09004d58330a098072e9031eb4a66aaa0e92166c
Author: Raigor <[email protected]>
AuthorDate: Thu Aug 22 13:29:53 2024 +0800
Improve show logical tables, add table type to result set (#32626)
* Improve show logical tables, add table type to result set
* Update test cases
---
.../rql/resource/ShowLogicalTableExecutor.java | 36 ++++++++--
.../rql/resource/ShowLogicalTableExecutorTest.java | 26 ++++++-
.../rql/resource/ShowStorageUnitExecutorTest.java | 83 +++++++++++-----------
.../engine/src/main/antlr4/imports/Keyword.g4 | 4 ++
.../engine/src/main/antlr4/imports/RQLStatement.g4 | 2 +-
.../core/kernel/KernelDistSQLStatementVisitor.java | 5 +-
.../rql/resource/ShowLogicalTablesStatement.java | 7 +-
.../handler/admin/executor/ShowTablesExecutor.java | 26 +++----
.../it/parser/src/main/resources/case/rql/show.xml | 2 +-
.../src/main/resources/sql/supported/rql/show.xml | 2 +-
10 files changed, 123 insertions(+), 70 deletions(-)
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutor.java
index 82ad9857245..954b0c549dc 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutor.java
@@ -25,11 +25,15 @@ 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.metadata.database.schema.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -43,7 +47,9 @@ public final class ShowLogicalTableExecutor implements
DistSQLQueryExecutor<Show
@Override
public Collection<String> getColumnNames(final ShowLogicalTablesStatement
sqlStatement) {
- return Collections.singleton("table_name");
+ return sqlStatement.isContainsFull()
+ ? Arrays.asList(String.format("Tables_in_%s",
database.getName()), "Table_type")
+ : Collections.singleton(String.format("Tables_in_%s",
database.getName()));
}
@Override
@@ -53,12 +59,30 @@ public final class ShowLogicalTableExecutor implements
DistSQLQueryExecutor<Show
if (null == database.getSchema(schemaName)) {
return Collections.emptyList();
}
- Collection<String> tables =
database.getSchema(schemaName).getAllTableNames();
- if (sqlStatement.getLikePattern().isPresent()) {
- 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 getTables(schemaName, sqlStatement).stream().map(each ->
getRow(each, sqlStatement)).collect(Collectors.toList());
+ }
+
+ private LocalDataQueryResultRow getRow(final ShardingSphereTable table,
final ShowLogicalTablesStatement sqlStatement) {
+ return sqlStatement.isContainsFull() ? new
LocalDataQueryResultRow(table.getName(), table.getType()) : new
LocalDataQueryResultRow(table.getName());
+ }
+
+ private Collection<ShardingSphereTable> getTables(final String schemaName,
final ShowLogicalTablesStatement sqlStatement) {
+ Collection<ShardingSphereTable> tables =
database.getSchema(schemaName).getTables().values();
+ Collection<ShardingSphereTable> filteredTables = filterByLike(tables,
sqlStatement);
+ return
filteredTables.stream().sorted(Comparator.comparing(ShardingSphereTable::getName)).collect(Collectors.toList());
+ }
+
+ private Collection<ShardingSphereTable> filterByLike(final
Collection<ShardingSphereTable> tables, final ShowLogicalTablesStatement
sqlStatement) {
+ Optional<Pattern> likePattern = getLikePattern(sqlStatement);
+ return likePattern.isPresent() ? tables.stream().filter(each ->
likePattern.get().matcher(each.getName()).matches()).collect(Collectors.toList())
: tables;
+ }
+
+ private Optional<Pattern> getLikePattern(final ShowLogicalTablesStatement
sqlStatement) {
+ if (!sqlStatement.getLikePattern().isPresent()) {
+ return Optional.empty();
}
- return
tables.stream().map(LocalDataQueryResultRow::new).collect(Collectors.toList());
+ Optional<String> pattern =
sqlStatement.getLikePattern().map(RegexUtils::convertLikePatternToRegex);
+ return pattern.map(optional ->
Pattern.compile(RegexUtils.convertLikePatternToRegex(optional),
Pattern.CASE_INSENSITIVE));
}
@Override
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutorTest.java
index 2f97644c0fe..808491761aa 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTableExecutorTest.java
@@ -17,11 +17,14 @@
package org.apache.shardingsphere.distsql.handler.executor.rql.resource;
+import org.apache.groovy.util.Maps;
import
org.apache.shardingsphere.distsql.statement.rql.resource.ShowLogicalTablesStatement;
+import
org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.junit.jupiter.api.BeforeEach;
@@ -32,9 +35,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -56,7 +59,8 @@ class ShowLogicalTableExecutorTest {
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema("foo_db")).thenReturn(schema);
- when(schema.getAllTableNames()).thenReturn(Arrays.asList("t_order",
"t_order_item"));
+ Map<String, ShardingSphereTable> tables = Maps.of("t_order",
mockShardingSphereTable("t_order"), "t_order_item",
mockShardingSphereTable("t_order_item"));
+ when(schema.getTables()).thenReturn(tables);
executor.setDatabase(database);
}
@@ -73,9 +77,25 @@ class ShowLogicalTableExecutorTest {
@Test
void assertRowDataWithLike() {
- Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowLogicalTablesStatement("t_order_%", null), mock(ContextManager.class));
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowLogicalTablesStatement(false, null, "t_order_%"),
mock(ContextManager.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
assertThat(iterator.next().getCell(1), is("t_order_item"));
}
+
+ @Test
+ void assertRowDataWithFullAndLike() {
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowLogicalTablesStatement(true, null, "t_order_%"),
mock(ContextManager.class));
+ assertThat(actual.size(), is(1));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("t_order_item"));
+ assertThat(row.getCell(2), is("TABLE"));
+ }
+
+ private ShardingSphereTable mockShardingSphereTable(final String
tableName) {
+ ShardingSphereTable result = mock(ShardingSphereTable.class);
+ when(result.getName()).thenReturn(tableName);
+ when(result.getType()).thenReturn(TableType.TABLE);
+ return result;
+ }
}
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutorTest.java
index 2cb57920848..317ed43bbe4 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowStorageUnitExecutorTest.java
@@ -78,22 +78,22 @@ class ShowStorageUnitExecutorTest {
nameMap.put(2, "ds_0");
Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), null, null),
mock(ContextManager.class));
assertThat(actual.size(), is(3));
- Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
+ Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
int index = 0;
- while (rowData.hasNext()) {
- LocalDataQueryResultRow data = rowData.next();
- assertThat(data.getCell(1), is(nameMap.get(index)));
- assertThat(data.getCell(2), is("MySQL"));
- assertThat(data.getCell(3), is("localhost"));
- assertThat(data.getCell(4), is("3307"));
- assertThat(data.getCell(5), is(nameMap.get(index)));
- assertThat(data.getCell(6), is(""));
- assertThat(data.getCell(7), is(""));
- assertThat(data.getCell(8), is(""));
- assertThat(data.getCell(9), is("100"));
- assertThat(data.getCell(10), is("10"));
- assertThat(data.getCell(11), is(""));
- assertThat(data.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
+ while (iterator.hasNext()) {
+ LocalDataQueryResultRow row = iterator.next();
+ assertThat(row.getCell(1), is(nameMap.get(index)));
+ assertThat(row.getCell(2), is("MySQL"));
+ assertThat(row.getCell(3), is("localhost"));
+ assertThat(row.getCell(4), is("3307"));
+ assertThat(row.getCell(5), is(nameMap.get(index)));
+ assertThat(row.getCell(6), is(""));
+ assertThat(row.getCell(7), is(""));
+ assertThat(row.getCell(8), is(""));
+ assertThat(row.getCell(9), is("100"));
+ assertThat(row.getCell(10), is("10"));
+ assertThat(row.getCell(11), is(""));
+ assertThat(row.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
index++;
}
}
@@ -102,19 +102,19 @@ class ShowStorageUnitExecutorTest {
void assertGetRowsWithLikePattern() {
Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), "_0", null),
mock(ContextManager.class));
assertThat(actual.size(), is(1));
- LocalDataQueryResultRow data = actual.iterator().next();
- assertThat(data.getCell(1), is("ds_0"));
- assertThat(data.getCell(2), is("MySQL"));
- assertThat(data.getCell(3), is("localhost"));
- assertThat(data.getCell(4), is("3307"));
- assertThat(data.getCell(5), is("ds_0"));
- assertThat(data.getCell(6), is(""));
- assertThat(data.getCell(7), is(""));
- assertThat(data.getCell(8), is(""));
- assertThat(data.getCell(9), is("100"));
- assertThat(data.getCell(10), is("10"));
- assertThat(data.getCell(11), is(""));
- assertThat(data.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("ds_0"));
+ assertThat(row.getCell(2), is("MySQL"));
+ assertThat(row.getCell(3), is("localhost"));
+ assertThat(row.getCell(4), is("3307"));
+ assertThat(row.getCell(5), is("ds_0"));
+ assertThat(row.getCell(6), is(""));
+ assertThat(row.getCell(7), is(""));
+ assertThat(row.getCell(8), is(""));
+ assertThat(row.getCell(9), is("100"));
+ assertThat(row.getCell(10), is("10"));
+ assertThat(row.getCell(11), is(""));
+ assertThat(row.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
}
@Test
@@ -123,20 +123,19 @@ class ShowStorageUnitExecutorTest {
when(database.getRuleMetaData()).thenReturn(metaData);
Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), null, 0),
mock(ContextManager.class));
assertThat(actual.size(), is(1));
- Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
- LocalDataQueryResultRow data = rowData.next();
- assertThat(data.getCell(1), is("ds_2"));
- assertThat(data.getCell(2), is("MySQL"));
- assertThat(data.getCell(3), is("localhost"));
- assertThat(data.getCell(4), is("3307"));
- assertThat(data.getCell(5), is("ds_2"));
- assertThat(data.getCell(6), is(""));
- assertThat(data.getCell(7), is(""));
- assertThat(data.getCell(8), is(""));
- assertThat(data.getCell(9), is("100"));
- assertThat(data.getCell(10), is("10"));
- assertThat(data.getCell(11), is(""));
- assertThat(data.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("ds_2"));
+ assertThat(row.getCell(2), is("MySQL"));
+ assertThat(row.getCell(3), is("localhost"));
+ assertThat(row.getCell(4), is("3307"));
+ assertThat(row.getCell(5), is("ds_2"));
+ assertThat(row.getCell(6), is(""));
+ assertThat(row.getCell(7), is(""));
+ assertThat(row.getCell(8), is(""));
+ assertThat(row.getCell(9), is("100"));
+ assertThat(row.getCell(10), is("10"));
+ assertThat(row.getCell(11), is(""));
+ assertThat(row.getCell(12),
is("{\"openedConnections\":[],\"closed\":false}"));
}
private RuleMetaData mockUnusedStorageUnitsRuleMetaData() {
diff --git a/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
b/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
index 6f096e6417f..93a556892e0 100644
--- a/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
+++ b/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
@@ -127,6 +127,10 @@ DATABASE
: D A T A B A S E
;
+FULL
+ : F U L L
+ ;
+
LOGICAL
: L O G I C A L
;
diff --git a/parser/distsql/engine/src/main/antlr4/imports/RQLStatement.g4
b/parser/distsql/engine/src/main/antlr4/imports/RQLStatement.g4
index faa74e7783d..65093eb0de1 100644
--- a/parser/distsql/engine/src/main/antlr4/imports/RQLStatement.g4
+++ b/parser/distsql/engine/src/main/antlr4/imports/RQLStatement.g4
@@ -28,7 +28,7 @@ showRulesUsedStorageUnit
;
showLogicalTables
- : SHOW LOGICAL TABLES showLike? (FROM databaseName)?
+ : SHOW FULL? LOGICAL TABLES (FROM databaseName)? showLike?
;
usageCount
diff --git
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
index b583ea61b5c..e9127b12975 100644
---
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
+++
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
@@ -237,8 +237,9 @@ public final class KernelDistSQLStatementVisitor extends
KernelDistSQLStatementB
@Override
public ASTNode visitShowLogicalTables(final ShowLogicalTablesContext ctx) {
- return new ShowLogicalTablesStatement(null == ctx.showLike() ? null :
getIdentifierValue(ctx.showLike().likePattern()),
- null == ctx.databaseName() ? null : (DatabaseSegment)
visit(ctx.databaseName()));
+ return new ShowLogicalTablesStatement(null != ctx.FULL(),
+ null == ctx.databaseName() ? null : (DatabaseSegment)
visit(ctx.databaseName()),
+ null == ctx.showLike() ? null :
getIdentifierValue(ctx.showLike().likePattern()));
}
@Override
diff --git
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/rql/resource/ShowLogicalTablesStatement.java
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/rql/resource/ShowLogicalTablesStatement.java
index 7e9859ce91e..96c4398e95c 100644
---
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/rql/resource/ShowLogicalTablesStatement.java
+++
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/rql/resource/ShowLogicalTablesStatement.java
@@ -17,14 +17,19 @@
package org.apache.shardingsphere.distsql.statement.rql.resource;
+import lombok.Getter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment;
/**
* Show logical tables statement.
*/
+@Getter
public final class ShowLogicalTablesStatement extends ShowTablesStatement {
- public ShowLogicalTablesStatement(final String likePattern, final
DatabaseSegment database) {
+ private final boolean containsFull;
+
+ public ShowLogicalTablesStatement(final boolean containsFull, final
DatabaseSegment database, final String likePattern) {
super(likePattern, database);
+ this.containsFull = containsFull;
}
}
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 d1a42ad60a2..b13f55f674e 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
@@ -37,6 +37,7 @@ import
org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement;
import java.sql.Types;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -52,7 +53,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
- private final ShowTablesStatement showTablesStatement;
+ private final ShowTablesStatement sqlStatement;
private final DatabaseType databaseType;
@@ -64,7 +65,7 @@ public final class ShowTablesExecutor implements
DatabaseAdminQueryExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- String databaseName = showTablesStatement.getFromDatabase().map(schema
->
schema.getDatabase().getIdentifier().getValue()).orElseGet(connectionSession::getUsedDatabaseName);
+ String databaseName = sqlStatement.getFromDatabase().map(schema ->
schema.getDatabase().getIdentifier().getValue()).orElseGet(connectionSession::getUsedDatabaseName);
queryResultMetaData = createQueryResultMetaData(databaseName);
mergedResult = new
TransparentMergedResult(getQueryResult(databaseName));
}
@@ -73,7 +74,7 @@ public final class ShowTablesExecutor implements
DatabaseAdminQueryExecutor {
List<RawQueryResultColumnMetaData> columnNames = new LinkedList<>();
String tableColumnName = String.format("Tables_in_%s", databaseName);
columnNames.add(new RawQueryResultColumnMetaData("", tableColumnName,
tableColumnName, Types.VARCHAR, "VARCHAR", 255, 0));
- if (showTablesStatement.isContainsFull()) {
+ if (sqlStatement.isContainsFull()) {
columnNames.add(new RawQueryResultColumnMetaData("", "Table_type",
"Table_type", Types.VARCHAR, "VARCHAR", 20, 0));
}
return new RawQueryResultMetaData(columnNames);
@@ -84,17 +85,16 @@ 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 =
getTables(databaseName).stream().map(each -> {
- List<Object> rowValues = new LinkedList<>();
- rowValues.add(each.getName());
- if (showTablesStatement.isContainsFull()) {
- rowValues.add(each.getType());
- }
- return new MemoryQueryResultDataRow(rowValues);
- }).collect(Collectors.toList());
+ List<MemoryQueryResultDataRow> rows =
getTables(databaseName).stream().map(this::getRow).collect(Collectors.toList());
return new RawMemoryQueryResult(queryResultMetaData, rows);
}
+ private MemoryQueryResultDataRow getRow(final ShardingSphereTable table) {
+ return sqlStatement.isContainsFull()
+ ? new MemoryQueryResultDataRow(Arrays.asList(table.getName(),
table.getType()))
+ : new
MemoryQueryResultDataRow(Collections.singletonList(table.getName()));
+ }
+
private Collection<ShardingSphereTable> getTables(final String
databaseName) {
Collection<ShardingSphereTable> tables =
ProxyContext.getInstance().getContextManager().getDatabase(databaseName).getSchema(databaseName).getTables().values();
Collection<ShardingSphereTable> filteredTables = filterByLike(tables);
@@ -107,10 +107,10 @@ public final class ShowTablesExecutor implements
DatabaseAdminQueryExecutor {
}
private Optional<Pattern> getLikePattern() {
- if (!showTablesStatement.getFilter().isPresent()) {
+ if (!sqlStatement.getFilter().isPresent()) {
return Optional.empty();
}
- Optional<String> pattern =
showTablesStatement.getFilter().get().getLike().map(optional ->
RegexUtils.convertLikePatternToRegex(optional.getPattern()));
+ Optional<String> pattern =
sqlStatement.getFilter().get().getLike().map(optional ->
RegexUtils.convertLikePatternToRegex(optional.getPattern()));
return pattern.map(optional ->
Pattern.compile(RegexUtils.convertLikePatternToRegex(optional),
Pattern.CASE_INSENSITIVE));
}
}
diff --git a/test/it/parser/src/main/resources/case/rql/show.xml
b/test/it/parser/src/main/resources/case/rql/show.xml
index 335d57a8360..6405159537f 100644
--- a/test/it/parser/src/main/resources/case/rql/show.xml
+++ b/test/it/parser/src/main/resources/case/rql/show.xml
@@ -192,6 +192,6 @@
</show-logical-tables>
<show-logical-tables sql-case-id="show-logical-tables-like"
like-pattern="t_%">
- <database name="sharding_db" start-index="36" stop-index="46" />
+ <database name="sharding_db" start-index="25" stop-index="35" />
</show-logical-tables>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/rql/show.xml
b/test/it/parser/src/main/resources/sql/supported/rql/show.xml
index 44c6aac70b6..b29d819a2cb 100644
--- a/test/it/parser/src/main/resources/sql/supported/rql/show.xml
+++ b/test/it/parser/src/main/resources/sql/supported/rql/show.xml
@@ -59,5 +59,5 @@
<sql-case id="show-storage-units-where-usage-count" value="SHOW STORAGE
UNITS FROM sharding_db WHERE USAGE_COUNT = 0" db-types="ShardingSphere" />
<sql-case id="show-logical-tables" value="SHOW LOGICAL TABLES"
db-types="ShardingSphere" />
<sql-case id="show-logical-tables-from" value="SHOW LOGICAL TABLES FROM
sharding_db" db-types="ShardingSphere" />
- <sql-case id="show-logical-tables-like" value="SHOW LOGICAL TABLES LIKE
't_%' FROM sharding_db" db-types="ShardingSphere" />
+ <sql-case id="show-logical-tables-like" value="SHOW LOGICAL TABLES FROM
sharding_db LIKE 't_%' " db-types="ShardingSphere" />
</sql-cases>