Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions crates/polars-expr/src/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ impl<'a> AggregationContext<'a> {
self.det_groups_from_list(s.as_materialized_series());
},
}

match &self.state {
AggState::AggregatedList(_) | AggState::NotAggregated(_) => {},
AggState::AggregatedScalar(c) => {
assert_eq!(self.update_groups, UpdateGroups::No);
self.groups = Cow::Owned({
let groups = (0..c.len() as IdxSize).map(|i| [i, 1]).collect();
GroupsType::new_slice(groups, false, true).into_sliceable()
});
},
AggState::LiteralScalar(c) => {
assert_eq!(c.len(), 1);
assert_eq!(self.update_groups, UpdateGroups::No);
self.groups = Cow::Owned({
let groups = vec![[0, 1]; self.groups.len()];
GroupsType::new_slice(groups, true, true).into_sliceable()
});
},
}

&self.groups
}

Expand Down Expand Up @@ -638,26 +658,7 @@ impl<'a> AggregationContext<'a> {

/// Fixes groups for `AggregatedScalar` and `LiteralScalar` so that they point to valid
/// data elements in the `AggState` values.
fn set_groups_for_undefined_agg_states(&mut self) {
match &self.state {
AggState::AggregatedList(_) | AggState::NotAggregated(_) => {},
AggState::AggregatedScalar(c) => {
assert_eq!(self.update_groups, UpdateGroups::No);
self.groups = Cow::Owned({
let groups = (0..c.len() as IdxSize).map(|i| [i, 1]).collect();
GroupsType::new_slice(groups, false, true).into_sliceable()
});
},
AggState::LiteralScalar(c) => {
assert_eq!(c.len(), 1);
assert_eq!(self.update_groups, UpdateGroups::No);
self.groups = Cow::Owned({
let groups = vec![[0, 1]; self.groups.len()];
GroupsType::new_slice(groups, true, true).into_sliceable()
});
},
}
}
fn set_groups_for_undefined_agg_states(&mut self) {}

pub fn into_static(&self) -> AggregationContext<'static> {
let groups: GroupPositions = GroupPositions::to_owned(&self.groups);
Expand Down
Loading