Skip to content

Commit 14929f0

Browse files
committed
Optimise getting sole element from vector
1 parent 627887a commit 14929f0

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
@@ -784,8 +784,7 @@ impl Accumulator for TrivialFirstValueAccumulator {
784784
first_idx = Some(0);
785785
}
786786
if let Some(first_idx) = first_idx {
787-
let mut row = get_row_at_idx(values, first_idx)?;
788-
self.first = row.swap_remove(0);
787+
self.first = ScalarValue::try_from_array(&values[0], first_idx)?;
789788
self.first.compact();
790789
self.is_set = true;
791790
}
@@ -1176,8 +1175,7 @@ impl Accumulator for TrivialLastValueAccumulator {
11761175
last_idx = Some(value.len() - 1);
11771176
}
11781177
if let Some(last_idx) = last_idx {
1179-
let mut row = get_row_at_idx(values, last_idx)?;
1180-
self.last = row.swap_remove(0);
1178+
self.last = ScalarValue::try_from_array(&values[0], last_idx)?;
11811179
self.last.compact();
11821180
self.is_set = true;
11831181
}

0 commit comments

Comments
 (0)