Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Space allowed between multiple deleted tags #4412

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading