morningman commented on a change in pull request #5807:
URL: https://github.com/apache/incubator-doris/pull/5807#discussion_r634124073
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,67 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
Review comment:
```suggestion
for (long dbId : dbIds) {
```
format
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,67 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ Table table = database.getTable(tableId);
Review comment:
database maybe null here, cause this is not an atomic operation
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,67 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ Table table = database.getTable(tableId);
+ if (table != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(table.getName());
+ row.add(String.valueOf(database.getId()));
+ rows.add(row);
Review comment:
I think we should break here, cause each table has a unique id.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,67 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ Table table = database.getTable(tableId);
+ if (table != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(table.getName());
+ row.add(String.valueOf(database.getId()));
+ rows.add(row);
+ }
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowPartitionId() throws AnalysisException {
+ ShowPartitionIdStmt showStmt = (ShowPartitionIdStmt) stmt;
+ long partitionId = showStmt.getPartitionId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ List<Table> tables = database.getTables();
+ for (Table tbl:tables) {
Review comment:
```suggestion
for (Table tbl : tables) {
```
format
And we need tbl's readlock here.
##########
File path:
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionIdStmt.java
##########
@@ -0,0 +1,74 @@
+// 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 TABLES
Review comment:
comment
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,67 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ Table table = database.getTable(tableId);
+ if (table != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(table.getName());
+ row.add(String.valueOf(database.getId()));
+ rows.add(row);
+ }
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowPartitionId() throws AnalysisException {
+ ShowPartitionIdStmt showStmt = (ShowPartitionIdStmt) stmt;
+ long partitionId = showStmt.getPartitionId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId:dbIds) {
+ Database database = catalog.getDb(dbId);
+ List<Table> tables = database.getTables();
+ for (Table tbl:tables) {
+ if (tbl instanceof OlapTable) {
+ Partition partition = ((OlapTable)
tbl).getPartition(partitionId);
+ if (partition != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(tbl.getName());
+ row.add(partition.getName());
+ row.add(String.valueOf(database.getId()));
+ row.add(String.valueOf(tbl.getId()));
+ rows.add(row);
Review comment:
break out the very outside loop.
##########
File path:
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTableIdStmt.java
##########
@@ -0,0 +1,88 @@
+// 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 com.google.common.base.Strings;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.cluster.ClusterNamespace;
+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 TABLES
+public class ShowTableIdStmt extends ShowStmt {
+ private String db;
+ private long tableId;
+
+ public ShowTableIdStmt(String db, long tableId) {
+ this.db = db;
+ this.tableId = tableId;
+ }
+
+ public String getDb() {
+ return db;
+ }
+
+ public long getTableId() {
+ return tableId;
+ }
+
+ @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 TABLE");
+ }
+ if (Strings.isNullOrEmpty(db)) {
+ db = analyzer.getDefaultDb();
Review comment:
Do we need to check db here?
I think the purpose of this stmt is to find out which database is this table
belongs to.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDbIdStmt.java
##########
@@ -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 TABLES
Review comment:
comment is wrong
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]