This is an automated email from the ASF dual-hosted git repository.
starocean999 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 6627d56d986 [Enhancement] (nereids)implement showPartitionIdCommand in
nereids (#43133)
6627d56d986 is described below
commit 6627d56d98641a43bb30b44b7fd753b269a2220a
Author: Vallish Pai <[email protected]>
AuthorDate: Mon Nov 18 14:32:29 2024 +0530
[Enhancement] (nereids)implement showPartitionIdCommand in nereids (#43133)
Issue Number: close #42756
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 11 ++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../plans/commands/ShowPartitionIdCommand.java | 120 +++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 +
.../show/test_nereids_showpartitionid.groovy | 58 ++++++++++
6 files changed, 196 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index b816b312194..e6623b2c51a 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -204,6 +204,7 @@ supportedShowStatement
((FROM | IN) database=identifier)?
#showView
| SHOW REPOSITORIES
#showRepositories
| SHOW ROLES
#showRoles
+ | SHOW PARTITION partitionId=INTEGER_VALUE
#showPartitionId
| SHOW PROC path=STRING_LITERAL
#showProc
| SHOW STORAGE? ENGINES
#showStorageEngines
| SHOW CREATE MATERIALIZED VIEW mvName=identifier
@@ -292,7 +293,6 @@ unsupportedShowStatement
| SHOW DATA (FROM tableName=multipartIdentifier)? sortClause?
propertyClause? #showData
| SHOW TEMPORARY? PARTITIONS FROM tableName=multipartIdentifier
wildWhere? sortClause? limitClause?
#showPartitions
- | SHOW PARTITION partitionId=INTEGER_VALUE
#showPartitionId
| SHOW TABLET tabletId=INTEGER_VALUE
#showTabletId
| SHOW TABLETS BELONG
tabletIds+=INTEGER_VALUE (COMMA tabletIds+=INTEGER_VALUE)*
#showTabletBelong
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 59ae207a696..cc44e69ae27 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -203,6 +203,7 @@ import
org.apache.doris.nereids.DorisParser.ShowCreateMaterializedViewContext;
import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext;
import org.apache.doris.nereids.DorisParser.ShowFrontendsContext;
import org.apache.doris.nereids.DorisParser.ShowLastInsertContext;
+import org.apache.doris.nereids.DorisParser.ShowPartitionIdContext;
import org.apache.doris.nereids.DorisParser.ShowProcContext;
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
@@ -446,6 +447,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewC
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowLastInsertCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowPartitionIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
@@ -4046,6 +4048,15 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new ShowLastInsertCommand();
}
+ @Override
+ public LogicalPlan visitShowPartitionId(ShowPartitionIdContext ctx) {
+ long partitionId = -1;
+ if (ctx.partitionId != null) {
+ partitionId = Long.parseLong(ctx.partitionId.getText());
+ }
+ return new ShowPartitionIdCommand(partitionId);
+ }
+
@Override
public LogicalPlan visitShowVariables(ShowVariablesContext ctx) {
SetType type = SetType.DEFAULT;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index 768ef8ca723..ee178d9873d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -181,6 +181,7 @@ public enum PlanType {
SHOW_CREATE_MATERIALIZED_VIEW_COMMAND,
SHOW_FRONTENDS_COMMAND,
SHOW_LAST_INSERT_COMMAND,
+ SHOW_PARTITIONID_COMMAND,
SHOW_PROC_COMMAND,
SHOW_REPOSITORIES_COMMAND,
SHOW_ROLE_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java
new file mode 100644
index 00000000000..fb7e5cdf968
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java
@@ -0,0 +1,120 @@
+// 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.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.ShowResultSetMetaData;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * show partition command
+ */
+public class ShowPartitionIdCommand extends ShowCommand {
+ public static final Logger LOG =
LogManager.getLogger(ShowPartitionIdCommand.class);
+ private final long partitionId;
+
+ /**
+ * constructor
+ */
+ public ShowPartitionIdCommand(long partitionId) {
+ super(PlanType.SHOW_PARTITIONID_COMMAND);
+ this.partitionId = partitionId;
+ }
+
+ /**
+ * get meta for show partionId
+ */
+ public ShowResultSetMetaData getMetaData() {
+ ShowResultSetMetaData.Builder builder =
ShowResultSetMetaData.builder();
+ builder.addColumn(new Column("DbName", ScalarType.createVarchar(30)));
+ builder.addColumn(new Column("TableName",
ScalarType.createVarchar(30)));
+ builder.addColumn(new Column("PartitionName",
ScalarType.createVarchar(30)));
+ builder.addColumn(new Column("DbId", ScalarType.createVarchar(30)));
+ builder.addColumn(new Column("TableId", ScalarType.createVarchar(30)));
+ return builder.build();
+ }
+
+ private ShowResultSet handleShowPartitionId(ConnectContext ctx,
StmtExecutor executor) throws Exception {
+ List<List<String>> rows = Lists.newArrayList();
+ Env env = ctx.getEnv();
+ List<Long> dbIds = env.getInternalCatalog().getDbIds();
+ for (long dbId : dbIds) {
+ Database database = env.getInternalCatalog().getDbNullable(dbId);
+ if (database == null) {
+ continue;
+ }
+ List<Table> tables = database.getTables();
+ for (Table tbl : tables) {
+ if (tbl instanceof OlapTable) {
+ tbl.readLock();
+ try {
+ 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);
+ break;
+ }
+ } finally {
+ tbl.readUnlock();
+ }
+ }
+ }
+ }
+ ShowResultSet resultSet = new ShowResultSet(getMetaData(), rows);
+ return resultSet;
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ // check access first
+ if
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.ADMIN)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
"SHOW PARTITION");
+ }
+ return handleShowPartitionId(ctx, executor);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowPartitionIdCommand(this, context);
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index 3b5ee877e8b..5ecaf96f4d1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -59,6 +59,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewC
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowLastInsertCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowPartitionIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
@@ -255,6 +256,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(showLastInsertCommand, context);
}
+ default R visitShowPartitionIdCommand(ShowPartitionIdCommand
showPartitionIdCommand, C context) {
+ return visitCommand(showPartitionIdCommand, context);
+ }
+
default R visitShowVariablesCommand(ShowVariablesCommand
showVariablesCommand, C context) {
return visitCommand(showVariablesCommand, context);
}
diff --git
a/regression-test/suites/nereids_p0/show/test_nereids_showpartitionid.groovy
b/regression-test/suites/nereids_p0/show/test_nereids_showpartitionid.groovy
new file mode 100644
index 00000000000..23b90ebf1b5
--- /dev/null
+++ b/regression-test/suites/nereids_p0/show/test_nereids_showpartitionid.groovy
@@ -0,0 +1,58 @@
+// 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.
+
+
+suite("test_nereids_showpartitionid") {
+ def table = "test_nereids_showpartitionid"
+ // create table and insert data
+ sql """ drop table if exists ${table} force"""
+ sql """
+ create table ${table} (
+ `id` int(11),
+ `name` varchar(128),
+ `da` date
+ )
+ engine=olap
+ duplicate key(id)
+ partition by range(da)(
+ PARTITION p3 VALUES LESS THAN ('2023-01-01'),
+ PARTITION p4 VALUES LESS THAN ('2024-01-01'),
+ PARTITION p5 VALUES LESS THAN ('2025-01-01')
+ )
+ distributed by hash(id) buckets 2
+ properties(
+ "replication_num"="1",
+ "light_schema_change"="true"
+ );
+ """
+
+ def result = sql_return_maparray "show partitions from ${table}"
+ logger.info("${result}")
+ def partitionId;
+ for (def partition : result) {
+ //get any partition ID.
+ partitionId = partition.PartitionId;
+ break;
+ }
+
+ checkNereidsExecute("show partition ${partitionId}")
+ def result1 = sql "show partition ${partitionId}";
+ logger.info("${result1}");
+
+
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]