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.
[Command] [SQL] Add show database/table/partition id command (apache#…
…5807) In BE, when a problem happened, in the log, we can find the database id, table id, partition id, but no database name, table name, partition name. In FE, there also no way to find database name/table name/partition name accourding to database id/table id/partition id. Therefore, this patch add 3 new commands: 1. show database id; mysql> show database 10002; +----------------------+ | DbName | +----------------------+ | default_cluster:test | +----------------------+ 2. show table id; mysql> show table 11100; +----------------------+-----------+-------+ | DbName | TableName | DbId | +----------------------+-----------+-------+ | default_cluster:test | table2 | 10002 | +----------------------+-----------+-------+ 3. show partition id; mysql> show partition 11099; +----------------------+-----------+---------------+-------+---------+ | DbName | TableName | PartitionName | DbId | TableId | +----------------------+-----------+---------------+-------+---------+ | default_cluster:test | table2 | p201708 | 10002 | 11100 | +----------------------+-----------+---------------+-------+---------+
- Loading branch information
1 parent
a55b12d
commit ba69f7a
Showing
14 changed files
with
708 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
docs/en/sql-reference/sql-statements/Data Manipulation/SHOW DATABASE.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,38 @@ | ||
--- | ||
{ | ||
"title": "SHOW DATABASE", | ||
"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. | ||
--> | ||
|
||
# SHOW DATABASE | ||
## Description | ||
This statement is used to display database name according to database id (for administrators only) | ||
Grammar: | ||
SHOW DATABASE [database_id] | ||
|
||
## example | ||
1. Display database name according to database id | ||
SHOW DATABASE 1001; | ||
|
||
## keyword | ||
SHOW,DATABASE |
38 changes: 38 additions & 0 deletions
38
docs/en/sql-reference/sql-statements/Data Manipulation/SHOW PARTITION.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,38 @@ | ||
--- | ||
{ | ||
"title": "SHOW PARTITION", | ||
"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. | ||
--> | ||
|
||
# SHOW PARTITION | ||
## Description | ||
This statement is used to display database name, table name, partition name according to partition id (for administrators only) | ||
Grammar: | ||
SHOW PARTITION [partition_id] | ||
|
||
## example | ||
1. Display database name, table name, partition name according to partition id | ||
SHOW PARTITION 10002; | ||
|
||
## keyword | ||
SHOW,PARTITION |
38 changes: 38 additions & 0 deletions
38
docs/en/sql-reference/sql-statements/Data Manipulation/SHOW TABLE.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,38 @@ | ||
--- | ||
{ | ||
"title": "SHOW TABLE", | ||
"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. | ||
--> | ||
|
||
# SHOW TABLE | ||
## Description | ||
This statement is used to display database name, table name according to table id (for administrators only) | ||
Grammar: | ||
SHOW TABLE [table_id] | ||
|
||
## example | ||
1. Display database name, table name according to table id | ||
SHOW TABLE 10001; | ||
|
||
## keyword | ||
SHOW,TABLE |
39 changes: 39 additions & 0 deletions
39
docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW DATABASE.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,39 @@ | ||
--- | ||
{ | ||
"title": "SHOW DATABASE", | ||
"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. | ||
--> | ||
|
||
# SHOW DATABASE | ||
## description | ||
该语句用于根据 database id 查找对应的 database name(仅管理员使用) | ||
语法: | ||
SHOW DATABASE [database_id] | ||
|
||
## example | ||
1. 根据 database id 查找对应的 database name | ||
SHOW DATABASE 1001; | ||
|
||
## keyword | ||
SHOW,DATABASE | ||
|
39 changes: 39 additions & 0 deletions
39
docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW PARTITION.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,39 @@ | ||
--- | ||
{ | ||
"title": "SHOW PARTITION", | ||
"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. | ||
--> | ||
|
||
# SHOW DATABASE | ||
## description | ||
该语句用于根据 partition id 查找对应的 database name, table name, partition name(仅管理员使用) | ||
语法: | ||
SHOW PARTITION [partition_id] | ||
|
||
## example | ||
1. 根据 partition id 查找对应的 database name, table name, partition name | ||
SHOW PARTITION 10002; | ||
|
||
## keyword | ||
SHOW,PARTITION | ||
|
39 changes: 39 additions & 0 deletions
39
docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW TABLE.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,39 @@ | ||
--- | ||
{ | ||
"title": "SHOW TABLE", | ||
"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. | ||
--> | ||
|
||
# SHOW DATABASE | ||
## description | ||
该语句用于根据 table id 查找对应的 database name, table name(仅管理员使用) | ||
语法: | ||
SHOW TABLE [table_id] | ||
|
||
## example | ||
1. 根据 table id 查找对应的 database name, table name | ||
SHOW TABLE 10001; | ||
|
||
## keyword | ||
SHOW,TABLE | ||
|
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
70 changes: 70 additions & 0 deletions
70
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDbIdStmt.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,70 @@ | ||
// 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.Catalog; | ||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.catalog.ScalarType; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.ShowResultSetMetaData; | ||
|
||
// SHOW DATABASE ID | ||
public class ShowDbIdStmt extends ShowStmt { | ||
private long dbId; | ||
|
||
public ShowDbIdStmt(long dbId) { | ||
this.dbId = dbId; | ||
} | ||
|
||
public long getDbId() { | ||
return dbId; | ||
} | ||
|
||
@Override | ||
public void analyze(Analyzer analyzer) throws AnalysisException { | ||
// check access first | ||
if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "SHOW DATABASE"); | ||
} | ||
} | ||
|
||
@Override | ||
public String toSql() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("SHOW"); | ||
sb.append(" DATABASE "); | ||
sb.append(this.dbId); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toSql(); | ||
} | ||
|
||
@Override | ||
public ShowResultSetMetaData getMetaData() { | ||
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder(); | ||
builder.addColumn(new Column("DbName", ScalarType.createVarchar(30))); | ||
return builder.build(); | ||
} | ||
} |
Oops, something went wrong.