houqp commented on a change in pull request #571:
URL: https://github.com/apache/arrow-datafusion/pull/571#discussion_r656791849
##########
File path: datafusion/src/physical_plan/planner.rs
##########
@@ -283,7 +322,7 @@ impl DefaultPhysicalPlanner {
Ok(Arc::new(WindowAggExec::try_new(
window_expr,
input_exec.clone(),
- physical_input_schema,
+ input_exec.schema(),
Review comment:
we should be able to take ownership of `physical_input_schema` here
instead of calling into `schema()` right?
##########
File path: datafusion/src/physical_plan/planner.rs
##########
@@ -265,8 +266,46 @@ impl DefaultPhysicalPlanner {
}
let input_exec = self.create_initial_plan(input, ctx_state)?;
- let physical_input_schema = input_exec.schema();
- let logical_input_schema = input.as_ref().schema();
+
+ // at this moment we are guaranteed by the logical planner
+ // to have all the window_expr to have equal sort key
+ let sort_keys = match window_expr[0] {
+ Expr::WindowFunction {
+ ref partition_by,
+ ref order_by,
+ ..
+ } => generate_sort_key(partition_by, order_by),
+ _ => unreachable!(),
+ };
+
+ let input_exec = if sort_keys.is_empty() {
+ input_exec
+ } else {
+ let sort_keys = sort_keys
+ .iter()
+ .map(|e| match e {
+ Expr::Sort {
+ expr,
+ asc,
+ nulls_first,
+ } => self.create_physical_sort_expr(
+ expr,
+ input.schema(),
+ &input_exec.schema(),
Review comment:
same here, we could avoid `schema()` call by reusing
`&physical_input_schema`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]