Skip to content

Commit 9157065

Browse files
hendrikmakaitsrh
authored andcommitted
Reduce size of Expr struct (apache#16207)
* First pass at incorporating boxed WindowFunction * Second pass * Adjust tests * cargo fmt * fmt * Add test * clippy * clippy * fmt * Adjust comments Backported from upstream DF 48 to cube-46.0.1 size_of::<Expr>() is now 128, whereas this patch in DF 48 makes it 144.
1 parent 17a38a4 commit 9157065

File tree

22 files changed

+492
-263
lines changed

22 files changed

+492
-263
lines changed

datafusion-examples/examples/advanced_udwf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl WindowUDFImpl for SimplifySmoothItUdf {
190190
/// default implementation will not be called (left as `todo!()`)
191191
fn simplify(&self) -> Option<WindowFunctionSimplification> {
192192
let simplify = |window_function: WindowFunction, _: &dyn SimplifyInfo| {
193-
Ok(Expr::WindowFunction(WindowFunction {
193+
Ok(Expr::from(WindowFunction {
194194
fun: WindowFunctionDefinition::AggregateUDF(avg_udaf()),
195195
params: WindowFunctionParams {
196196
args: window_function.params.args,

datafusion/core/src/physical_planner.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -568,27 +568,25 @@ impl DefaultPhysicalPlanner {
568568
let input_exec = children.one()?;
569569

570570
let get_sort_keys = |expr: &Expr| match expr {
571-
Expr::WindowFunction(WindowFunction {
572-
params:
573-
WindowFunctionParams {
574-
ref partition_by,
575-
ref order_by,
576-
..
577-
},
578-
..
579-
}) => generate_sort_key(partition_by, order_by),
571+
Expr::WindowFunction(window_fun) => {
572+
let WindowFunctionParams {
573+
ref partition_by,
574+
ref order_by,
575+
..
576+
} = &window_fun.as_ref().params;
577+
generate_sort_key(partition_by, order_by)
578+
}
580579
Expr::Alias(Alias { expr, .. }) => {
581580
// Convert &Box<T> to &T
582581
match &**expr {
583-
Expr::WindowFunction(WindowFunction {
584-
params:
585-
WindowFunctionParams {
586-
ref partition_by,
587-
ref order_by,
588-
..
589-
},
590-
..
591-
}) => generate_sort_key(partition_by, order_by),
582+
Expr::WindowFunction(window_fun) => {
583+
let WindowFunctionParams {
584+
ref partition_by,
585+
ref order_by,
586+
..
587+
} = &window_fun.as_ref().params;
588+
generate_sort_key(partition_by, order_by)
589+
}
592590
_ => unreachable!(),
593591
}
594592
}
@@ -1515,17 +1513,18 @@ pub fn create_window_expr_with_name(
15151513
let name = name.into();
15161514
let physical_schema: &Schema = &logical_schema.into();
15171515
match e {
1518-
Expr::WindowFunction(WindowFunction {
1519-
fun,
1520-
params:
1521-
WindowFunctionParams {
1522-
args,
1523-
partition_by,
1524-
order_by,
1525-
window_frame,
1526-
null_treatment,
1527-
},
1528-
}) => {
1516+
Expr::WindowFunction(window_fun) => {
1517+
let WindowFunction {
1518+
fun,
1519+
params:
1520+
WindowFunctionParams {
1521+
args,
1522+
partition_by,
1523+
order_by,
1524+
window_frame,
1525+
null_treatment,
1526+
},
1527+
} = window_fun.as_ref();
15291528
let physical_args =
15301529
create_physical_exprs(args, logical_schema, execution_props)?;
15311530
let partition_by =

datafusion/core/tests/dataframe/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ async fn window_using_aggregates() -> Result<()> {
887887
vec![col("c3")],
888888
);
889889

890-
Expr::WindowFunction(w)
890+
Expr::from(w)
891891
.null_treatment(NullTreatment::IgnoreNulls)
892892
.order_by(vec![col("c2").sort(true, true), col("c3").sort(true, true)])
893893
.window_frame(WindowFrame::new_bounds(
@@ -2567,7 +2567,7 @@ async fn test_count_wildcard_on_window() -> Result<()> {
25672567
let df_results = ctx
25682568
.table("t1")
25692569
.await?
2570-
.select(vec![Expr::WindowFunction(WindowFunction::new(
2570+
.select(vec![Expr::from(WindowFunction::new(
25712571
WindowFunctionDefinition::AggregateUDF(count_udaf()),
25722572
vec![Expr::Literal(COUNT_STAR_EXPANSION)],
25732573
))

0 commit comments

Comments
 (0)