notfilippo opened a new issue, #11432: URL: https://github.com/apache/datafusion/issues/11432
### Describe the bug The function which parses the Preceding and Following expressions in window functions returns a `ScalarValue::Utf8`: https://github.com/apache/datafusion/blob/1dfac86a89750193491cf3e04917e37b92c64ffa/datafusion/expr/src/window_frame.rs#L364 I suspect that for unoptimized plans the `WindowFrameBound` containing a `ScalarValue::Utf8` gets directly passed to the substrait conversion logic, causing the fallback branch in the pattern match to execute and resulting to a `SubstraitBound::Unbounded`. https://github.com/apache/datafusion/blob/1dfac86a89750193491cf3e04917e37b92c64ffa/datafusion/substrait/src/logical_plan/producer.rs#L1824 Not sure if the fix should be developed in the substrait conversion logic or before. ### To Reproduce ```rust #[tokio::main] async fn main() -> datafusion::error::Result<()> { let ctx = SessionContext::new(); let schema = Schema::new(vec![ Field::new("salary", DataType::Int64, false), Field::new("empno", DataType::Int64, false), ]); let table = MemTable::try_new(Arc::new(schema), vec![])?; ctx.register_table("empsalary", Arc::new(table))?; let df = ctx .sql( "SELECT avg(salary) OVER(ORDER BY salary ASC ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS avg FROM empsalary ORDER BY empno", ) .await?; let plan = df.logical_plan(); let plan = datafusion_substrait::logical_plan::producer::to_substrait_plan(plan, &ctx)?; eprintln!("{:#?}", plan); Ok(()) } ``` ``` WindowFunction { function_reference: 0, arguments: [ ... ], invocation: Unspecified, partitions: [], bounds_type: Rows, lower_bound: Some( Bound { kind: Some( Unbounded( Unbounded, ), ), }, ), upper_bound: Some( Bound { kind: Some( Unbounded( Unbounded, ), ), }, ), args: [], }, ``` ### Expected behavior The bounds such as `BETWEEN 1 PRECEDING AND 1 FOLLOWING` should be correctly encoded in substrait. ### Additional context _No response_ -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
