Skip to content

Commit 45e1027

Browse files
committed
test: folder contains empty csv files (with header) and normal files
1 parent 9523450 commit 45e1027

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

datafusion/core/src/datasource/file_format/csv.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,48 @@ mod tests {
876876
Ok(())
877877
}
878878

879+
/// Read multiple csv files (some are empty) with header
880+
///
881+
/// some_empty_with_header
882+
/// ├── a_empty.csv
883+
/// ├── b.csv
884+
/// └── c_nulls_column.csv
885+
///
886+
/// a_empty.csv:
887+
/// c1,c2,c3
888+
///
889+
/// b.csv:
890+
/// c1,c2,c3
891+
/// 1,1,1
892+
/// 2,2,2
893+
///
894+
/// c_nulls_column.csv:
895+
/// c1,c2,c3
896+
/// 3,3,
897+
#[tokio::test]
898+
async fn test_csv_some_empty_with_header() -> Result<()> {
899+
let ctx = SessionContext::new();
900+
ctx.register_csv(
901+
"some_empty_with_header",
902+
"tests/data/empty_files/some_empty_with_header",
903+
CsvReadOptions::new().has_header(true),
904+
)
905+
.await?;
906+
907+
let query = "select sum(c3) from some_empty_with_header;";
908+
let query_result = ctx.sql(query).await?.collect().await?;
909+
910+
assert_snapshot!(batches_to_string(&query_result),@r"
911+
+--------------------------------+
912+
| sum(some_empty_with_header.c3) |
913+
+--------------------------------+
914+
| 3 |
915+
+--------------------------------+
916+
");
917+
918+
Ok(())
919+
}
920+
879921
#[tokio::test]
880922
async fn test_csv_extension_compressed() -> Result<()> {
881923
// Write compressed CSV files
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c1,c2,c3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
c1,c2,c3
2+
1,1,1
3+
2,2,2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
c1,c2,c3
2+
3,3,

0 commit comments

Comments
 (0)