You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/08 02:46:12 UTC
[doris] 04/05: [Improvement](meta)add IsCurrent column in show catalogs result #14700
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
commit 56ce20993e8df4ff876d508e5249af44b4e61d46
Author: Yulei-Yang <yu...@gmail.com>
AuthorDate: Mon Dec 5 08:32:16 2022 +0800
[Improvement](meta)add IsCurrent column in show catalogs result #14700
When a user has multiple catalogs and switch several times, he may forget which catalog is using. So I add a iscurrent column in show catalogs result for help.
mysql> show catalogs;
+-----------+-------------+----------+-----------+
| CatalogId | CatalogName | Type | IsCurrent |
+-----------+-------------+----------+-----------+
| 136591 | es | es | |
| 130100 | hive | hms | yes |
| 0 | internal | internal | |
+-----------+-------------+----------+-----------+
---
.../sql-reference/Show-Statements/SHOW-CATALOGS.md | 23 +++++++++++-----------
.../sql-reference/Show-Statements/SHOW-CATALOGS.md | 23 +++++++++++-----------
.../org/apache/doris/analysis/ShowCatalogStmt.java | 1 +
.../org/apache/doris/datasource/CatalogMgr.java | 11 +++++++++++
.../java/org/apache/doris/qe/ShowExecutor.java | 4 ++--
.../apache/doris/analysis/ShowCatalogStmtTest.java | 4 ++--
.../apache/doris/datasource/CatalogMgrTest.java | 11 +++++++++++
7 files changed, 51 insertions(+), 26 deletions(-)
diff --git a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
index 712f449ebb..0d8bba8c34 100644
--- a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
+++ b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
@@ -50,6 +50,7 @@ Return result:
* CatalogId: Unique ID of the catalog
* CatalogName: Catalog name. where "internal" is the default built-in catalog, which cannot be modified.
* Type: Catalog type.
+* IsCurrent: Show yes on the line of current using catalog.
### Example
@@ -57,23 +58,23 @@ Return result:
```sql
SHOW CATALOGS;
- +-----------+-------------+----------+
- | CatalogId | CatalogName | Type |
- +-----------+-------------+----------+
- | 10024 | hive | hms |
- | 0 | internal | internal |
- +-----------+-------------+----------+
+ +-----------+-------------+----------+-----------+
+ | CatalogId | CatalogName | Type | IsCurrent |
+ +-----------+-------------+----------+-----------+
+ | 130100 | hive | hms | |
+ | 0 | internal | internal | yes |
+ +-----------+-------------+----------+-----------+
```
2. Fuzzy query by catalog name
```sql
SHOW CATALOGS LIKE 'hi%';
- +-----------+-------------+----------+
- | CatalogId | CatalogName | Type |
- +-----------+-------------+----------+
- | 10024 | hive | hms |
- +-----------+-------------+----------+
+ +-----------+-------------+----------+-----------+
+ | CatalogId | CatalogName | Type | IsCurrent |
+ +-----------+-------------+----------+-----------+
+ | 130100 | hive | hms | |
+ +-----------+-------------+----------+-----------+
```
### Keywords
diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
index 811f8cb4d1..ddc30d1e05 100644
--- a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
+++ b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS.md
@@ -53,6 +53,7 @@ LIKE:可按照CATALOG名进行模糊查询
* CatalogId:数据目录唯一ID
* CatalogName:数据目录名称。其中 internal 是默认内置的 catalog,不可修改。
* Type:数据目录类型。
+* IsCurrent: 是否为当前正在使用的数据目录。
### Example
@@ -60,23 +61,23 @@ LIKE:可按照CATALOG名进行模糊查询
```sql
SHOW CATALOGS;
- +-----------+-------------+----------+
- | CatalogId | CatalogName | Type |
- +-----------+-------------+----------+
- | 10024 | hive | hms |
- | 0 | internal | internal |
- +-----------+-------------+----------+
+ +-----------+-------------+----------+-----------+
+ | CatalogId | CatalogName | Type | IsCurrent |
+ +-----------+-------------+----------+-----------+
+ | 130100 | hive | hms | |
+ | 0 | internal | internal | yes |
+ +-----------+-------------+----------+-----------+
```
2. 按照目录名进行模糊搜索
```sql
SHOW CATALOGS LIKE 'hi%';
- +-----------+-------------+----------+
- | CatalogId | CatalogName | Type |
- +-----------+-------------+----------+
- | 10024 | hive | hms |
- +-----------+-------------+----------+
+ +-----------+-------------+----------+-----------+
+ | CatalogId | CatalogName | Type | IsCurrent |
+ +-----------+-------------+----------+-----------+
+ | 130100 | hive | hms | |
+ +-----------+-------------+----------+-----------+
```
### Keywords
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCatalogStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCatalogStmt.java
index 62fb146daa..3863f1c39f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCatalogStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCatalogStmt.java
@@ -30,6 +30,7 @@ public class ShowCatalogStmt extends ShowStmt {
ShowResultSetMetaData.builder().addColumn(new Column("CatalogId", ScalarType.BIGINT))
.addColumn(new Column("CatalogName", ScalarType.createVarchar(64)))
.addColumn(new Column("Type", ScalarType.createStringType()))
+ .addColumn(new Column("IsCurrent", ScalarType.createStringType()))
.build();
private static final ShowResultSetMetaData META_DATA_SPECIFIC =
diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
index 403270044c..255b63526f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
@@ -74,6 +74,8 @@ import java.util.stream.Collectors;
public class CatalogMgr implements Writable, GsonPostProcessable {
private static final Logger LOG = LogManager.getLogger(CatalogMgr.class);
+ private static final String YES = "yes";
+
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
@SerializedName(value = "idToCatalog")
@@ -341,6 +343,10 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
* List all catalog or get the special catalog with a name.
*/
public ShowResultSet showCatalogs(ShowCatalogStmt showStmt) throws AnalysisException {
+ return showCatalogs(showStmt, InternalCatalog.INTERNAL_CATALOG_NAME);
+ }
+
+ public ShowResultSet showCatalogs(ShowCatalogStmt showStmt, String currentCtlg) throws AnalysisException {
List<List<String>> rows = Lists.newArrayList();
readLock();
try {
@@ -363,6 +369,11 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
row.add(String.valueOf(catalog.getId()));
row.add(name);
row.add(catalog.getType());
+ if (name.equals(currentCtlg)) {
+ row.add(YES);
+ } else {
+ row.add("");
+ }
rows.add(row);
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
index a8c38c04b0..f1e5ab9113 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
@@ -2173,7 +2173,7 @@ public class ShowExecutor {
columnStatistics.add(Pair.of(column.getName(), columnStatistic));
} else {
columnStatistics.addAll(StatisticsRepository.queryColumnStatisticsByPartitions(tableName,
- colName, showColumnStatsStmt.getPartitionNames().getPartitionNames())
+ colName, showColumnStatsStmt.getPartitionNames().getPartitionNames())
.stream().map(s -> Pair.of(colName, s))
.collect(Collectors.toList()));
}
@@ -2315,7 +2315,7 @@ public class ShowExecutor {
public void handleShowCatalogs() throws AnalysisException {
ShowCatalogStmt showStmt = (ShowCatalogStmt) stmt;
- resultSet = Env.getCurrentEnv().getCatalogMgr().showCatalogs(showStmt);
+ resultSet = Env.getCurrentEnv().getCatalogMgr().showCatalogs(showStmt, ctx.getCurrentCatalog().getName());
}
// Show create catalog
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowCatalogStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowCatalogStmtTest.java
index 2f03b3174c..bb881515cf 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowCatalogStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowCatalogStmtTest.java
@@ -30,14 +30,14 @@ public class ShowCatalogStmtTest {
ShowCatalogStmt stmt = new ShowCatalogStmt();
stmt.analyze(analyzer);
Assert.assertNull(stmt.getCatalogName());
- Assert.assertEquals(3, stmt.getMetaData().getColumnCount());
+ Assert.assertEquals(4, stmt.getMetaData().getColumnCount());
Assert.assertEquals("SHOW CATALOGS", stmt.toSql());
stmt = new ShowCatalogStmt(null, "%hive%");
stmt.analyze(analyzer);
Assert.assertNull(stmt.getCatalogName());
Assert.assertNotNull(stmt.getPattern());
- Assert.assertEquals(3, stmt.getMetaData().getColumnCount());
+ Assert.assertEquals(4, stmt.getMetaData().getColumnCount());
Assert.assertEquals("SHOW CATALOGS LIKE '%hive%'", stmt.toSql());
stmt = new ShowCatalogStmt("testCatalog", null);
diff --git a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
index a09ca07ee5..13931798af 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
@@ -337,6 +337,12 @@ public class CatalogMgrTest extends TestWithFeService {
// user2 can switch to internal catalog
parseAndAnalyzeStmt("switch " + InternalCatalog.INTERNAL_CATALOG_NAME + ";", user2Ctx);
Assert.assertEquals(InternalCatalog.INTERNAL_CATALOG_NAME, user2Ctx.getDefaultCatalog());
+
+ String showCatalogSql = "SHOW CATALOGS";
+ ShowCatalogStmt showStmt = (ShowCatalogStmt) parseAndAnalyzeStmt(showCatalogSql);
+ ShowResultSet showResultSet = mgr.showCatalogs(showStmt, user2Ctx.getCurrentCatalog().getName());
+ Assertions.assertEquals("yes", showResultSet.getResultRows().get(1).get(3));
+
// user2 can switch to hive
SwitchStmt switchHive = (SwitchStmt) parseAndAnalyzeStmt("switch hive;", user2Ctx);
env.changeCatalog(user2Ctx, switchHive.getCatalogName());
@@ -345,6 +351,11 @@ public class CatalogMgrTest extends TestWithFeService {
GrantStmt user2GrantHiveTable = (GrantStmt) parseAndAnalyzeStmt(
"grant select_priv on tpch.customer to 'user2'@'%';", user2Ctx);
auth.grant(user2GrantHiveTable);
+
+ showCatalogSql = "SHOW CATALOGS";
+ showStmt = (ShowCatalogStmt) parseAndAnalyzeStmt(showCatalogSql);
+ showResultSet = mgr.showCatalogs(showStmt, user2Ctx.getCurrentCatalog().getName());
+ Assertions.assertEquals("yes", showResultSet.getResultRows().get(0).get(3));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org