JingsongLi commented on code in PR #7537:
URL: https://github.com/apache/paimon/pull/7537#discussion_r3442918515
##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/CompactActionITCase.java:
##########
@@ -930,6 +932,127 @@ public void testDataEvolutionTableCompact() throws
Exception {
assertThat(value).isEqualTo(30000);
}
+ @Test
+ @Timeout(60)
+ public void testSkipExpiredPartitions() throws Exception {
+ // Use a date far in the past (expired) and today's date (not expired)
+ String expiredDt =
+
LocalDate.now().minusDays(30).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+ String activeDt =
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+
+ Map<String, String> tableOptions = new HashMap<>();
+ tableOptions.put(CoreOptions.WRITE_ONLY.key(), "true");
+ tableOptions.put(CoreOptions.PARTITION_EXPIRATION_TIME.key(), "7 d");
+ tableOptions.put(
+ CoreOptions.PARTITION_EXPIRATION_STRATEGY.key(),
+ CoreOptions.PartitionExpireStrategy.VALUES_TIME.toString());
+ tableOptions.put(CoreOptions.PARTITION_TIMESTAMP_FORMATTER.key(),
"yyyyMMdd");
+
+ FileStoreTable table =
+ prepareTable(
+ Collections.singletonList("dt"),
+ Arrays.asList("dt", "k"),
+ Collections.emptyList(),
+ tableOptions);
+
+ // Write two batches to each partition so each has multiple files
+ writeData(
+ rowData(1, 100, 15, BinaryString.fromString(expiredDt)),
+ rowData(1, 100, 15, BinaryString.fromString(activeDt)));
+
+ writeData(
+ rowData(2, 100, 15, BinaryString.fromString(expiredDt)),
+ rowData(2, 100, 15, BinaryString.fromString(activeDt)));
+
+ checkLatestSnapshot(table, 2, Snapshot.CommitKind.APPEND);
+
+ CompactAction action =
+ createAction(
+ CompactAction.class,
+ "compact",
+ "--warehouse",
+ warehouse,
+ "--database",
+ database,
+ "--table",
+ tableName,
+ "--table_conf",
+ CoreOptions.COMPACTION_SKIP_EXPIRED_PARTITIONS.key() +
"=true");
+ StreamExecutionEnvironment env =
streamExecutionEnvironmentBuilder().batchMode().build();
+ action.withStreamExecutionEnvironment(env).build();
+ env.execute();
+
+ checkLatestSnapshot(table, 3, Snapshot.CommitKind.COMPACT);
Review Comment:
This assertion assumes partition expiration does not run during the compact
commit, but that is not guaranteed here. `CompactAction` copies the table with
`write-only=false`, so `TableCommitImpl.maintain` may call
`PartitionExpire.expire(...)` after the compaction snapshot.
`NormalPartitionExpire` also initializes `lastCheck` with a random offset
within `partition.expiration-check-interval`, so even with the default 1h
interval this test can occasionally expire `expiredDt`, creating an extra
OVERWRITE snapshot before this check (or removing the expired split before the
later file-count assertion). Could we make the test deterministic, for example
by setting a very large `partition.expiration-check-interval`, or by explicitly
asserting the documented delete-on-commit behavior?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]