Skip to content

Commit 07e7fb5

Browse files
committed
Renames as per TODO
1 parent 3f475b1 commit 07e7fb5

1 file changed

Lines changed: 29 additions & 32 deletions

File tree

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl AggregateUDFImpl for FirstValue {
220220
.map(|e| e.expr.data_type(args.schema))
221221
.collect::<Result<Vec<_>>>()?;
222222

223-
FirstPrimitiveGroupsAccumulator::<T>::try_new(
223+
PrimitiveGroupsAccumulator::<T>::try_new(
224224
ordering,
225225
args.ignore_nulls,
226226
args.return_field.data_type(),
@@ -311,8 +311,7 @@ impl AggregateUDFImpl for FirstValue {
311311
}
312312
}
313313

314-
// TODO: rename to PrimitiveGroupsAccumulator
315-
struct FirstPrimitiveGroupsAccumulator<T>
314+
struct PrimitiveGroupsAccumulator<T>
316315
where
317316
T: ArrowPrimitiveType + Send,
318317
{
@@ -337,8 +336,7 @@ where
337336
// buffer for `get_filtered_min_of_each_group`
338337
// filter_min_of_each_group_buf.0[group_idx] -> idx_in_val
339338
// only valid if filter_min_of_each_group_buf.1[group_idx] == true
340-
// TODO: rename to extreme_of_each_group_buf
341-
min_of_each_group_buf: (Vec<usize>, BooleanBufferBuilder),
339+
extreme_of_each_group_buf: (Vec<usize>, BooleanBufferBuilder),
342340

343341
// =========== option ============
344342

@@ -356,7 +354,7 @@ where
356354
default_orderings: Vec<ScalarValue>,
357355
}
358356

359-
impl<T> FirstPrimitiveGroupsAccumulator<T>
357+
impl<T> PrimitiveGroupsAccumulator<T>
360358
where
361359
T: ArrowPrimitiveType + Send,
362360
{
@@ -385,7 +383,7 @@ where
385383
orderings: Vec::new(),
386384
is_sets: BooleanBufferBuilder::new(0),
387385
size_of_orderings: 0,
388-
min_of_each_group_buf: (Vec::new(), BooleanBufferBuilder::new(0)),
386+
extreme_of_each_group_buf: (Vec::new(), BooleanBufferBuilder::new(0)),
389387
pick_first_in_group,
390388
})
391389
}
@@ -468,8 +466,8 @@ where
468466

469467
self.is_sets.resize(new_size);
470468

471-
self.min_of_each_group_buf.0.resize(new_size, 0);
472-
self.min_of_each_group_buf.1.resize(new_size);
469+
self.extreme_of_each_group_buf.0.resize(new_size, 0);
470+
self.extreme_of_each_group_buf.1.resize(new_size);
473471
}
474472

475473
fn update_state(
@@ -496,10 +494,10 @@ where
496494
&mut self,
497495
emit_to: EmitTo,
498496
) -> (ArrayRef, Vec<Vec<ScalarValue>>, BooleanBuffer) {
499-
emit_to.take_needed(&mut self.min_of_each_group_buf.0);
500-
self.min_of_each_group_buf
497+
emit_to.take_needed(&mut self.extreme_of_each_group_buf.0);
498+
self.extreme_of_each_group_buf
501499
.1
502-
.truncate(self.min_of_each_group_buf.0.len());
500+
.truncate(self.extreme_of_each_group_buf.0.len());
503501

504502
(
505503
self.take_vals_and_null_buf(emit_to),
@@ -519,8 +517,7 @@ where
519517
/// Returns a vector of tuples `(group_idx, idx_in_val)` representing the index of the
520518
/// minimum value in `orderings` for each group, using lexicographical comparison.
521519
/// Values are filtered using `opt_filter` and `is_set_arr` if provided.
522-
/// TODO: rename to get_filtered_extreme_of_each_group
523-
fn get_filtered_min_of_each_group(
520+
fn get_filtered_extreme_of_each_group(
524521
&mut self,
525522
orderings: &[ArrayRef],
526523
group_indices: &[usize],
@@ -529,8 +526,8 @@ where
529526
is_set_arr: Option<&BooleanArray>,
530527
) -> Result<Vec<(usize, usize)>> {
531528
// Set all values in min_of_each_group_buf.1 to false.
532-
self.min_of_each_group_buf.1.truncate(0);
533-
self.min_of_each_group_buf
529+
self.extreme_of_each_group_buf.1.truncate(0);
530+
self.extreme_of_each_group_buf
534531
.1
535532
.append_n(self.vals.len(), false);
536533

@@ -565,29 +562,29 @@ where
565562
continue;
566563
}
567564

568-
let is_valid = self.min_of_each_group_buf.1.get_bit(group_idx);
565+
let is_valid = self.extreme_of_each_group_buf.1.get_bit(group_idx);
569566

570567
if !is_valid {
571-
self.min_of_each_group_buf.1.set_bit(group_idx, true);
572-
self.min_of_each_group_buf.0[group_idx] = idx_in_val;
568+
self.extreme_of_each_group_buf.1.set_bit(group_idx, true);
569+
self.extreme_of_each_group_buf.0[group_idx] = idx_in_val;
573570
} else {
574571
let ordering = comparator
575-
.compare(self.min_of_each_group_buf.0[group_idx], idx_in_val);
572+
.compare(self.extreme_of_each_group_buf.0[group_idx], idx_in_val);
576573

577574
if (ordering.is_gt() && self.pick_first_in_group)
578575
|| (ordering.is_lt() && !self.pick_first_in_group)
579576
{
580-
self.min_of_each_group_buf.0[group_idx] = idx_in_val;
577+
self.extreme_of_each_group_buf.0[group_idx] = idx_in_val;
581578
}
582579
}
583580
}
584581

585582
Ok(self
586-
.min_of_each_group_buf
583+
.extreme_of_each_group_buf
587584
.0
588585
.iter()
589586
.enumerate()
590-
.filter(|(group_idx, _)| self.min_of_each_group_buf.1.get_bit(*group_idx))
587+
.filter(|(group_idx, _)| self.extreme_of_each_group_buf.1.get_bit(*group_idx))
591588
.map(|(group_idx, idx_in_val)| (group_idx, *idx_in_val))
592589
.collect::<Vec<_>>())
593590
}
@@ -603,7 +600,7 @@ where
603600
}
604601
}
605602

606-
impl<T> GroupsAccumulator for FirstPrimitiveGroupsAccumulator<T>
603+
impl<T> GroupsAccumulator for PrimitiveGroupsAccumulator<T>
607604
where
608605
T: ArrowPrimitiveType + Send,
609606
{
@@ -623,7 +620,7 @@ where
623620

624621
// The overhead of calling `extract_row_at_idx_to_buf` is somewhat high, so we need to minimize its calls as much as possible.
625622
for (group_idx, idx) in self
626-
.get_filtered_min_of_each_group(
623+
.get_filtered_extreme_of_each_group(
627624
&values_and_order_cols[1..],
628625
group_indices,
629626
opt_filter,
@@ -704,7 +701,7 @@ where
704701

705702
let vals = values[0].as_primitive::<T>();
706703
// The overhead of calling `extract_row_at_idx_to_buf` is somewhat high, so we need to minimize its calls as much as possible.
707-
let groups = self.get_filtered_min_of_each_group(
704+
let groups = self.get_filtered_extreme_of_each_group(
708705
&val_and_order_cols[1..],
709706
group_indices,
710707
opt_filter,
@@ -733,8 +730,8 @@ where
733730
+ self.null_builder.capacity() / 8 // capacity is in bits, so convert to bytes
734731
+ self.is_sets.capacity() / 8
735732
+ self.size_of_orderings
736-
+ self.min_of_each_group_buf.0.capacity() * size_of::<usize>()
737-
+ self.min_of_each_group_buf.1.capacity() / 8
733+
+ self.extreme_of_each_group_buf.0.capacity() * size_of::<usize>()
734+
+ self.extreme_of_each_group_buf.1.capacity() / 8
738735
}
739736

740737
fn supports_convert_to_state(&self) -> bool {
@@ -1185,7 +1182,7 @@ impl AggregateUDFImpl for LastValue {
11851182
.map(|e| e.expr.data_type(args.schema))
11861183
.collect::<Result<Vec<_>>>()?;
11871184

1188-
Ok(Box::new(FirstPrimitiveGroupsAccumulator::<T>::try_new(
1185+
Ok(Box::new(PrimitiveGroupsAccumulator::<T>::try_new(
11891186
ordering,
11901187
args.ignore_nulls,
11911188
args.return_field.data_type(),
@@ -1668,7 +1665,7 @@ mod tests {
16681665
options: SortOptions::default(),
16691666
}];
16701667

1671-
let mut group_acc = FirstPrimitiveGroupsAccumulator::<Int64Type>::try_new(
1668+
let mut group_acc = PrimitiveGroupsAccumulator::<Int64Type>::try_new(
16721669
sort_keys.into(),
16731670
true,
16741671
&DataType::Int64,
@@ -1762,7 +1759,7 @@ mod tests {
17621759
options: SortOptions::default(),
17631760
}];
17641761

1765-
let mut group_acc = FirstPrimitiveGroupsAccumulator::<Int64Type>::try_new(
1762+
let mut group_acc = PrimitiveGroupsAccumulator::<Int64Type>::try_new(
17661763
sort_keys.into(),
17671764
true,
17681765
&DataType::Int64,
@@ -1843,7 +1840,7 @@ mod tests {
18431840
options: SortOptions::default(),
18441841
}];
18451842

1846-
let mut group_acc = FirstPrimitiveGroupsAccumulator::<Int64Type>::try_new(
1843+
let mut group_acc = PrimitiveGroupsAccumulator::<Int64Type>::try_new(
18471844
sort_keys.into(),
18481845
true,
18491846
&DataType::Int64,

0 commit comments

Comments
 (0)