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 f08c62f302979..808491761aa65 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.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 @@ void setUp() { 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 tables = Maps.of("t_order", mockShardingSphereTable("t_order"), "t_order_item", mockShardingSphereTable("t_order_item")); + when(schema.getTables()).thenReturn(tables); executor.setDatabase(database); } @@ -78,4 +82,20 @@ void assertRowDataWithLike() { Iterator iterator = actual.iterator(); assertThat(iterator.next().getCell(1), is("t_order_item")); } + + @Test + void assertRowDataWithFullAndLike() { + Collection 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 2cb5792084838..317ed43bbe443 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 @@ void assertGetRowsWithAllStorageUnits() { nameMap.put(2, "ds_0"); Collection actual = executor.getRows(new ShowStorageUnitsStatement(mock(DatabaseSegment.class), null, null), mock(ContextManager.class)); assertThat(actual.size(), is(3)); - Iterator rowData = actual.iterator(); + Iterator 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 @@ void assertGetRowsWithAllStorageUnits() { void assertGetRowsWithLikePattern() { Collection 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 @@ void assertGetRowsWithUnusedStorageUnits() { when(database.getRuleMetaData()).thenReturn(metaData); Collection actual = executor.getRows(new ShowStorageUnitsStatement(mock(DatabaseSegment.class), null, 0), mock(ContextManager.class)); assertThat(actual.size(), is(1)); - Iterator 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/test/it/parser/src/main/resources/case/rql/show.xml b/test/it/parser/src/main/resources/case/rql/show.xml index 335d57a83606e..6405159537fd7 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 @@ - + 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 44c6aac70b687..b29d819a2cb40 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 @@ - +