This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 852b03729f [Improvement](meta)add IsCurrent column in show catalogs
result #14700
852b03729f is described below
commit 852b03729f8a91a01383f4b3b8b690aede58c2e3
Author: Yulei-Yang <[email protected]>
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 6060a64dc4..335f76c95e 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
@@ -31,6 +31,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 419bf71f24..7741febfb7 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
@@ -68,6 +68,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")
@@ -295,6 +297,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 {
@@ -317,6 +323,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 183487ee99..0e672f8cba 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
@@ -2167,7 +2167,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()));
}
@@ -2309,7 +2309,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());
}
private void handleShowAnalyze() throws AnalysisException {
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 feec7f8d29..0f83664f96 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
@@ -32,14 +32,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 647d5ee690..1ff736a555 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
@@ -283,6 +283,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());
@@ -291,6 +297,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: [email protected]
For additional commands, e-mail: [email protected]