Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public class CreateTagProcedure extends CreateOrReplaceTagBaseProcedure {

@Override
void createOrReplaceTag(Table table, String tagName, Long snapshotId, Duration timeRetained) {
if (snapshotId == null) {
if (timeRetained == null) {
if (snapshotId == null) {
table.createTag(tagName);
} else {
table.createTag(tagName, snapshotId);
}
} else if (snapshotId == null) {
table.createTag(tagName, timeRetained);
} else {
table.createTag(tagName, snapshotId, timeRetained);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public class CreateTagProcedure extends CreateOrReplaceTagBaseProcedure {

@Override
void createOrReplaceTag(Table table, String tagName, Long snapshotId, Duration timeRetained) {
if (snapshotId == null) {
if (timeRetained == null) {
if (snapshotId == null) {
table.createTag(tagName);
} else {
table.createTag(tagName, snapshotId);
}
} else if (snapshotId == null) {
table.createTag(tagName, timeRetained);
} else {
table.createTag(tagName, snapshotId, timeRetained);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
Expand All @@ -36,6 +37,28 @@
/** IT Case for {@link ExpireTagsProcedure}. */
public class ExpireTagsProcedureITCase extends CatalogITCaseBase {

@Test
public void testCreateTagUsesDefaultRetention() throws Exception {
sql("CREATE TABLE T (id INT) WITH ('tag.default-time-retained' = '1d')");
sql("INSERT INTO T VALUES (1)");
sql("INSERT INTO T VALUES (2)");

sql("CALL sys.create_tag(`table` => 'default.T', tag => 'latest')");
sql("CALL sys.create_tag(`table` => 'default.T', tag => 'by-id', snapshot_id => 1)");
sql(
"CALL sys.create_tag(`table` => 'default.T', tag => 'override', time_retained => '1h')");

FileStoreTable table = paimonTable("T");
assertThat(table.tagManager().getOrThrow("latest").id()).isEqualTo(2L);
assertThat(table.tagManager().getOrThrow("by-id").id()).isEqualTo(1L);
assertThat(table.tagManager().getOrThrow("latest").getTagTimeRetained())
.isEqualTo(Duration.ofDays(1));
assertThat(table.tagManager().getOrThrow("by-id").getTagTimeRetained())
.isEqualTo(Duration.ofDays(1));
assertThat(table.tagManager().getOrThrow("override").getTagTimeRetained())
.isEqualTo(Duration.ofHours(1));
}

@Test
public void testExpireTagsByTagCreateTimeAndTagTimeRetained() throws Exception {
boolean tagTimeExpireEnabled = ThreadLocalRandom.current().nextBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ private CreateTagProcedure(TableCatalog tableCatalog) {

@Override
void createOrReplaceTag(Table table, String tagName, Long snapshotId, Duration timeRetained) {
if (snapshotId == null) {
if (timeRetained == null) {
if (snapshotId == null) {
table.createTag(tagName);
} else {
table.createTag(tagName, snapshotId);
}
} else if (snapshotId == null) {
table.createTag(tagName, timeRetained);
} else {
table.createTag(tagName, snapshotId, timeRetained);
Expand Down
Loading