Skip to content

Commit

Permalink
Add Window::try_new_from_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sadboy committed Mar 20, 2024
1 parent 237decd commit 4b7892a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,13 +2087,33 @@ impl Window {
window_func_dependencies.extend(new_deps);
}

Ok(Window {
input,
Self::try_new_with_schema(
window_expr,
schema: Arc::new(
input,
Arc::new(
DFSchema::new_with_metadata(window_fields, metadata)?
.with_functional_dependencies(window_func_dependencies)?,
),
)
}

pub fn try_new_with_schema(
window_expr: Vec<Expr>,
input: Arc<LogicalPlan>,
schema: DFSchemaRef,
) -> Result<Self> {
if window_expr.len() != schema.fields().len() - input.schema().fields().len() {
return plan_err!(
"Window has mismatch between number of expressions ({}) and number of fields in schema ({})",
window_expr.len(),
schema.fields().len() - input.schema().fields().len()
);
}

Ok(Window {
input,
window_expr,
schema,
})
}
}
Expand Down

0 comments on commit 4b7892a

Please sign in to comment.