Skip to content

Commit

Permalink
only retain string type
Browse files Browse the repository at this point in the history
  • Loading branch information
askwang committed Sep 19, 2024
1 parent 72d2628 commit 3591706
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,12 @@ public InternalRow[] call(InternalRow args) {
builder.snapshotRetainMin(retainMin);
}
if (!StringUtils.isNullOrWhitespaceOnly(olderThanStr)) {
long olderThanMills;
// forward compatibility for timestamp type
if (StringUtils.isNumeric(olderThanStr)) {
olderThanMills = Long.parseLong(olderThanStr) / 1000;
builder.snapshotTimeRetain(
Duration.ofMillis(System.currentTimeMillis() - olderThanMills));
} else {
olderThanMills =
DateTimeUtils.parseTimestampData(
olderThanStr, 3, TimeZone.getDefault())
.getMillisecond();
builder.snapshotTimeRetain(
Duration.ofMillis(System.currentTimeMillis() - olderThanMills));
}
long olderThanMills =
DateTimeUtils.parseTimestampData(
olderThanStr, 3, TimeZone.getDefault())
.getMillisecond();
builder.snapshotTimeRetain(
Duration.ofMillis(System.currentTimeMillis() - olderThanMills));
}
if (maxDeletes != null) {
builder.snapshotMaxDeletes(maxDeletes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ExpireSnapshotsProcedureTest extends PaimonSparkTestBase with StreamTest {
}
}

test("test parameter order_than with old timestamp type and new string type") {
test("Paimon Procedure: test parameter order_than with string type") {
sql(
"CREATE TABLE T (a INT, b STRING) " +
"TBLPROPERTIES ( 'num-sorted-run.compaction-trigger' = '999' )")
Expand All @@ -154,17 +154,10 @@ class ExpireSnapshotsProcedureTest extends PaimonSparkTestBase with StreamTest {
}
checkSnapshots(snapshotManager, 1, 5)

// older_than with old timestamp type, like "1724664000000"
val nanosecond: Long = snapshotManager.latestSnapshot().timeMillis * 1000
spark.sql(
s"CALL paimon.sys.expire_snapshots(table => 'test.T', older_than => $nanosecond, max_deletes => 2)")
checkSnapshots(snapshotManager, 3, 5)

// older_than with new string type, like "2024-08-26 17:20:00"
val timestamp = new Timestamp(snapshotManager.latestSnapshot().timeMillis)
spark.sql(
s"CALL paimon.sys.expire_snapshots(table => 'test.T', older_than => '${timestamp.toString}', max_deletes => 2)")
checkSnapshots(snapshotManager, 5, 5)
checkSnapshots(snapshotManager, 3, 5)
}

def checkSnapshots(sm: SnapshotManager, earliest: Int, latest: Int): Unit = {
Expand Down

0 comments on commit 3591706

Please sign in to comment.