@@ -322,13 +322,17 @@ private void compactAwareBucketTable(
322322 if (partitionPredicate != null ) {
323323 snapshotReader .withPartitionFilter (partitionPredicate );
324324 }
325+ boolean filterByPartitionIdleTime = partitionIdleTime != null ;
325326 Set <BinaryRow > partitionToBeCompacted =
326- getHistoryPartition (snapshotReader , partitionIdleTime );
327+ getPartitionsToCompact (snapshotReader , partitionIdleTime );
327328 List <Pair <byte [], Integer >> partitionBuckets =
328329 snapshotReader .bucketEntries ().stream ()
329330 .map (entry -> Pair .of (entry .partition (), entry .bucket ()))
330331 .distinct ()
331- .filter (pair -> partitionToBeCompacted .contains (pair .getKey ()))
332+ .filter (
333+ pair ->
334+ !filterByPartitionIdleTime
335+ || partitionToBeCompacted .contains (pair .getKey ()))
332336 .map (
333337 p ->
334338 Pair .of (
@@ -615,29 +619,25 @@ private static List<CommitMessage> deserializeCommitMessagesAndReleaseSerialized
615619 return messages ;
616620 }
617621
618- private Set <BinaryRow > getHistoryPartition (
622+ static Set <BinaryRow > getPartitionsToCompact (
619623 SnapshotReader snapshotReader , @ Nullable Duration partitionIdleTime ) {
620- Set <Pair <BinaryRow , Long >> partitionInfo =
621- snapshotReader .partitionEntries ().stream ()
622- .map (
623- partitionEntry ->
624- Pair .of (
625- partitionEntry .partition (),
626- partitionEntry .lastFileCreationTime ()))
627- .collect (Collectors .toSet ());
628- if (partitionIdleTime != null ) {
629- long historyMilli =
630- LocalDateTime .now ()
631- .minus (partitionIdleTime )
632- .atZone (ZoneId .systemDefault ())
633- .toInstant ()
634- .toEpochMilli ();
635- partitionInfo =
636- partitionInfo .stream ()
637- .filter (partition -> partition .getValue () <= historyMilli )
638- .collect (Collectors .toSet ());
639- }
640- return partitionInfo .stream ().map (Pair ::getKey ).collect (Collectors .toSet ());
624+ return partitionIdleTime == null
625+ ? Collections .emptySet ()
626+ : getHistoryPartition (snapshotReader , partitionIdleTime );
627+ }
628+
629+ private static Set <BinaryRow > getHistoryPartition (
630+ SnapshotReader snapshotReader , Duration partitionIdleTime ) {
631+ long historyMilli =
632+ LocalDateTime .now ()
633+ .minus (partitionIdleTime )
634+ .atZone (ZoneId .systemDefault ())
635+ .toInstant ()
636+ .toEpochMilli ();
637+ return snapshotReader .partitionEntries ().stream ()
638+ .filter (partition -> partition .lastFileCreationTime () <= historyMilli )
639+ .map (PartitionEntry ::partition )
640+ .collect (Collectors .toSet ());
641641 }
642642
643643 private void sortCompactUnAwareBucketTable (
0 commit comments