You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "PiotrSrebrny (via GitHub)" <gi...@apache.org> on 2026/05/12 13:52:55 UTC

Re: [PR] fix missing window expressions when unparsing plans without outer projections [datafusion]

PiotrSrebrny commented on code in PR #21801:
URL: https://github.com/apache/datafusion/pull/21801#discussion_r3226941605


##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
@@ -2848,6 +2849,253 @@ fn test_unparse_window() -> Result<()> {
     Ok(())
 }
 
+#[test]
+fn test_unparse_window_over_aggregate_without_projection() -> Result<()> {
+    let schema = Schema::new(vec![
+        Field::new("time", DataType::Int64, false),
+        Field::new("value", DataType::Float64, true),
+    ]);
+    let window_expr = Expr::WindowFunction(Box::new(WindowFunction {
+        fun: WindowFunctionDefinition::WindowUDF(row_number_udwf()),
+        params: WindowFunctionParams {
+            args: vec![],
+            partition_by: vec![],
+            order_by: vec![col("time").sort(true, true)],
+            window_frame: WindowFrame::new(None),
+            null_treatment: None,
+            distinct: false,
+            filter: None,
+        },
+    }))
+    .alias("row_idx");
+    let plan = table_scan(Some("gas"), &schema, None)?
+        .aggregate(vec![col("time")], vec![sum(col("value")).alias("sum_n")])?
+        .window(vec![window_expr])?

Review Comment:
   I tried to access the row_idx column here in a filter just by inserting this expression:
   ```
   .filter(col("row_idx").eq(lit(0i64)))?
   ```
   and the unparser fails with this error: Error: Internal("Tried to unproject agg expr for column 'row_idx' that was not found in the provided Aggregate!")
   
   when accessing the "sum_n" column there is no problem. 



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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