-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix incorrect lazy schema for explode()
in agg()
#19623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,7 @@ fn create_physical_expr_inner( | |
// TODO! Order by | ||
let group_by = create_physical_expressions_from_nodes( | ||
partition_by, | ||
Context::Default, | ||
Context::Aggregation, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is under |
||
expr_arena, | ||
schema, | ||
state, | ||
|
@@ -473,10 +473,13 @@ fn create_physical_expr_inner( | |
options, | ||
} => { | ||
let is_scalar = is_scalar_ae(expression, expr_arena); | ||
let output_dtype = | ||
let mut output_field = | ||
expr_arena | ||
.get(expression) | ||
.to_field(schema, Context::Default, expr_arena)?; | ||
if let Context::Aggregation = ctxt { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just pass the context to line 497 instead of updating the dtype here. |
||
output_field.dtype = DataType::List(Box::new(output_field.dtype)); | ||
} | ||
|
||
let is_reducing_aggregation = options.flags.contains(FunctionFlags::RETURNS_SCALAR) | ||
&& matches!(options.collect_groups, ApplyOptions::GroupWise); | ||
|
@@ -501,21 +504,24 @@ fn create_physical_expr_inner( | |
*options, | ||
state.allow_threading, | ||
schema.clone(), | ||
output_dtype, | ||
output_field, | ||
is_scalar, | ||
))) | ||
}, | ||
Function { | ||
input, | ||
function, | ||
options, | ||
.. | ||
} => { | ||
let is_scalar = is_scalar_ae(expression, expr_arena); | ||
let output_field = | ||
let mut output_field = | ||
expr_arena | ||
.get(expression) | ||
.to_field(schema, Context::Default, expr_arena)?; | ||
if let Context::Aggregation = ctxt { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||
output_field.dtype = DataType::List(Box::new(output_field.dtype)); | ||
} | ||
|
||
let is_reducing_aggregation = options.flags.contains(FunctionFlags::RETURNS_SCALAR) | ||
&& matches!(options.collect_groups, ApplyOptions::GroupWise); | ||
// Will be reset in the function so get that here. | ||
|
@@ -565,9 +571,15 @@ fn create_physical_expr_inner( | |
move |c: &mut [polars_core::frame::column::Column]| c[0].explode().map(Some), | ||
) as Arc<dyn ColumnsUdf>); | ||
|
||
let field = expr_arena | ||
.get(expression) | ||
.to_field(schema, ctxt, expr_arena)?; | ||
let mut field = | ||
expr_arena | ||
.get(expression) | ||
.to_field(schema, Context::Default, expr_arena)?; | ||
|
||
if let Context::Aggregation = ctxt { | ||
field.dtype = DataType::List(Box::new(field.dtype)); | ||
} | ||
|
||
Ok(Arc::new(ApplyExpr::new( | ||
vec![input], | ||
function, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,6 @@ impl AExpr { | |
}, | ||
Explode(expr) => { | ||
let field = arena.get(*expr).to_field_impl(schema, arena, nested)?; | ||
*nested = nested.saturating_sub(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix for the linked issue |
||
|
||
if let List(inner) = field.dtype() { | ||
Ok(Field::new(field.name().clone(), *inner.clone())) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the output field of the expression should created in an aggregation-context-aware manner, so I've updated this assertion.