niebayes opened a new issue, #17269:
URL: https://github.com/apache/datafusion/issues/17269

   ### Describe the bug
   
   Applying a UDAF on an empty table would return a non-empty result, a single 
null value.
   
   ### To Reproduce
   
   I have written a simple test for reproducing the bug. For any UDAF, such as 
last_value and first_value, calling it on an empty table would give a result 
containing a non empty result.
   
   ``` Rust
   #[tokio::test]
       async fn test_last_value() {
           use std::sync::Arc;
   
           use arrow_array::RecordBatch;
           use arrow_schema::{DataType, Field, Schema};
           use datafusion::assert_batches_eq;
           use datafusion::physical_plan::collect;
           use datafusion::prelude::SessionContext;
   
           let schema = Arc::new(Schema::new(vec![
               Field::new("id", DataType::Int32, false),
               Field::new("value", DataType::Int32, false),
           ]));
           let batch = RecordBatch::new_empty(schema);
   
           let ctx = SessionContext::new();
           ctx.register_batch("t", batch).unwrap();
   
           let plan = ctx
               .sql("select last_value(value order by id) from t")
               .await
               .unwrap()
               .logical_plan()
               .clone();
           let exec_plan = 
ctx.state().create_physical_plan(&plan).await.unwrap();
           let batches = collect(exec_plan, ctx.task_ctx()).await.unwrap();
   
           assert_eq!(batches.iter().map(|b| b.num_rows()).sum::<usize>(), 1);
           assert_batches_eq!(
               &[
                   "+----------------------------------------------------+",
                   "| last_value(t.value) ORDER BY [t.id ASC NULLS LAST] |",
                   "+----------------------------------------------------+",
                   "|                                                    |",
                   "+----------------------------------------------------+",
               ],
               &batches
           );
       }
   ```
   
   ### Expected behavior
   
   Calling a UDAF on an empty table should given an empty result.
   
   ### 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]

Reply via email to