@@ -325,6 +325,60 @@ mod integration_tests {
325325 Ok ( ( ) )
326326 }
327327
328+ /// Test that a table with all rows deleted returns 0 rows
329+ ///
330+ /// This is the bug scenario from https://github.com/hotdata-dev/datafusion-ducklake/issues/30
331+ /// When all rows are deleted from a table, querying should return 0 rows.
332+ #[ tokio:: test]
333+ async fn test_table_with_all_rows_deleted ( ) -> DataFusionResult < ( ) > {
334+ let temp_dir = TempDir :: new ( )
335+ . map_err ( |e| datafusion:: error:: DataFusionError :: External ( Box :: new ( e) ) ) ?;
336+ let catalog_path = temp_dir. path ( ) . join ( "all_deleted.ducklake" ) ;
337+
338+ // Generate test data - inserts a row, then deletes it
339+ common:: create_catalog_empty_table ( & catalog_path) . map_err ( common:: to_datafusion_error) ?;
340+
341+ let catalog = create_catalog ( & catalog_path. to_string_lossy ( ) ) ?;
342+
343+ let ctx = SessionContext :: new ( ) ;
344+ ctx. register_catalog ( "all_deleted" , catalog) ;
345+
346+ // Query the table - should return 0 rows since all data was deleted
347+ let df = ctx
348+ . sql ( "SELECT * FROM all_deleted.main.tbl" )
349+ . await ?;
350+ let results = df. collect ( ) . await ?;
351+
352+ let total_rows: usize = results. iter ( ) . map ( |b| b. num_rows ( ) ) . sum ( ) ;
353+ assert_eq ! (
354+ total_rows, 0 ,
355+ "Table with all rows deleted should return 0 rows, but got {}" ,
356+ total_rows
357+ ) ;
358+
359+ // Also verify COUNT(*) returns 0
360+ let df = ctx
361+ . sql ( "SELECT COUNT(*) as cnt FROM all_deleted.main.tbl" )
362+ . await ?;
363+ let results = df. collect ( ) . await ?;
364+
365+ assert ! ( !results. is_empty( ) ) ;
366+ let batch = & results[ 0 ] ;
367+ let counts = batch
368+ . column ( 0 )
369+ . as_any ( )
370+ . downcast_ref :: < Int64Array > ( )
371+ . unwrap ( ) ;
372+
373+ assert_eq ! (
374+ counts. value( 0 ) ,
375+ 0 ,
376+ "COUNT(*) should be 0 after all rows deleted"
377+ ) ;
378+
379+ Ok ( ( ) )
380+ }
381+
328382 /// Test filter pushdown correctness with delete files
329383 ///
330384 /// This test verifies that WHERE filters are applied AFTER delete filtering,
0 commit comments