Skip to content

Commit ecbd327

Browse files
committed
address partial
1 parent 3973c69 commit ecbd327

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

datafusion/datasource/src/file_scan_config.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,12 @@ impl FileScanConfig {
884884
sort_order: &LexOrdering,
885885
target_partitions: usize,
886886
) -> Result<Vec<FileGroup>> {
887+
if target_partitions == 0 {
888+
return Err(DataFusionError::Internal(
889+
"target_partitions must be greater than 0".to_string(),
890+
));
891+
}
892+
887893
let flattened_files = file_groups
888894
.iter()
889895
.flat_map(FileGroup::iter)
@@ -903,12 +909,10 @@ impl FileScanConfig {
903909
let indices_sorted_by_min = statistics.min_values_sorted();
904910

905911
// Initialize with target_partitions empty groups
906-
let mut file_groups_indices: Vec<Vec<usize>> =
907-
vec![vec![]; target_partitions.max(1)];
912+
let mut file_groups_indices: Vec<Vec<usize>> = vec![vec![]; target_partitions];
908913

909914
for (idx, min) in indices_sorted_by_min {
910-
// Find all groups where the file can fit
911-
let mut suitable_groups: Vec<(usize, &mut Vec<usize>)> = file_groups_indices
915+
if let Some((_, group)) = file_groups_indices
912916
.iter_mut()
913917
.enumerate()
914918
.filter(|(_, group)| {
@@ -917,12 +921,8 @@ impl FileScanConfig {
917921
> statistics
918922
.max(*group.last().expect("groups should not be empty"))
919923
})
920-
.collect();
921-
922-
// Sort by group size to prioritize smaller groups
923-
suitable_groups.sort_by_key(|(_, group)| group.len());
924-
925-
if let Some((_, group)) = suitable_groups.first_mut() {
924+
.min_by_key(|(_, group)| group.len())
925+
{
926926
group.push(idx);
927927
} else {
928928
// Create a new group if no existing group fits

0 commit comments

Comments
 (0)