This is an automated email from the ASF dual-hosted git repository.
chenjiahao 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 da95e15bf00 Enhance the output information of SHOW TABLE METADATA
(#29228)
da95e15bf00 is described below
commit da95e15bf00aa078c1b23382a4a7faba8dae6199
Author: Raigor <[email protected]>
AuthorDate: Tue Nov 28 18:03:34 2023 +0800
Enhance the output information of SHOW TABLE METADATA (#29228)
---
.../query/ShowUnloadedSingleTableExecutor.java | 2 +-
.../ral/queryable/ShowTableMetaDataExecutor.java | 25 +++++++++++++---------
.../queryable/ShowTableMetaDataExecutorTest.java | 6 +++++-
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
index 08d51d6bc90..38e330b79c3 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
@@ -54,7 +54,7 @@ public final class ShowUnloadedSingleTableExecutor implements
RQLExecutor<ShowUn
Optional<SingleRule> singleRule =
database.getRuleMetaData().findSingleRule(SingleRule.class);
if (singleRule.isPresent()) {
for (String each :
singleRule.get().getLogicTableMapper().getTableNames()) {
- actualDataNodes.remove(each);
+ actualDataNodes.remove(each.toLowerCase());
}
}
actualDataNodes.forEach((key, value) -> result.add(new
LocalDataQueryResultRow(key, value.iterator().next().getDataSourceName())));
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
index 3c82b114ab9..08c0ac5d978 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
@@ -22,8 +22,11 @@ import
org.apache.shardingsphere.distsql.statement.ral.queryable.ShowTableMetaDa
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.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
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.util.json.JsonUtils;
import java.util.Arrays;
import java.util.Collection;
@@ -37,29 +40,31 @@ public final class ShowTableMetaDataExecutor implements
DatabaseRequiredQueryabl
@Override
public Collection<String> getColumnNames() {
- return Arrays.asList("database_name", "table_name", "type", "name");
+ return Arrays.asList("database_name", "table_name", "type", "name",
"value");
}
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowTableMetaDataStatement sqlStatement)
{
String defaultSchema = new
DatabaseTypeRegistry(database.getProtocolType()).getDefaultSchemaName(database.getName());
ShardingSphereSchema schema = database.getSchema(defaultSchema);
- return schema.getAllTableNames().stream().filter(each ->
sqlStatement.getTableNames().contains(each))
- .map(each -> buildTableRows(database.getName(), schema,
each)).flatMap(Collection::stream).collect(Collectors.toList());
+ return sqlStatement.getTableNames().stream().filter(each ->
schema.getAllTableNames().contains(each.toLowerCase()))
+ .map(each -> buildTableRows(database.getName(), schema,
each.toLowerCase())).flatMap(Collection::stream).collect(Collectors.toList());
}
private Collection<LocalDataQueryResultRow> buildTableRows(final String
databaseName, final ShardingSphereSchema schema, final String tableName) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- Collection<LocalDataQueryResultRow> columnRows =
schema.getAllColumnNames(tableName).stream().map(each -> buildRow(databaseName,
tableName, "COLUMN", each)).collect(Collectors.toList());
- Collection<LocalDataQueryResultRow> indexRows =
schema.getTable(tableName).getIndexValues().stream().map(ShardingSphereIndex::getName)
- .map(each -> buildRow(databaseName, tableName, "INDEX",
each)).collect(Collectors.toList());
- result.addAll(columnRows);
- result.addAll(indexRows);
+ ShardingSphereTable table = schema.getTable(tableName);
+ result.addAll(table.getColumnValues().stream().map(each ->
buildColumnRow(databaseName, tableName, each)).collect(Collectors.toList()));
+ result.addAll(table.getIndexValues().stream().map(each ->
buildIndexRow(databaseName, tableName, each)).collect(Collectors.toList()));
return result;
}
- private LocalDataQueryResultRow buildRow(final String databaseName, final
String tableName, final String type, final String name) {
- return new LocalDataQueryResultRow(databaseName, tableName, type,
name);
+ private LocalDataQueryResultRow buildColumnRow(final String databaseName,
final String tableName, final ShardingSphereColumn column) {
+ return new LocalDataQueryResultRow(databaseName, tableName, "COLUMN",
column.getName(), JsonUtils.toJsonString(column));
+ }
+
+ private LocalDataQueryResultRow buildIndexRow(final String databaseName,
final String tableName, final ShardingSphereIndex index) {
+ return new LocalDataQueryResultRow(databaseName, tableName, "INDEX",
index.getName(), JsonUtils.toJsonString(index));
}
@Override
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
index 60ff4d66708..1638f08f726 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
@@ -54,12 +54,13 @@ class ShowTableMetaDataExecutorTest {
void assertGetColumnNames() {
ShowTableMetaDataExecutor executor = new ShowTableMetaDataExecutor();
Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(4));
+ assertThat(columns.size(), is(5));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("database_name"));
assertThat(iterator.next(), is("table_name"));
assertThat(iterator.next(), is("type"));
assertThat(iterator.next(), is("name"));
+ assertThat(iterator.next(), is("value"));
}
@Test
@@ -73,11 +74,14 @@ class ShowTableMetaDataExecutorTest {
assertThat(row.getCell(2), is("t_order"));
assertThat(row.getCell(3), is("COLUMN"));
assertThat(row.getCell(4), is("order_id"));
+ assertThat(row.getCell(5),
+
is("{\"name\":\"order_id\",\"dataType\":0,\"primaryKey\":false,\"generated\":false,\"caseSensitive\":false,\"visible\":true,\"unsigned\":false,\"nullable\":false}"));
row = iterator.next();
assertThat(row.getCell(1), is("foo_db"));
assertThat(row.getCell(2), is("t_order"));
assertThat(row.getCell(3), is("INDEX"));
assertThat(row.getCell(4), is("primary"));
+ assertThat(row.getCell(5),
is("{\"name\":\"primary\",\"columns\":[],\"unique\":false}"));
}
private ShardingSphereDatabase mockDatabase() {