This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new db8bcd7fd [core] Introduce deleteTags and deleteBranches to Table
db8bcd7fd is described below

commit db8bcd7fdd9c2705435d2ab1d2341c52d1f67ee5
Author: Jingsong <[email protected]>
AuthorDate: Fri Jul 5 22:23:28 2024 +0800

    [core] Introduce deleteTags and deleteBranches to Table
---
 docs/content/flink/procedures.md                         |  4 ++--
 docs/content/spark/procedures.md                         |  2 +-
 .../src/main/java/org/apache/paimon/table/Table.java     | 16 ++++++++++++++++
 .../apache/paimon/flink/action/DeleteBranchAction.java   |  5 +----
 .../org/apache/paimon/flink/action/DeleteTagAction.java  |  5 +----
 .../paimon/flink/procedure/DeleteBranchProcedure.java    |  8 +-------
 .../paimon/flink/procedure/DeleteTagProcedure.java       |  6 +-----
 .../paimon/spark/procedure/DeleteBranchProcedure.java    |  6 +-----
 .../paimon/spark/procedure/DeleteTagProcedure.java       |  6 +-----
 9 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/docs/content/flink/procedures.md b/docs/content/flink/procedures.md
index e899e882c..0632a80a8 100644
--- a/docs/content/flink/procedures.md
+++ b/docs/content/flink/procedures.md
@@ -127,7 +127,7 @@ All available procedures are listed below.
       <td>
          To delete a tag. Arguments:
             <li>identifier: the target table identifier. Cannot be empty.</li>
-            <li>tagName: name of the tag to be deleted.If you specify multiple 
tags, delimiter is ','.</li>
+            <li>tagName: name of the tag to be deleted. If you specify 
multiple tags, delimiter is ','.</li>
       </td>
       <td>
          CALL sys.delete_tag('default.T', 'my_tag')
@@ -331,7 +331,7 @@ All available procedures are listed below.
       <td>
          To delete a branch. Arguments:
             <li>identifier: the target table identifier. Cannot be empty.</li>
-            <li>branchName: name of the branch to be deleted.If you specify 
multiple branches, delimiter is ','.</li>
+            <li>branchName: name of the branch to be deleted. If you specify 
multiple branches, delimiter is ','.</li>
       </td>
       <td>
          CALL sys.delete_branch('default.T', 'branch1')
diff --git a/docs/content/spark/procedures.md b/docs/content/spark/procedures.md
index c0e0131c4..8007431ec 100644
--- a/docs/content/spark/procedures.md
+++ b/docs/content/spark/procedures.md
@@ -169,7 +169,7 @@ This section introduce all available spark procedures about 
paimon.
       <td>
          To merge a branch to main branch. Arguments:
             <li>table: the target table identifier. Cannot be empty.</li>
-            <li>branch: name of the branch to be merged.If you specify 
multiple branches, delimiter is ','.</li>
+            <li>branch: name of the branch to be merged. If you specify 
multiple branches, delimiter is ','.</li>
       </td>
       <td>
           CALL sys.delete_branch(table => 'test_db.T', branch => 'test_branch')
diff --git a/paimon-core/src/main/java/org/apache/paimon/table/Table.java 
b/paimon-core/src/main/java/org/apache/paimon/table/Table.java
index aef5e9f48..0e23ec607 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/Table.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/Table.java
@@ -95,6 +95,14 @@ public interface Table extends Serializable {
     @Experimental
     void deleteTag(String tagName);
 
+    /** Delete tags, tags are separated by commas. */
+    @Experimental
+    default void deleteTags(String tagNames) {
+        for (String tagName : tagNames.split(",")) {
+            deleteTag(tagName);
+        }
+    }
+
     /** Rollback table's state to a specific tag. */
     @Experimental
     void rollbackTo(String tagName);
@@ -115,6 +123,14 @@ public interface Table extends Serializable {
     @Experimental
     void deleteBranch(String branchName);
 
+    /** Delete branches, branches are separated by commas. */
+    @Experimental
+    default void deleteBranches(String branchNames) {
+        for (String branch : branchNames.split(",")) {
+            deleteBranch(branch);
+        }
+    }
+
     /** Merge a branch to main branch. */
     @Experimental
     void fastForward(String branchName);
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteBranchAction.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteBranchAction.java
index d5a48fcb4..7373f8fff 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteBranchAction.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteBranchAction.java
@@ -37,9 +37,6 @@ public class DeleteBranchAction extends TableActionBase {
 
     @Override
     public void run() throws Exception {
-        String[] branches = branchNames.split(",");
-        for (String branch : branches) {
-            table.deleteBranch(branch);
-        }
+        table.deleteBranches(branchNames);
     }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteTagAction.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteTagAction.java
index dc7d5dc9f..73cf21033 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteTagAction.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/DeleteTagAction.java
@@ -37,9 +37,6 @@ public class DeleteTagAction extends TableActionBase {
 
     @Override
     public void run() throws Exception {
-        String[] tagNames = tagNameStr.split(",");
-        for (String tagName : tagNames) {
-            table.deleteTag(tagName);
-        }
+        table.deleteTags(tagNameStr);
     }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteBranchProcedure.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteBranchProcedure.java
index 56f585ea3..e7ff20f28 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteBranchProcedure.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteBranchProcedure.java
@@ -20,7 +20,6 @@ package org.apache.paimon.flink.procedure;
 
 import org.apache.paimon.catalog.Catalog;
 import org.apache.paimon.catalog.Identifier;
-import org.apache.paimon.table.Table;
 
 import org.apache.flink.table.procedure.ProcedureContext;
 
@@ -42,12 +41,7 @@ public class DeleteBranchProcedure extends ProcedureBase {
 
     public String[] call(ProcedureContext procedureContext, String tableId, 
String branchStr)
             throws Catalog.TableNotExistException {
-        String[] branchs = branchStr.split(",");
-        for (String branch : branchs) {
-            Table table = catalog.getTable(Identifier.fromString(tableId));
-            table.deleteBranch(branch);
-        }
-
+        
catalog.getTable(Identifier.fromString(tableId)).deleteBranches(branchStr);
         return new String[] {"Success"};
     }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteTagProcedure.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteTagProcedure.java
index 5f597ce48..58e6d637f 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteTagProcedure.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/DeleteTagProcedure.java
@@ -38,11 +38,7 @@ public class DeleteTagProcedure extends ProcedureBase {
     public String[] call(ProcedureContext procedureContext, String tableId, 
String tagNameStr)
             throws Catalog.TableNotExistException {
         Table table = catalog.getTable(Identifier.fromString(tableId));
-        String[] tagNames = tagNameStr.split(",");
-        for (String tagName : tagNames) {
-            table.deleteTag(tagName);
-        }
-
+        table.deleteTags(tagNameStr);
         return new String[] {"Success"};
     }
 
diff --git 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteBranchProcedure.java
 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteBranchProcedure.java
index d5536250a..e398eee02 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteBranchProcedure.java
+++ 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteBranchProcedure.java
@@ -61,14 +61,10 @@ public class DeleteBranchProcedure extends BaseProcedure {
     public InternalRow[] call(InternalRow args) {
         Identifier tableIdent = toIdentifier(args.getString(0), 
PARAMETERS[0].name());
         String branchStr = args.getString(1);
-        String[] branches = branchStr.split(",");
-
         return modifyPaimonTable(
                 tableIdent,
                 table -> {
-                    for (String branch : branches) {
-                        table.deleteBranch(branch);
-                    }
+                    table.deleteBranches(branchStr);
                     InternalRow outputRow = newInternalRow(true);
                     return new InternalRow[] {outputRow};
                 });
diff --git 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteTagProcedure.java
 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteTagProcedure.java
index 4868ac0a0..890608491 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteTagProcedure.java
+++ 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/DeleteTagProcedure.java
@@ -61,14 +61,10 @@ public class DeleteTagProcedure extends BaseProcedure {
     public InternalRow[] call(InternalRow args) {
         Identifier tableIdent = toIdentifier(args.getString(0), 
PARAMETERS[0].name());
         String tagStr = args.getString(1);
-        String[] tags = tagStr.split(",");
-
         return modifyPaimonTable(
                 tableIdent,
                 table -> {
-                    for (String tag : tags) {
-                        table.deleteTag(tag);
-                    }
+                    table.deleteTags(tagStr);
                     InternalRow outputRow = newInternalRow(true);
                     return new InternalRow[] {outputRow};
                 });

Reply via email to