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 f3e9d70ab95 [Enhancement] (nereids)implement DropFileCommand in 
nereids (#44504)
f3e9d70ab95 is described below

commit f3e9d70ab9558bf8df5145d0432b4d43cceef24b
Author: Vallish Pai <vallish...@gmail.com>
AuthorDate: Wed Nov 27 14:48:58 2024 +0530

    [Enhancement] (nereids)implement DropFileCommand in nereids (#44504)
    
    Issue Number: close #42619
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  4 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 13 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../trees/plans/commands/DropFileCommand.java      | 93 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../suites/auth_call/test_ddl_file_auth.groovy     |  2 +-
 6 files changed, 115 insertions(+), 3 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 f1b17a1b9fb..cee972a63d2 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
@@ -205,6 +205,8 @@ supportedDropStatement
     | DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq                           
 #dropSqlBlockRule
     | DROP USER (IF EXISTS)? userIdentify                                      
 #dropUser
     | DROP WORKLOAD GROUP (IF EXISTS)? name=identifierOrText                   
 #dropWorkloadGroup
+    | DROP FILE name=STRING_LITERAL
+        ((FROM | IN) database=identifier)? properties=propertyClause           
 #dropFile
     | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText                  
 #dropWorkloadPolicy
     ;
 
@@ -671,8 +673,6 @@ unsupportedDropStatement
     | DROP TABLE (IF EXISTS)? name=multipartIdentifier FORCE?                  
 #dropTable
     | DROP VIEW (IF EXISTS)? name=multipartIdentifier                          
 #dropView
     | DROP REPOSITORY name=identifier                                          
 #dropRepository
-    | DROP FILE name=STRING_LITERAL
-        ((FROM | IN) database=identifier)? properties=propertyClause           
 #dropFile
     | DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier 
 #dropIndex
     | DROP RESOURCE (IF EXISTS)? name=identifierOrText                         
 #dropResource
     | DROP ROW POLICY (IF EXISTS)? policyName=identifier
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 d553d93da9c..1a49c7ba65f 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
@@ -106,6 +106,7 @@ import 
org.apache.doris.nereids.DorisParser.DereferenceContext;
 import org.apache.doris.nereids.DorisParser.DropCatalogRecycleBinContext;
 import org.apache.doris.nereids.DorisParser.DropConstraintContext;
 import org.apache.doris.nereids.DorisParser.DropEncryptkeyContext;
+import org.apache.doris.nereids.DorisParser.DropFileContext;
 import org.apache.doris.nereids.DorisParser.DropMTMVContext;
 import org.apache.doris.nereids.DorisParser.DropProcedureContext;
 import org.apache.doris.nereids.DorisParser.DropRoleContext;
@@ -474,6 +475,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinComman
 import 
org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand.IdType;
 import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropEncryptkeyCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropFileCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropJobCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
@@ -4617,6 +4619,17 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new DropEncryptkeyCommand(new EncryptKeyName(nameParts), 
ctx.EXISTS() != null);
     }
 
+    @Override
+    public LogicalPlan visitDropFile(DropFileContext ctx) {
+        String dbName = null;
+        if (ctx.database != null) {
+            dbName = ctx.database.getText();
+        }
+        Map<String, String> properties = ctx.propertyClause() != null
+                                    ? 
Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : Maps.newHashMap();
+        return new DropFileCommand(stripQuotes(ctx.name.getText()), dbName, 
properties);
+    }
+
     @Override
     public LogicalPlan visitDropSqlBlockRule(DropSqlBlockRuleContext ctx) {
         return new 
DropSqlBlockRuleCommand(visitIdentifierSeq(ctx.identifierSeq()), ctx.EXISTS() 
!= 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 b5f511d8fe3..20d46d612d0 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
@@ -174,6 +174,7 @@ public enum PlanType {
     ALTER_WORKLOAD_POLICY_COMMAND,
     DROP_CATALOG_RECYCLE_BIN_COMMAND,
     DROP_ENCRYPTKEY_COMMAND,
+    DROP_FILE_COMMAND,
     UNSET_VARIABLE_COMMAND,
     UNSET_DEFAULT_STORAGE_VAULT_COMMAND,
     UNSUPPORTED_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropFileCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropFileCommand.java
new file mode 100644
index 00000000000..92e516238a5
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropFileCommand.java
@@ -0,0 +1,93 @@
+// 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.Database;
+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.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.StmtExecutor;
+
+import com.google.common.base.Strings;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * drop file command command
+ */
+public class DropFileCommand extends DropCommand {
+    public static final String PROP_CATALOG = "catalog";
+    private final String fileName;
+    private String dbName; // update based on current db if not present.
+    private final Map<String, String> properties;
+    private String catalogName = null;
+
+    /**
+     * constructor
+     */
+    public DropFileCommand(String fileName, String dbName, Map<String, String> 
properties) {
+        super(PlanType.DROP_FILE_COMMAND);
+        this.fileName = fileName;
+        this.dbName = dbName;
+        this.properties = properties;
+    }
+
+    @Override
+    public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        // check operation privilege
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+
+        if (Strings.isNullOrEmpty(dbName)) {
+            dbName = ctx.getDatabase();
+            if (Strings.isNullOrEmpty(dbName)) {
+                ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
+            }
+        }
+
+        if (Strings.isNullOrEmpty(fileName)) {
+            throw new AnalysisException("File name is not specified");
+        }
+
+        Optional<String> optional = properties.keySet().stream().filter(
+                entity -> !PROP_CATALOG.equals(entity)).findFirst();
+        if (optional.isPresent()) {
+            throw new AnalysisException(optional.get() + " is invalid 
property");
+        }
+
+        catalogName = properties.get(PROP_CATALOG);
+        if (Strings.isNullOrEmpty(catalogName)) {
+            throw new AnalysisException("catalog name is missing");
+        }
+
+        Database db = 
Env.getCurrentInternalCatalog().getDbOrDdlException(dbName);
+        Env.getCurrentEnv().getSmallFileMgr().removeFile(db.getId(), 
catalogName, fileName, false);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitDropFileCommand(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 8cdd9fa3278..0af9ce4dc9c 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
@@ -41,6 +41,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropEncryptkeyCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropFileCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropJobCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
@@ -436,6 +437,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(dropEncryptkeyCommand, context);
     }
 
+    default R visitDropFileCommand(DropFileCommand dropFileCommand, C context) 
{
+        return visitCommand(dropFileCommand, context);
+    }
+
     default R visitDropSqlBlockRuleCommand(DropSqlBlockRuleCommand 
dropSqlBlockRuleCommand, C context) {
         return visitCommand(dropSqlBlockRuleCommand, context);
     }
diff --git a/regression-test/suites/auth_call/test_ddl_file_auth.groovy 
b/regression-test/suites/auth_call/test_ddl_file_auth.groovy
index 99b71eabddf..53cab5b3687 100644
--- a/regression-test/suites/auth_call/test_ddl_file_auth.groovy
+++ b/regression-test/suites/auth_call/test_ddl_file_auth.groovy
@@ -81,7 +81,7 @@ suite("test_ddl_file_auth","p0,auth_call") {
         def res = sql """SHOW FILE FROM ${dbName};"""
         assertTrue(res.size() == 1)
 
-        sql """DROP FILE "${fileName}" from ${dbName} properties("catalog" = 
"internal");"""
+        checkNereidsExecute("""DROP FILE "${fileName}" from ${dbName} 
properties("catalog" = "internal");""")
         res = sql """SHOW FILE FROM ${dbName};"""
         assertTrue(res.size() == 0)
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to