Skip to content

Commit

Permalink
implement final ApplyExpression state
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 26, 2021
1 parent 4299fce commit ab60e8d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion polars/polars-lazy/src/physical_plan/expressions/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,29 @@ impl PhysicalAggregation for ApplyExpr {
// if its flat, we just apply and return
// if not flat, the flattening sorts by group, so we must create new group tuples
// and again aggregate.
panic!("flat apply function with multiple inputs no yet implemented, but likely apply is a better fit anyway ;)")
let name = acs[0].series().name().to_string();

// get the flat representation of the aggregation contexts
let mut container = acs
.iter_mut()
.map(|ac| {
// this is hard because the flattening sorts by group
assert!(
ac.is_not_aggregated(),
"flat apply on any expression that is already \
in aggregated state is not yet suported"
);
ac.flat().into_owned()
})
.collect::<Vec<_>>();

let out = self.function.call_udf(&mut container)?;
let out = out.agg_list(acs[0].groups().as_ref()).map(|mut out| {
out.rename(&name);
out
});

Ok(out)
}
ApplyOptions::ApplyList => {
let mut s = acs
Expand Down

0 comments on commit ab60e8d

Please sign in to comment.