This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 7ce9b6ea06 docs: `Window::try_new_with_schema` with a descriptive 
error message (#17926)
7ce9b6ea06 is described below

commit 7ce9b6ea06d7962595920f5ae86efbb73e4f9590
Author: Khanh Duong <[email protected]>
AuthorDate: Wed Oct 8 04:26:38 2025 +0900

    docs: `Window::try_new_with_schema` with a descriptive error message 
(#17926)
---
 datafusion/expr/src/logical_plan/plan.rs | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/datafusion/expr/src/logical_plan/plan.rs 
b/datafusion/expr/src/logical_plan/plan.rs
index 3cc0322774..b8200ab8a4 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -2543,16 +2543,22 @@ impl Window {
         )
     }
 
+    /// Create a new window function using the provided schema to avoid the 
overhead of
+    /// building the schema again when the schema is already known.
+    ///
+    /// This method should only be called when you are absolutely sure that 
the schema being
+    /// provided is correct for the window function. If in doubt, call 
[try_new](Self::try_new) instead.
     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() {
+        let input_fields_count = input.schema().fields().len();
+        if schema.fields().len() != input_fields_count + window_expr.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()
+                "Window schema has wrong number of fields. Expected {} got {}",
+                input_fields_count + window_expr.len(),
+                schema.fields().len()
             );
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to