Skip to content

Commit 1d44595

Browse files
committed
Optimise getting sole element from vector
1 parent 6aec3f3 commit 1d44595

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,7 @@ impl Accumulator for TrivialFirstValueAccumulator {
800800
first_idx = Some(0);
801801
}
802802
if let Some(first_idx) = first_idx {
803-
let mut row = get_row_at_idx(values, first_idx)?;
804-
self.first = row.swap_remove(0);
803+
self.first = ScalarValue::try_from_array(&values[0], first_idx)?;
805804
self.first.compact();
806805
self.is_set = true;
807806
}
@@ -1292,8 +1291,7 @@ impl Accumulator for TrivialLastValueAccumulator {
12921291
last_idx = Some(value.len() - 1);
12931292
}
12941293
if let Some(last_idx) = last_idx {
1295-
let mut row = get_row_at_idx(values, last_idx)?;
1296-
self.last = row.swap_remove(0);
1294+
self.last = ScalarValue::try_from_array(&values[0], last_idx)?;
12971295
self.last.compact();
12981296
self.is_set = true;
12991297
}

0 commit comments

Comments
 (0)