Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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 org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -56,21 +57,22 @@ public Collection<String> getColumnNames(final ShowLogicalTablesStatement sqlSta
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowLogicalTablesStatement sqlStatement, final ContextManager contextManager) {
DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(database.getProtocolType()).getDialectDatabaseMetaData();
String schemaName = dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().orElse(database.getName());
IdentifierValue schemaName = new IdentifierValue(dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().orElse(database.getName()));
if (null == database.getSchema(schemaName)) {
return Collections.emptyList();
}
return getTables(schemaName, sqlStatement).stream().map(each -> getRow(schemaName, each, sqlStatement)).collect(Collectors.toList());
}

private LocalDataQueryResultRow getRow(final String schemaName, final ShardingSphereTable table, final ShowLogicalTablesStatement sqlStatement) {
private LocalDataQueryResultRow getRow(final IdentifierValue schemaName, final ShardingSphereTable table, final ShowLogicalTablesStatement sqlStatement) {
if (new DatabaseTypeRegistry(database.getProtocolType()).getDialectDatabaseMetaData().getSchemaOption().isSchemaAvailable()) {
return sqlStatement.isContainsFull() ? new LocalDataQueryResultRow(table.getName(), table.getType(), schemaName) : new LocalDataQueryResultRow(table.getName(), schemaName);
return sqlStatement.isContainsFull() ? new LocalDataQueryResultRow(table.getName(), table.getType(), schemaName.getValue())
: new LocalDataQueryResultRow(table.getName(), schemaName.getValue());
}
return sqlStatement.isContainsFull() ? new LocalDataQueryResultRow(table.getName(), table.getType()) : new LocalDataQueryResultRow(table.getName());
}

private Collection<ShardingSphereTable> getTables(final String schemaName, final ShowLogicalTablesStatement sqlStatement) {
private Collection<ShardingSphereTable> getTables(final IdentifierValue schemaName, final ShowLogicalTablesStatement sqlStatement) {
Collection<ShardingSphereTable> tables = database.getSchema(schemaName).getAllTables();
Collection<ShardingSphereTable> filteredTables = filterByLike(tables, sqlStatement);
return filteredTables.stream().sorted(Comparator.comparing(ShardingSphereTable::getName)).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -57,7 +58,7 @@ void setUp() {
when(database.getName()).thenReturn("foo_db");
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema("foo_db")).thenReturn(schema);
when(database.getSchema(new IdentifierValue("foo_db"))).thenReturn(schema);
Collection<ShardingSphereTable> tables = Arrays.asList(mockShardingSphereTable("t_order"), mockShardingSphereTable("t_order_item"));
when(schema.getAllTables()).thenReturn(tables);
executor.setDatabase(database);
Expand Down
Loading