From 3029b47a89ca55c422a268d2d0e2ba38fbff9e95 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" <6406592+v0y4g3r@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:56:03 +0800 Subject: [PATCH] fix: find latest window (#5037) * fix: find latest window * more test files --- src/mito2/src/compaction/twcs.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/mito2/src/compaction/twcs.rs b/src/mito2/src/compaction/twcs.rs index 96fc755a7a70..f454b5923559 100644 --- a/src/mito2/src/compaction/twcs.rs +++ b/src/mito2/src/compaction/twcs.rs @@ -353,10 +353,10 @@ fn find_latest_window_in_seconds<'a>( let mut latest_timestamp = None; for f in files { let (_, end) = f.time_range(); - if let Some(latest) = latest_timestamp - && end > latest - { - latest_timestamp = Some(end); + if let Some(latest) = latest_timestamp { + if end > latest { + latest_timestamp = Some(end); + } } else { latest_timestamp = Some(end); } @@ -406,6 +406,18 @@ mod tests { ) .unwrap() ); + + assert_eq!( + Some((i64::MAX / 3600000 + 1) * 3600), + find_latest_window_in_seconds( + [ + new_file_handle(FileId::random(), i64::MIN, i64::MAX, 0), + new_file_handle(FileId::random(), 0, 1000, 0) + ] + .iter(), + 3600 + ) + ); } #[test]