This is an automated email from the ASF dual-hosted git repository.
lide pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
new 94cb49caa14 [Improvement](cmd) add show-tablets-belong stmt for
analyzing a batch of tablet-ids (#28165)
94cb49caa14 is described below
commit 94cb49caa1458226d85c824bb32010a2c29d424c
Author: Yulei-Yang <[email protected]>
AuthorDate: Fri Dec 8 11:41:23 2023 +0800
[Improvement](cmd) add show-tablets-belong stmt for analyzing a batch of
tablet-ids (#28165)
---
.../Show-Statements/SHOW-TABLETS-BELONG.md | 74 +++++++++++++++++
docs/sidebars.json | 1 +
.../Show-Statements/SHOW-TABLETS-BELONG.md | 74 +++++++++++++++++
fe/fe-core/src/main/cup/sql_parser.cup | 5 ++
.../doris/analysis/ShowTabletsBelongStmt.java | 94 ++++++++++++++++++++++
.../java/org/apache/doris/qe/ShowExecutor.java | 68 ++++++++++++++++
fe/fe-core/src/main/jflex/sql_scanner.flex | 1 +
7 files changed, 317 insertions(+)
diff --git
a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
new file mode 100644
index 00000000000..9321c90ff51
--- /dev/null
+++
b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
@@ -0,0 +1,74 @@
+---
+{
+ "title": "SHOW-TABLETS-BELONG",
+ "language": "en"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<version since="dev">
+
+## SHOW-TABLETS-BELONG
+
+</version>
+
+### Name
+
+SHOW TABLETS BELONG
+
+### Description
+
+Used to show tablets and information of their belonging table
+
+grammar:
+
+```sql
+SHOW TABLETS BELONG tablet-ids;
+```
+
+illustrate:
+
+1. tablet-ids:one or more tablet-ids, with comma separated
+2. Columns of result keep same with result of `SHOW-DATA` for the same table
+
+### Example
+
+1. show information of four tablet-ids (actually, three tablet-ids. Result
will be deduplicated)
+
+ ```sql
+ SHOW TABLETS BELONG 27028,78880,78382,27028;
+ ```
+
+ ```
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+| DbName | TableName | TableSize | PartitionNum | BucketNum |
ReplicaCount | TabletIds |
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+| default_cluster:db1 | kec | 613.000 B | 379 | 604 | 604
| [78880, 78382] |
+| default_cluster:db1 | test | 1.874 KB | 1 | 1 | 1
| [27028] |
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+ ```
+
+### Keywords
+
+ SHOW, TABLETS, BELONG
+
+### Best Practice
+
diff --git a/docs/sidebars.json b/docs/sidebars.json
index db81bf5e1c1..6f9552deb76 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -945,6 +945,7 @@
"sql-manual/sql-reference/Show-Statements/SHOW-WHITE-LIST",
"sql-manual/sql-reference/Show-Statements/SHOW-WARNING",
"sql-manual/sql-reference/Show-Statements/SHOW-TABLET",
+
"sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG",
"sql-manual/sql-reference/Show-Statements/SHOW-VARIABLES",
"sql-manual/sql-reference/Show-Statements/SHOW-PLUGINS",
"sql-manual/sql-reference/Show-Statements/SHOW-ROLES",
diff --git
a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
new file mode 100644
index 00000000000..49265963468
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
@@ -0,0 +1,74 @@
+---
+{
+ "title": "SHOW-TABLETS-BELONG",
+ "language": "zh-CN"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<version since="dev">
+
+## SHOW-TABLETS-BELONG
+
+</version>
+
+### Name
+
+SHOW TABLETS BELONG
+
+### Description
+
+该语句用于展示指定Tablets归属的表的信息
+
+语法:
+
+```sql
+SHOW TABLETS BELONG tablet-ids;
+```
+
+说明:
+
+1. tablet-ids:代表一到多个tablet-id构成的列表。如有多个,使用逗号分隔
+2. 结果中 table 相关的信息和 `SHOW-DATA` 语句的口径一致
+
+### Example
+
+1. 展示3个tablet-id的相关信息(tablet-id可去重)
+
+ ```sql
+ SHOW TABLETS BELONG 27028,78880,78382,27028;
+ ```
+
+ ```
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+| DbName | TableName | TableSize | PartitionNum | BucketNum |
ReplicaCount | TabletIds |
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+| default_cluster:db1 | kec | 613.000 B | 379 | 604 | 604
| [78880, 78382] |
+| default_cluster:db1 | test | 1.874 KB | 1 | 1 | 1
| [27028] |
++---------------------+-----------+-----------+--------------+-----------+--------------+----------------+
+ ```
+
+### Keywords
+
+ SHOW, TABLETS, BELONG
+
+### Best Practice
+
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index dcf6fd394ab..bee869915a2 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -262,6 +262,7 @@ terminal String
KW_BACKENDS,
KW_BACKUP,
KW_BEGIN,
+ KW_BELONG,
KW_BETWEEN,
KW_BIGINT,
KW_BIN,
@@ -3602,6 +3603,10 @@ show_param ::=
{:
RESULT = new ShowTabletStmt(null, tabletId);
:}
+ | KW_TABLETS KW_BELONG integer_list:tabletIds
+ {:
+ RESULT = new ShowTabletsBelongStmt(tabletIds);
+ :}
| KW_TABLETS KW_FROM table_name:dbTblName
opt_partition_names:partitionNames opt_wild_where order_by_clause:orderByClause
limit_clause:limitClause
{:
RESULT = new ShowTabletStmt(dbTblName, -1L, partitionNames,
parser.where, orderByClause, limitClause);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTabletsBelongStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTabletsBelongStmt.java
new file mode 100644
index 00000000000..b321dace7f5
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTabletsBelongStmt.java
@@ -0,0 +1,94 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.UserException;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ShowTabletsBelongStmt is used to show information of tables which tablets
are belonged to
+ * syntax:
+ * SHOW TABLETS BELONG tablet_ids
+ */
+public class ShowTabletsBelongStmt extends ShowStmt {
+ private List<Long> tabletIds;
+
+ private static final ImmutableList<String> TITLE_NAMES = new
ImmutableList.Builder<String>()
+ .add("DbName")
+ .add("TableName")
+ .add("TableSize")
+ .add("PartitionNum")
+ .add("BucketNum")
+ .add("ReplicaCount")
+ .add("TabletIds")
+ .build();
+
+ public ShowTabletsBelongStmt(List<Long> tabletIds) {
+ this.tabletIds = tabletIds;
+ }
+
+ public List<Long> getTabletIds() {
+ return tabletIds;
+ }
+
+ @Override
+ public void analyze(Analyzer analyzer) throws UserException {
+ if (tabletIds == null || tabletIds.isEmpty()) {
+ throw new UserException("Please supply at least one tablet id");
+ }
+ }
+
+ @Override
+ public ShowResultSetMetaData getMetaData() {
+ ShowResultSetMetaData.Builder builder =
ShowResultSetMetaData.builder();
+ for (String title : TITLE_NAMES) {
+ builder.addColumn(new Column(title,
ScalarType.createVarchar(128)));
+ }
+ return builder.build();
+ }
+
+ @Override
+ public RedirectStatus getRedirectStatus() {
+ return RedirectStatus.FORWARD_NO_SYNC;
+ }
+
+ @Override
+ public String toSql() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("SHOW TABLETS BELONG ");
+
+ for (long tabletId : tabletIds) {
+ sb.append(tabletId);
+ sb.append(", ");
+ }
+
+ String tmp = sb.toString();
+ return tmp.substring(tmp.length() - 1);
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+}
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 f2534080789..12220a33177 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
@@ -90,6 +90,7 @@ import org.apache.doris.analysis.ShowTableStatsStmt;
import org.apache.doris.analysis.ShowTableStatusStmt;
import org.apache.doris.analysis.ShowTableStmt;
import org.apache.doris.analysis.ShowTabletStmt;
+import org.apache.doris.analysis.ShowTabletsBelongStmt;
import org.apache.doris.analysis.ShowTransactionStmt;
import org.apache.doris.analysis.ShowTrashDiskStmt;
import org.apache.doris.analysis.ShowTrashStmt;
@@ -156,6 +157,7 @@ import org.apache.doris.common.proc.TrashProcDir;
import org.apache.doris.common.proc.TrashProcNode;
import org.apache.doris.common.profile.ProfileTreeNode;
import org.apache.doris.common.profile.ProfileTreePrinter;
+import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.common.util.ListComparator;
import org.apache.doris.common.util.LogBuilder;
import org.apache.doris.common.util.LogKey;
@@ -215,8 +217,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
@@ -384,6 +388,8 @@ public class ShowExecutor {
handleShowCreateCatalog();
} else if (stmt instanceof ShowAnalyzeStmt) {
handleShowAnalyze();
+ } else if (stmt instanceof ShowTabletsBelongStmt) {
+ handleShowTabletsBelong();
} else if (stmt instanceof AdminCopyTabletStmt) {
handleCopyTablet();
} else if (stmt instanceof ShowCatalogRecycleBinStmt) {
@@ -2343,6 +2349,68 @@ public class ShowExecutor {
resultSet = new ShowResultSet(showStmt.getMetaData(), results);
}
+ private void handleShowTabletsBelong() {
+ ShowTabletsBelongStmt showStmt = (ShowTabletsBelongStmt) stmt;
+ List<List<String>> rows = new ArrayList<>();
+
+ Env env = Env.getCurrentEnv();
+
+ TabletInvertedIndex invertedIndex = Env.getCurrentInvertedIndex();
+ Map<String, HashSet<Long>> tableToTabletIdsMap = new HashMap<>();
+ for (long tabletId : showStmt.getTabletIds()) {
+ TabletMeta tabletMeta = invertedIndex.getTabletMeta(tabletId);
+ if (tabletMeta == null) {
+ continue;
+ }
+ long dbId = tabletMeta.getDbId();
+ Database db = env.getInternalCatalog().getDbNullable(dbId);
+ if (db == null) {
+ continue;
+ }
+ long tableId = tabletMeta.getTableId();
+ Table table = db.getTableNullable(tableId);
+ if (table == null) {
+ continue;
+ }
+
+ String idString = String.format("%d_%d", dbId, tableId);
+ if (!tableToTabletIdsMap.containsKey(idString)) {
+ tableToTabletIdsMap.put(idString, new HashSet<>());
+ }
+ tableToTabletIdsMap.get(idString).add(tabletId);
+ }
+
+ for (String idString : tableToTabletIdsMap.keySet()) {
+ long dbId = new Long(idString.split("_")[0]).longValue();
+ long tableId = new Long(idString.split("_")[1]).longValue();
+ Database db = Env.getCurrentInternalCatalog().getDbNullable(dbId);
+ OlapTable table = (OlapTable) db.getTableNullable(tableId);
+
+ List<String> line = new ArrayList<>();
+ line.add(db.getFullName());
+ line.add(table.getName());
+
+ OlapTable olapTable = (OlapTable) table;
+ Pair<Double, String> tableSizePair = DebugUtil.getByteUint((long)
olapTable.getDataSize());
+ String readableSize =
DebugUtil.DECIMAL_FORMAT_SCALE_3.format(tableSizePair.first) + " "
+ + tableSizePair.second;
+ line.add(readableSize);
+ line.add(new Long(olapTable.getPartitionKeys().size()).toString());
+ int totalBucketNum = 0;
+ Set<String> partitionNamesSet = table.getPartitionNames();
+ for (String partitionName : partitionNamesSet) {
+ totalBucketNum +=
table.getPartition(partitionName).getDistributionInfo().getBucketNum();
+ }
+ line.add(new Long(totalBucketNum).toString());
+ line.add(new Long(olapTable.getReplicaCount()).toString());
+ line.add(tableToTabletIdsMap.get(idString).toString());
+
+ rows.add(line);
+ }
+
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
private void handleCopyTablet() throws AnalysisException {
AdminCopyTabletStmt copyStmt = (AdminCopyTabletStmt) stmt;
long tabletId = copyStmt.getTabletId();
diff --git a/fe/fe-core/src/main/jflex/sql_scanner.flex
b/fe/fe-core/src/main/jflex/sql_scanner.flex
index 52dcdd5e8d0..98667c31a86 100644
--- a/fe/fe-core/src/main/jflex/sql_scanner.flex
+++ b/fe/fe-core/src/main/jflex/sql_scanner.flex
@@ -113,6 +113,7 @@ import org.apache.doris.qe.SqlModeHelper;
keywordMap.put("backends", new Integer(SqlParserSymbols.KW_BACKENDS));
keywordMap.put("backup", new Integer(SqlParserSymbols.KW_BACKUP));
keywordMap.put("begin", new Integer(SqlParserSymbols.KW_BEGIN));
+ keywordMap.put("belong", new Integer(SqlParserSymbols.KW_BELONG));
keywordMap.put("between", new Integer(SqlParserSymbols.KW_BETWEEN));
keywordMap.put("bigint", new Integer(SqlParserSymbols.KW_BIGINT));
keywordMap.put("bin", new Integer(SqlParserSymbols.KW_BIN));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]