You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/09/05 10:23:00 UTC

(datafusion) branch gh-readonly-queue/main/pr-24750-35f58f53cde2f634c21f6370e385cf1d7e9bc55c created (now 293f5ebda4)

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

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-24750-35f58f53cde2f634c21f6370e385cf1d7e9bc55c
in repository https://gitbox.apache.org/repos/asf/datafusion.git


      at 293f5ebda4 fix: prevent CSE from extracting window functions (#24750)

This branch includes the following new commits:

     new 293f5ebda4 fix: prevent CSE from extracting window functions (#24750)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion) 01/01: fix: prevent CSE from extracting window functions (#24750)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-24750-35f58f53cde2f634c21f6370e385cf1d7e9bc55c
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit 293f5ebda41888c0ef3718f4153a144e11c2ae1d
Author: Christian Del Monte <ch...@posteo.de>
AuthorDate: Sat Sep 5 10:22:37 2026 +0000

    fix: prevent CSE from extracting window functions (#24750)
    
    ## Which issue does this PR close?
    
    - Closes #15190
    
    ## Rationale for this change
    
    Common subexpression elimination can extract duplicated window functions
    into an intermediate Projection. Since window functions cannot be
    evaluated by a projection, this produces a plan that fails during
    physical planning.
    
    ## What changes are included in this PR?
    
    Exclude WindowFunction expressions themselves from CSE extraction and
    add a regression test.
    
    ## Are these changes tested?
    
    Yes. A regression test verifies that duplicated window functions remain
    in the WindowAggr node.
    
    ## Are there any user-facing changes?
    
    Queries affected by #15190 no longer fail during physical planning. No
    documentation changes are required.
---
 datafusion/core/tests/dataframe/mod.rs               | 17 +++++++++++++++++
 datafusion/optimizer/src/common_subexpr_eliminate.rs | 19 +++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/datafusion/core/tests/dataframe/mod.rs b/datafusion/core/tests/dataframe/mod.rs
index 527c956749..4e32ea3116 100644
--- a/datafusion/core/tests/dataframe/mod.rs
+++ b/datafusion/core/tests/dataframe/mod.rs
@@ -206,6 +206,23 @@ async fn with_column_window_functions() -> DataFusionResult<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn duplicated_window_functions_can_be_executed() -> Result<()> {
+    let wexpr = datafusion::functions_window::row_number::row_number_udwf().call(vec![]);
+
+    let plan = LogicalPlanBuilder::empty(true)
+        .window(vec![wexpr.clone(), wexpr.alias("aliased")])?
+        .build()?;
+
+    let ctx = SessionContext::new();
+
+    let collected = DataFrame::new(ctx.state(), plan).collect().await?;
+
+    assert_eq!(collected.iter().map(|b| b.num_rows()).sum::<usize>(), 1);
+
+    Ok(())
+}
+
 #[tokio::test]
 async fn test_coalesce_schema() -> Result<()> {
     let ctx = SessionContext::new();
diff --git a/datafusion/optimizer/src/common_subexpr_eliminate.rs b/datafusion/optimizer/src/common_subexpr_eliminate.rs
index 6004ccb86e..9a9ffc36a1 100644
--- a/datafusion/optimizer/src/common_subexpr_eliminate.rs
+++ b/datafusion/optimizer/src/common_subexpr_eliminate.rs
@@ -733,6 +733,7 @@ impl CSEController for ExprCSEController<'_> {
                 | Expr::Wildcard { .. }
                 | Expr::Lambda(_)
                 | Expr::LambdaVariable(_)
+                | Expr::WindowFunction(..)
         );
 
         let is_aggr = matches!(node, Expr::AggregateFunction(..));
@@ -857,6 +858,7 @@ mod test {
     use crate::test::udfs::leaf_udf_expr;
     use crate::test::*;
     use datafusion_expr::test::function_stub::{avg, sum};
+    use datafusion_functions_window::row_number::row_number_udwf;
 
     macro_rules! assert_optimized_plan_equal {
         (
@@ -1933,4 +1935,21 @@ mod test {
         "
         )
     }
+
+    #[test]
+    fn test_window_function_is_not_extracted() -> Result<()> {
+        let wexpr = row_number_udwf().call(vec![]);
+
+        let plan = LogicalPlanBuilder::empty(true)
+            .window(vec![wexpr.clone(), wexpr.alias("aliased")])?
+            .build()?;
+
+        assert_optimized_plan_equal!(
+            plan,
+            @r"
+        WindowAggr: windowExpr=[[row_number() ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING, row_number() ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING AS aliased]]
+          EmptyRelation: rows=1
+        "
+        )
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org