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 c096c2de45d [Enhancement](nereids)support admin set partition version 
(#53079)
c096c2de45d is described below

commit c096c2de45d4e310dc28db0e9677e634bf11e1cc
Author: lsy3993 <[email protected]>
AuthorDate: Mon Jul 14 09:45:25 2025 +0800

    [Enhancement](nereids)support admin set partition version (#53079)
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |   8 +-
 .../main/java/org/apache/doris/catalog/Env.java    |  13 +++
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  12 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |   1 +
 .../commands/AdminSetPartitionVersionCommand.java  | 102 +++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |   5 +
 .../AdminSetPartitionVersionCommandTest.java       |  59 ++++++++++++
 ...test_nereids_admin_set_partition_version.groovy |  47 ++++++++++
 8 files changed, 241 insertions(+), 6 deletions(-)

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 b942728d8f9..8f9654fbf0b 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
@@ -74,7 +74,6 @@ statementBase
 
 unsupportedStatement
     : unsupportedStatsStatement
-    | unsupportedAdminStatement
     | unsupportedLoadStatement
     ;
 
@@ -588,6 +587,8 @@ supportedAdminStatement
     | ADMIN REPAIR TABLE baseTableRef                                          
     #adminRepairTable
     | ADMIN CANCEL REPAIR TABLE baseTableRef                                   
     #adminCancelRepairTable
     | ADMIN COPY TABLET tabletId=INTEGER_VALUE properties=propertyClause?      
     #adminCopyTablet
+    | ADMIN SET TABLE name=multipartIdentifier
+        PARTITION VERSION properties=propertyClause?                           
     #adminSetPartitionVersion
     ;
 
 supportedRecoverStatement
@@ -598,11 +599,6 @@ supportedRecoverStatement
         FROM tableName=multipartIdentifier                                     
     #recoverPartition
     ;
 
-unsupportedAdminStatement
-    : ADMIN SET TABLE name=multipartIdentifier
-        PARTITION VERSION properties=propertyClause?                           
     #adminSetPartitionVersion
-    ;
-
 baseTableRef
     : multipartIdentifier optScanParams? tableSnapshot? specifiedPartition?
         tabletList? tableAlias sample? relationHint?
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 52b45f58396..849872a15e4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -188,6 +188,7 @@ import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.nereids.jobs.load.LabelProcessor;
 import org.apache.doris.nereids.stats.HboPlanStatisticsManager;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetFrontendConfigCommand;
+import 
org.apache.doris.nereids.trees.plans.commands.AdminSetPartitionVersionCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaVersionCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterSystemCommand;
@@ -6236,6 +6237,18 @@ public class Env {
         }
     }
 
+    public void setPartitionVersion(AdminSetPartitionVersionCommand command) 
throws Exception {
+        String database = command.getDatabase();
+        String table = command.getTable();
+        long partitionId = command.getPartitionId();
+        long visibleVersion = command.getVisibleVersion();
+        int setSuccess = setPartitionVersionInternal(database, table, 
partitionId, visibleVersion, false);
+        if (setSuccess == -1) {
+            throw new DdlException("Failed to set partition visible version to 
" + visibleVersion + ". " + "Partition "
+                    + partitionId + " not exists. Database " + database + ", 
Table " + table + ".");
+        }
+    }
+
     public void replayBackendReplicasInfo(BackendReplicasInfo 
backendReplicasInfo) {
         long backendId = backendReplicasInfo.getBackendId();
         List<BackendReplicasInfo.ReplicaReportInfo> replicaInfos = 
backendReplicasInfo.getReplicaReportInfos();
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 cbcd8a21cb5..380dbb35ded 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
@@ -583,6 +583,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AdminCopyTabletCommand;
 import org.apache.doris.nereids.trees.plans.commands.AdminRebalanceDiskCommand;
 import org.apache.doris.nereids.trees.plans.commands.AdminRepairTableCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetFrontendConfigCommand;
+import 
org.apache.doris.nereids.trees.plans.commands.AdminSetPartitionVersionCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaVersionCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
@@ -6025,6 +6026,17 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
             applyToAll);
     }
 
+    @Override
+    public LogicalPlan 
visitAdminSetPartitionVersion(DorisParser.AdminSetPartitionVersionContext ctx) {
+        List<String> parts = visitMultipartIdentifier(ctx.name);
+        TableNameInfo info = new TableNameInfo(parts);
+        Map<String, String> properties = ctx.properties != null
+                ? Maps.newHashMap(visitPropertyClause(ctx.properties))
+                : Maps.newHashMap();
+
+        return new AdminSetPartitionVersionCommand(info, properties);
+    }
+
     @Override
     public LogicalPlan visitShowFrontends(ShowFrontendsContext ctx) {
         String detail = (ctx.name != null) ? ctx.name.getText() : null;
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 54d6e60b6a0..8fb6adfa741 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
@@ -236,6 +236,7 @@ public enum PlanType {
     DROP_WORKLOAD_GROUP_NAME,
     DROP_WORKLOAD_POLICY_COMMAND,
     ADMIN_SET_TABLE_STATUS_COMMAND,
+    ADMIN_SET_PARTITION_VERSION_COMMAND,
     ALTER_CATALOG_COMMENT_COMMAND,
     ALTER_SQL_BLOCK_RULE_COMMAND,
     ALTER_REPOSITORY_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommand.java
new file mode 100644
index 00000000000..972894d7bf9
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommand.java
@@ -0,0 +1,102 @@
+// 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.Env;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.util.PropertyAnalyzer;
+import org.apache.doris.common.util.Util;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+import java.util.Map;
+
+/**
+ * admin set partition version ("key" = "value");
+ * key and value may be : "partition_id" = "10075", "visible_version" = "100");
+ */
+public class AdminSetPartitionVersionCommand extends Command implements 
ForwardWithSync {
+    private long partitionId = -1;
+    private long visibleVersion = -1;
+    private final TableNameInfo tableName;
+    private final Map<String, String> properties;
+
+    /**
+     * constructor of AdminSetPartitionVersionCommand
+     */
+    public AdminSetPartitionVersionCommand(TableNameInfo tableName, 
Map<String, String> properties) {
+        super(PlanType.ADMIN_SET_PARTITION_VERSION_COMMAND);
+        this.tableName = tableName;
+        this.properties = properties;
+    }
+
+    public String getDatabase() {
+        return tableName.getDb();
+    }
+
+    public String getTable() {
+        return tableName.getTbl();
+    }
+
+    public Long getPartitionId() {
+        return partitionId;
+    }
+
+    public Long getVisibleVersion() {
+        return visibleVersion;
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        // check auth
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+
+        tableName.analyze(ctx);
+        Util.prohibitExternalCatalog(tableName.getCtl(), 
this.getClass().getSimpleName());
+
+        checkProperties();
+        Env.getCurrentEnv().setPartitionVersion(this);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitAdminSetPartitionVersionCommand(this, context);
+    }
+
+    private void checkProperties() throws AnalysisException {
+        partitionId = PropertyAnalyzer.analyzePartitionId(properties);
+        if (partitionId == -1) {
+            throw new AnalysisException("Should specify 'partition_id' 
property.");
+        }
+        visibleVersion = PropertyAnalyzer.analyzeVisibleVersion(properties);
+        if (visibleVersion == -1) {
+            throw new AnalysisException("Should specify 'visible_version' 
property.");
+        }
+        if (properties != null && !properties.isEmpty()) {
+            throw new AnalysisException("Unknown properties: " + 
properties.keySet());
+        }
+    }
+}
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 eb8e3738bbb..b748962a890 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
@@ -27,6 +27,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AdminCopyTabletCommand;
 import org.apache.doris.nereids.trees.plans.commands.AdminRebalanceDiskCommand;
 import org.apache.doris.nereids.trees.plans.commands.AdminRepairTableCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetFrontendConfigCommand;
+import 
org.apache.doris.nereids.trees.plans.commands.AdminSetPartitionVersionCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetReplicaVersionCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
@@ -1328,6 +1329,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(command, context);
     }
 
+    default R 
visitAdminSetPartitionVersionCommand(AdminSetPartitionVersionCommand command, C 
context) {
+        return visitCommand(command, context);
+    }
+
     default R visitRevokeRoleCommand(RevokeRoleCommand revokeRoleCommand, C 
context) {
         return visitCommand(revokeRoleCommand, context);
     }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommandTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommandTest.java
new file mode 100644
index 00000000000..6e566745f80
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommandTest.java
@@ -0,0 +1,59 @@
+// 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.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AdminSetPartitionVersionCommandTest extends TestWithFeService {
+    @Test
+    public void testNormal() throws Exception {
+        // test logical plan
+        String sql = "ADMIN SET TABLE __internal_schema.audit_log PARTITION 
VERSION PROPERTIES(\"partition_id\" = \"10075\", \"visible_version\" = 
\"100\");";
+        LogicalPlan plan = new NereidsParser().parseSingle(sql);
+        Assertions.assertTrue(plan instanceof AdminSetPartitionVersionCommand);
+
+        // test object
+        TableNameInfo tableInfo = new TableNameInfo("internal", "test", "t1");
+        Map<String, String> properties = new HashMap<>();
+        properties.put("partition_id", "10086");
+        properties.put("visible_version", "100");
+        AdminSetPartitionVersionCommand command = new 
AdminSetPartitionVersionCommand(tableInfo, properties);
+        Assertions.assertThrows(DdlException.class, () -> 
command.run(connectContext, null));
+    }
+
+    @Test
+    public void testEmptyConfig() {
+        String sql = "ADMIN SET TABLE test.t1 PARTITION VERSION 
PROPERTIES(\"a\" = \"b\")";
+        LogicalPlan plan = new NereidsParser().parseSingle(sql);
+        Assertions.assertTrue(plan instanceof AdminSetPartitionVersionCommand);
+        AnalysisException exception = 
Assertions.assertThrows(AnalysisException.class,
+                () -> ((AdminSetPartitionVersionCommand) 
plan).run(connectContext, null));
+        Assertions.assertTrue(exception.getMessage().contains("Should specify 
'partition_id' property."));
+    }
+}
diff --git 
a/regression-test/suites/nereids_p0/ddl/admin/test_nereids_admin_set_partition_version.groovy
 
b/regression-test/suites/nereids_p0/ddl/admin/test_nereids_admin_set_partition_version.groovy
new file mode 100644
index 00000000000..f00e7c4f8cb
--- /dev/null
+++ 
b/regression-test/suites/nereids_p0/ddl/admin/test_nereids_admin_set_partition_version.groovy
@@ -0,0 +1,47 @@
+// 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_admin_set_partition_version") {
+    sql "drop table if exists test_nereids_admin_set_partition_version"
+    sql """
+        CREATE TABLE IF NOT EXISTS test_nereids_admin_set_partition_version (
+                    k1 INT,
+                    v1 INT,
+                    v2 varchar(20)
+                )
+        DUPLICATE KEY (k1)
+        PARTITION BY LIST (`v2`)
+        (
+            PARTITION `p_huabei` VALUES IN ("beijing", "tianjin")
+        )
+        DISTRIBUTED BY HASH(k1) BUCKETS 1 properties("replication_num" = "1");
+    """
+
+    def res = sql """show partitions from 
test_nereids_admin_set_partition_version"""
+    def partitionId = res.get(0).get(0)
+
+    checkNereidsExecute("ADMIN SET TABLE 
test_nereids_admin_set_partition_version PARTITION VERSION 
PROPERTIES('partition_id' = '${partitionId}', 'visible_version' = '100')")
+
+    sql """
+        ADMIN SET TABLE test_nereids_admin_set_partition_version PARTITION 
VERSION PROPERTIES('partition_id' = '${partitionId}', 'visible_version' = '101')
+    """
+    assertThrows(Exception.class, {
+        sql """ADMIN SET TABLE test_nereids_admin_set_partition_version 
PARTITION VERSION PROPERTIES('a'='b')"""
+    })
+
+    sql "drop table if exists test_nereids_admin_set_partition_version"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to