Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Nov 12, 2024
1 parent 28d91e2 commit e9b4340
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions crates/polars-io/src/cloud/polars_object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,49 @@ mod tests {
[(0..67108864, 0), (67108864..134217728, 2)]
);

// <= 1MiB gap, merge
assert_eq!(
merge_ranges(&[0..1, 1024 * 1024 + 1..1024 * 1024 + 2]).collect::<Vec<_>>(),
[(0..1048578, 2)]
);

// > 1MiB gap, do not merge
assert_eq!(
merge_ranges(&[0..1, 1024 * 1024 + 2..1024 * 1024 + 3]).collect::<Vec<_>>(),
[(0..1, 1), (1048578..1048579, 2)]
);

// <= 12.5% gap, merge
assert_eq!(
merge_ranges(&[0..8, 10..11]).collect::<Vec<_>>(),
[(0..11, 2)]
);

// <= 12.5% gap relative to RHS, merge
assert_eq!(
merge_ranges(&[0..1, 3..11]).collect::<Vec<_>>(),
[(0..11, 2)]
);

// Overlapping range, merge
assert_eq!(
merge_ranges(&[0..80 * 1024 * 1024, 10 * 1024 * 1024..70 * 1024 * 1024])
.collect::<Vec<_>>(),
[(0..80 * 1024 * 1024, 2)]
);
}

#[test]
fn test_merge_small_ranges() {
// Tests merge logic that merges small ranges regardless of how large
// the existing merged range is.

use super::{get_download_chunk_size, merge_ranges};

let chunk_size = get_download_chunk_size();

assert_eq!(chunk_size, 64 * 1024 * 1024);

assert_eq!(
merge_ranges(&[
0..1,
Expand All @@ -475,7 +518,6 @@ mod tests {
]
);

// Test small ranges merge rule.
assert_eq!(
merge_ranges(&[
0..64 * 1024 * 1024,
Expand Down Expand Up @@ -521,36 +563,5 @@ mod tests {
.collect::<Vec<_>>(),
[(0..71303168, 8)]
);

// <= 1MiB gap, merge
assert_eq!(
merge_ranges(&[0..1, 1024 * 1024 + 1..1024 * 1024 + 2]).collect::<Vec<_>>(),
[(0..1048578, 2)]
);

// > 1MiB gap, do not merge
assert_eq!(
merge_ranges(&[0..1, 1024 * 1024 + 2..1024 * 1024 + 3]).collect::<Vec<_>>(),
[(0..1, 1), (1048578..1048579, 2)]
);

// <= 12.5% gap, merge
assert_eq!(
merge_ranges(&[0..8, 10..11]).collect::<Vec<_>>(),
[(0..11, 2)]
);

// <= 12.5% gap relative to RHS, merge
assert_eq!(
merge_ranges(&[0..1, 3..11]).collect::<Vec<_>>(),
[(0..11, 2)]
);

// Overlapping range, merge
assert_eq!(
merge_ranges(&[0..80 * 1024 * 1024, 10 * 1024 * 1024..70 * 1024 * 1024])
.collect::<Vec<_>>(),
[(0..80 * 1024 * 1024, 2)]
);
}
}

0 comments on commit e9b4340

Please sign in to comment.