Skip to content

Commit ea12495

Browse files
committed
clippy, remove collect
1 parent 0def286 commit ea12495

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

datafusion/common/src/pruning.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,15 @@ impl PartitionPruningStatistics {
202202
impl PruningStatistics for PartitionPruningStatistics {
203203
fn min_values(&self, column: &Column) -> Option<ArrayRef> {
204204
let index = self.partition_schema.index_of(column.name()).ok()?;
205-
self.partition_values
206-
.get(index)
207-
.map(|v| {
208-
if v.is_empty() || v.null_count() == v.len() {
209-
// If the array is empty or all nulls, return None
210-
None
211-
} else {
212-
// Otherwise, return the array as is
213-
Some(Arc::clone(v))
214-
}
215-
})
216-
.flatten()
205+
self.partition_values.get(index).and_then(|v| {
206+
if v.is_empty() || v.null_count() == v.len() {
207+
// If the array is empty or all nulls, return None
208+
None
209+
} else {
210+
// Otherwise, return the array as is
211+
Some(Arc::clone(v))
212+
}
213+
})
217214
}
218215

219216
fn max_values(&self, column: &Column) -> Option<ArrayRef> {
@@ -239,18 +236,18 @@ impl PruningStatistics for PartitionPruningStatistics {
239236
) -> Option<BooleanArray> {
240237
let index = self.partition_schema.index_of(column.name()).ok()?;
241238
let array = self.partition_values.get(index)?;
242-
let boolean_arrays = values
243-
.iter()
244-
.map(|v| {
245-
let arrow_value = v.to_scalar()?;
246-
arrow::compute::kernels::cmp::eq(array, &arrow_value)
247-
})
248-
.collect::<Result<Vec<_>, _>>()
249-
.ok()?;
250-
let boolean_array = boolean_arrays.into_iter().reduce(|acc, arr| {
251-
arrow::compute::kernels::boolean::and(&acc, &arr)
252-
.expect("arrays are known to have equal lengths")
253-
})?;
239+
let boolean_array = values.iter().try_fold(None, |acc, v| {
240+
let arrow_value = v.to_scalar().ok()?;
241+
let eq_result = arrow::compute::kernels::cmp::eq(array, &arrow_value).ok()?;
242+
match acc {
243+
None => Some(Some(eq_result)),
244+
Some(acc_array) => {
245+
arrow::compute::kernels::boolean::and(&acc_array, &eq_result)
246+
.map(Some)
247+
.ok()
248+
}
249+
}
250+
})??;
254251
// If the boolean array is empty or all null values, return None
255252
if boolean_array.is_empty() || boolean_array.null_count() == boolean_array.len() {
256253
None

0 commit comments

Comments
 (0)