Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
askwang committed Oct 30, 2024
1 parent 97b9b33 commit 1be1ba1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions paimon-core/src/main/java/org/apache/paimon/table/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.io.Serializable;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -126,8 +127,10 @@ default String fullName() {

/** Delete tags, tags are separated by commas. */
@Experimental
default void deleteTags(String tagNames) {
for (String tagName : tagNames.split(",")) {
default void deleteTags(String tagStr) {
String[] tagNames =
Arrays.stream(tagStr.split(",")).map(String::trim).toArray(String[]::new);
for (String tagName : tagNames) {
deleteTag(tagName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes
spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"),
Row("test_tag_2") :: Row("test_tag_3") :: Nil)

// delete test_tag_1 and test_tag_2
// delete test_tag_2 and test_tag_3
checkAnswer(
spark.sql(
"CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag_2,test_tag_3')"),
Expand Down Expand Up @@ -199,4 +199,30 @@ class CreateAndDeleteTagProcedureTest extends PaimonSparkTestBase with StreamTes
spark.sql("CALL paimon.sys.delete_tag(table => 'test.T', tag => 'test_tag')"),
Row(true) :: Nil)
}

test("Paimon Procedure: delete multiple tags") {
spark.sql("CREATE TABLE T (id INT, name STRING) USING PAIMON")
spark.sql("insert into T values (1, 'a')")

// create four tags
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 'tag-1')")
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 'tag-2')")
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 'tag-3')")
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 'tag-4')")
checkAnswer(spark.sql("SELECT count(*) FROM paimon.test.`T$tags`"), Row(4) :: Nil)

// multiple tags with no space
checkAnswer(
spark.sql("CALL paimon.sys.delete_tag(table => 'test.T', tag => 'tag-1,tag-2')"),
Row(true) :: Nil)
checkAnswer(
spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"),
Row("tag-3") :: Row("tag-4") :: Nil)

// multiple tags with space
checkAnswer(
spark.sql("CALL paimon.sys.delete_tag(table => 'test.T', tag => 'tag-3, tag-4')"),
Row(true) :: Nil)
checkAnswer(spark.sql("SELECT tag_name FROM paimon.test.`T$tags`"), Nil)
}
}

0 comments on commit 1be1ba1

Please sign in to comment.