forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature](analyze_cmd) add show-tablets-belong stmt for analyzing a b…
…atch of tablet-ids (apache#27994)
- Loading branch information
1 parent
e148d46
commit 255bac9
Showing
7 changed files
with
312 additions
and
1 deletion.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-TABLETS-BELONG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTabletsBelongStmt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters