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

(auron) branch master updated: [AURON #2569] Fix WindowGroupLimit fusion with multiple window expressions (#2570)

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

slfan1989 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/auron.git


The following commit(s) were added to refs/heads/master by this push:
     new 24563488 [AURON #2569] Fix WindowGroupLimit fusion with multiple window expressions (#2570)
24563488 is described below

commit 245634882d35abfb6e0945ed4573cbf82adb3bf5
Author: linfeng <33...@users.noreply.github.com>
AuthorDate: Sat Oct 17 08:28:17 2026 +0800

    [AURON #2569] Fix WindowGroupLimit fusion with multiple window expressions (#2570)
    
    # Which issue does this PR close?
    
    Closes #2569
    
    # Rationale for this change
    
    Native execution can fail when a window containing multiple expressions
    is fused with `WindowGroupLimit`. The fused operator produces multiple
    window columns, but group-limit filtering requires exactly one, causing
    an assertion failure.
    
    # What changes are included in this PR?
    
    - Allow fusion only when the upper window contains exactly one rank-like
    expression; otherwise, execute the operators separately.
    - Add a regression test with a lower `RANK <= 2` limit and an upper
    window computing `RANK` and `ROW_NUMBER`, including tied ordering
    values.
    
    # Are there any user-facing changes?
    
    Queries with multiple ranking functions and a rank filter now execute
    correctly.
    
    # How was this patch tested?
    
    - Add a regression test verifying correct results for multiple ranking
    expressions above WindowGroupLimit.
    
    # Was this patch authored or co-authored using generative AI tooling?
    - [x] Yes
    - [ ] No
    
    If yes, include: `Generated-by: OpenAI Codex (GPT-6)`
    
    ASF guidance: https://www.apache.org/legal/generative-tooling.html
---
 .../datafusion-ext-plans/src/window/mod.rs         |  4 ++
 .../datafusion-ext-plans/src/window_exec.rs        | 70 +++++++++++++++++++++-
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/native-engine/datafusion-ext-plans/src/window/mod.rs b/native-engine/datafusion-ext-plans/src/window/mod.rs
index f22772b6..f83a3654 100644
--- a/native-engine/datafusion-ext-plans/src/window/mod.rs
+++ b/native-engine/datafusion-ext-plans/src/window/mod.rs
@@ -112,6 +112,10 @@ impl WindowExpr {
         }
     }
 
+    pub fn is_rank_like(&self) -> bool {
+        matches!(self.func, WindowFunction::RankLike(_))
+    }
+
     pub fn requires_full_partition(&self) -> bool {
         matches!(
             self.func,
diff --git a/native-engine/datafusion-ext-plans/src/window_exec.rs b/native-engine/datafusion-ext-plans/src/window_exec.rs
index 1edbe1b6..d30d4601 100644
--- a/native-engine/datafusion-ext-plans/src/window_exec.rs
+++ b/native-engine/datafusion-ext-plans/src/window_exec.rs
@@ -164,9 +164,11 @@ impl ExecutionPlan for WindowExec {
         partition: usize,
         context: Arc<TaskContext>,
     ) -> Result<SendableRecordBatchStream> {
-        // combine WindowGroupLimitExec -> WindowExec
+        // Combining group limit filtering requires exactly one rank-like output column.
         if let Ok(window_group_limit) = downcast_any!(&self.input, WindowExec)
             && window_group_limit.window_context().group_limit.is_some()
+            && self.context.window_exprs.len() == 1
+            && self.context.window_exprs[0].is_rank_like()
         {
             let combined = Arc::new(Self {
                 input: window_group_limit.input.clone(),
@@ -790,6 +792,72 @@ mod test {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn test_window_group_limit_with_multiple_rank_functions()
+    -> Result<(), Box<dyn std::error::Error>> {
+        let task_ctx = SessionContext::new().task_ctx();
+        let input = build_table(
+            ("a1", &vec![1, 1, 1, 1, 2, 3, 3]),
+            ("b1", &vec![1, 2, 2, 3, 4, 1, 1]),
+            ("c1", &vec![0, 0, 0, 0, 0, 0, 0]),
+        )?;
+        let window_exprs = vec![
+            WindowExpr::new(
+                WindowFunction::RankLike(WindowRankType::Rank),
+                vec![],
+                Arc::new(Field::new("rank", DataType::Int32, false)),
+                DataType::Int32,
+            ),
+            WindowExpr::new(
+                WindowFunction::RankLike(WindowRankType::RowNumber),
+                vec![],
+                Arc::new(Field::new("row_number", DataType::Int32, false)),
+                DataType::Int32,
+            ),
+        ];
+        let group_limit = Arc::new(WindowExec::try_new(
+            input,
+            vec![window_exprs[0].clone()],
+            vec![Arc::new(Column::new("a1", 0))],
+            vec![PhysicalSortExpr {
+                expr: Arc::new(Column::new("b1", 1)),
+                options: Default::default(),
+            }],
+            Some(2),
+            false,
+        )?);
+        let window = WindowExec::try_new(
+            group_limit,
+            window_exprs,
+            vec![Arc::new(Column::new("a1", 0))],
+            vec![PhysicalSortExpr {
+                expr: Arc::new(Column::new("b1", 1)),
+                options: Default::default(),
+            }],
+            None,
+            true,
+        )?;
+
+        let batches =
+            datafusion::physical_plan::common::collect(window.execute(0, task_ctx)?).await?;
+        assert_batches_eq!(
+            [
+                "+----+----+----+------+------------+",
+                "| a1 | b1 | c1 | rank | row_number |",
+                "+----+----+----+------+------------+",
+                "| 1  | 1  | 0  | 1    | 1          |",
+                "| 1  | 2  | 0  | 2    | 2          |",
+                "| 1  | 2  | 0  | 2    | 3          |",
+                "| 2  | 4  | 0  | 1    | 1          |",
+                "| 3  | 1  | 0  | 1    | 1          |",
+                "| 3  | 1  | 0  | 1    | 2          |",
+                "+----+----+----+------+------------+",
+            ],
+            &batches
+        );
+        Ok(())
+    }
+
     #[tokio::test]
     async fn test_window_lead_across_batches() -> Result<(), Box<dyn std::error::Error>> {
         let session_ctx = SessionContext::new();