berkaysynnada opened a new issue, #14108: URL: https://github.com/apache/datafusion/issues/14108
### Describe the bug There is an `unreachable!()` block in `PushDownFilter` rule, where `LogicalPlan::Window` is being handled. https://github.com/apache/datafusion/blob/f9cc3325cdb5891b7566a6f3503c1f7ac6ad51e0/datafusion/optimizer/src/push_down_filter.rs#L1020 The following query enters there: ```rust pub(crate) const QUERY2: &str = " -- Define the subquery WITH SubQuery AS ( SELECT a.column1, a.column2 AS ts_column, a.column3, SUM(a.column3) OVER ( PARTITION BY a.column1 ORDER BY a.column2 RANGE BETWEEN INTERVAL '10 minutes' PRECEDING AND CURRENT ROW ) AS moving_sum FROM source_table a ) SELECT column1, ts_column, moving_sum FROM SubQuery WHERE moving_sum > 100 "; ``` ### To Reproduce ```rust #[tokio::test] async fn test_window_alias_in_subquery() -> Result<()> { let schema = Arc::new(Schema::new(vec![ Field::new("column1", DataType::Utf8, false), Field::new( "column2", DataType::Timestamp(TimeUnit::Nanosecond, None), false, ), Field::new("column3", DataType::Float64, false), ])); let column1 = Arc::new(StringArray::from(vec!["item1", "item2", "item1"])); let column2 = Arc::new(TimestampNanosecondArray::from(vec![ 1_000_000_000, 2_000_000_000, 3_000_000_000, ])); let column3 = Arc::new(Float64Array::from(vec![50.0, 30.0, 25.0])); let source_table = RecordBatch::try_new(schema.clone(), vec![column1, column2, column3])?; let mut ctx = SessionContext::new(); ctx.register_batch("source_table", source_table)?; let df = ctx.sql(QUERY2).await?; let results = df.collect().await?; for batch in results { println!("{:?}", batch); } Ok(()) } ``` ### Expected behavior It should work. ### Additional context This query works successfully: ```rust SELECT a.column1, a.column2 AS ts_column, a.column3, SUM(a.column3) OVER ( PARTITION BY a.column1 ORDER BY a.column2 RANGE BETWEEN INTERVAL '10 minutes' PRECEDING AND CURRENT ROW ) AS moving_sum FROM source_table a ``` However, if it becomes a subquery, then it starts to fail. Handling the alias expr in the `if let` part solves the problem, but I am not sure it is the correct way. -- 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]
