Skip to content

Commit 18b3fae

Browse files
committed
Comment adjustment and addressed some warnings
1 parent 7c71b24 commit 18b3fae

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

datafusion/src/cube_ext/joinagg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::logical_plan::{DFSchemaRef, Expr, LogicalPlan, UserDefinedLogicalNode
2626
use crate::optimizer::optimizer::OptimizerRule;
2727
use crate::optimizer::utils::from_plan;
2828
use crate::physical_plan::hash_aggregate::{
29-
create_accumulation_state, AccumulationState, Accumulators, AggregateMode,
29+
create_accumulation_state, AggregateMode,
3030
};
3131
use crate::physical_plan::planner::{physical_name, ExtensionPlanner};
3232
use crate::physical_plan::{hash_aggregate, PhysicalPlanner};

datafusion/src/physical_plan/expressions/average.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::sync::Arc;
2323

2424
use crate::error::{DataFusionError, Result};
2525
use crate::physical_plan::groups_accumulator::GroupsAccumulator;
26-
use crate::physical_plan::groups_accumulator_adapter::GroupsAccumulatorAdapter;
2726
use crate::physical_plan::groups_accumulator_flat_adapter::GroupsAccumulatorFlatAdapter;
2827
use crate::physical_plan::{Accumulator, AggregateExpr, PhysicalExpr};
2928
use crate::scalar::ScalarValue;

datafusion/src/physical_plan/expressions/sum.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::sync::Arc;
2323

2424
use crate::error::{DataFusionError, Result};
2525
use crate::physical_plan::groups_accumulator::GroupsAccumulator;
26-
use crate::physical_plan::groups_accumulator_adapter::GroupsAccumulatorAdapter;
2726
use crate::physical_plan::groups_accumulator_flat_adapter::GroupsAccumulatorFlatAdapter;
2827
use crate::physical_plan::{Accumulator, AggregateExpr, PhysicalExpr};
2928
use crate::scalar::ScalarValue;
@@ -45,7 +44,7 @@ use super::format_state_name;
4544
use smallvec::smallvec;
4645
use smallvec::SmallVec;
4746

48-
// SUM aggregate expression
47+
/// SUM aggregate expression
4948
#[derive(Debug)]
5049
pub struct Sum {
5150
name: String,

datafusion/src/physical_plan/groups_accumulator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ pub trait GroupsAccumulator: Send {
155155
total_num_groups: usize,
156156
) -> Result<()>;
157157

158-
/// update_batch but where group_indices is already ordered into adjacent groups. `offsets` has
159-
/// the group boundaries, and note that `offsets[0] == 0` (and the last offset is
160-
/// `group_indices.len()`).
158+
/// update_batch but where group_indices is already clumped into groups. `offsets` has the
159+
/// group boundaries, and note that `offsets[0] == 0` (and the last offset is
160+
/// `group_indices.len()`). So offsets[i] .. offsets[i + 1] is a half-open interval of equal
161+
/// group indices.
161162
fn update_batch_preordered(
162163
&mut self,
163164
values: &[ArrayRef],

datafusion/src/physical_plan/groups_accumulator_adapter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
//! Utilities for implementing GroupsAccumulator
1919
//! Adapter that makes [`GroupsAccumulator`] out of [`Accumulator`]
2020
21-
use std::mem::{size_of, size_of_val};
21+
use std::mem::size_of;
22+
// use std::mem::size_of_val; // TODO: Remove commented Accumulator::size() code?
2223

2324
use crate::arrow_datafusion_err;
2425
use crate::error::{DataFusionError, Result};
@@ -252,8 +253,8 @@ impl GroupsAccumulatorAdapter {
252253
// RecordBatch(es)
253254
let iter = groups_with_rows.iter().zip(offsets.windows(2));
254255

255-
let mut sizes_pre = 0;
256-
let mut sizes_post = 0;
256+
// let mut sizes_pre = 0;
257+
// let mut sizes_post = 0;
257258
for (&group_idx, offsets) in iter {
258259
let state = &mut self.states[group_idx];
259260
// sizes_pre += state.size(); // TODO: Add Accumulator::size?
@@ -331,7 +332,7 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {
331332

332333
let results: Vec<ScalarValue> = states
333334
.into_iter()
334-
.map(|mut state| {
335+
.map(|state| {
335336
// self.free_allocation(state.size()); // TODO: Add Accumulator::size?
336337
state.accumulator.evaluate()
337338
})
@@ -357,7 +358,7 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {
357358
// which we need to form into columns
358359
let mut results: Vec<Vec<ScalarValue>> = vec![];
359360

360-
for mut state in states {
361+
for state in states {
361362
// self.free_allocation(state.size()); // TODO: Add Accumulator::size?
362363
let accumulator_state = state.accumulator.state()?;
363364
results.resize_with(accumulator_state.len(), Vec::new);

datafusion/src/physical_plan/groups_accumulator_flat_adapter.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
//! Utilities for implementing GroupsAccumulator
1919
//! Adapter that makes [`GroupsAccumulator`] out of [`Accumulator`]
2020
21-
use std::mem::{size_of, size_of_val};
21+
use std::mem::size_of;
22+
// use std::mem::size_of_val; // TODO: Remove commented Accumulator::size() code?
2223

2324
use crate::arrow_datafusion_err;
2425
use crate::error::{DataFusionError, Result};
@@ -189,8 +190,8 @@ impl<AccumulatorType: Accumulator> GroupsAccumulatorFlatAdapter<AccumulatorType>
189190
"asserting values[0].len() == group_indices.len()"
190191
);
191192

192-
let mut sizes_pre = 0;
193-
let mut sizes_post = 0;
193+
// let mut sizes_pre = 0;
194+
// let mut sizes_post = 0;
194195
for offsets in offsets_param.windows(2) {
195196
let group_idx = group_indices[offsets[0]];
196197
let accumulator: &mut AccumulatorType = &mut self.accumulators[group_idx];
@@ -271,8 +272,8 @@ impl<AccumulatorType: Accumulator> GroupsAccumulatorFlatAdapter<AccumulatorType>
271272
// RecordBatch(es)
272273
let iter = groups_with_rows.iter().zip(offsets.windows(2));
273274

274-
let mut sizes_pre = 0;
275-
let mut sizes_post = 0;
275+
// let mut sizes_pre = 0;
276+
// let mut sizes_post = 0;
276277
for (&group_idx, offsets) in iter {
277278
// sizes_pre += state.size(); // TODO: Add Accumulator::size?
278279

@@ -373,7 +374,7 @@ impl<AccumulatorType: Accumulator> GroupsAccumulator
373374

374375
let results: Vec<ScalarValue> = accumulators
375376
.into_iter()
376-
.map(|mut accumulator| {
377+
.map(|accumulator| {
377378
// self.free_allocation(state.size()); // TODO: Add Accumulator::size?
378379
accumulator.evaluate()
379380
})
@@ -400,7 +401,7 @@ impl<AccumulatorType: Accumulator> GroupsAccumulator
400401
// which we need to form into columns
401402
let mut results: Vec<Vec<ScalarValue>> = vec![];
402403

403-
for mut accumulator in accumulators {
404+
for accumulator in accumulators {
404405
// self.free_allocation(state.size()); // TODO: Add Accumulator::size?
405406
let accumulator_state = accumulator.state()?;
406407
results.resize_with(accumulator_state.len(), Vec::new);

datafusion/src/physical_plan/hash_aggregate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,10 @@ pub type KeyVec = SmallVec<[u8; 64]>;
940940
type AccumulatorItem = Box<dyn Accumulator>;
941941
#[allow(missing_docs)]
942942
pub type AccumulatorSet = SmallVec<[AccumulatorItem; 2]>;
943-
pub type SpottyAccumulatorSet = SmallVec<[Option<AccumulatorItem>; 2]>; // TODO: Name?
943+
/// Not really a set. Order matters, as this is a parallel array with some GroupsAccumulator array.
944+
/// There are Nones in place where there is (in some AccumulationState, presumably) a groups
945+
/// accumulator in the parallel array.
946+
pub type SpottyAccumulatorSet = SmallVec<[Option<AccumulatorItem>; 2]>;
944947
#[allow(missing_docs)]
945948
pub type Accumulators = HashMap<KeyVec, AccumulationGroupState, RandomState>;
946949

datafusion/src/physical_plan/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ pub trait AggregateExpr: Send + Sync + Debug {
465465
/// return states with the same description as `state_fields`
466466
fn create_accumulator(&self) -> Result<Box<dyn Accumulator>>;
467467

468-
// TODO: Make create_accumulator just return a Result<Option<Box<..>>> with None in the case this is true.
469468
/// Returns true if and only if create_groups_accumulator returns Ok(Some(_)) (if not an Err(_)).
470469
fn uses_groups_accumulator(&self) -> bool {
471470
return false;

0 commit comments

Comments
 (0)