kosiew commented on code in PR #19370:
URL: https://github.com/apache/datafusion/pull/19370#discussion_r2639289304
##########
datafusion/datasource/src/write/demux.rs:
##########
@@ -228,6 +232,19 @@ async fn row_count_demuxer(
next_send_steam = (next_send_steam + 1) % minimum_parallel_files;
}
+
+ // if there is no batch send but with a single file, send an empty batch
+ if single_file_output && !is_batch_received {
Review Comment:
The `DataFrameWriteOptions::with_single_file_output()` method should also be
updated about empty DataFrame behavior.
##########
datafusion/core/src/datasource/file_format/json.rs:
##########
@@ -349,4 +349,42 @@ mod tests {
fn fmt_batches(batches: &[RecordBatch]) -> String {
pretty::pretty_format_batches(batches).unwrap().to_string()
}
+
+ #[tokio::test]
+ async fn test_write_empty_json_from_sql() -> Result<()> {
+ let ctx = SessionContext::new();
+ let tmp_dir = tempfile::TempDir::new()?;
+ let path = format!("{}/empty_sql.json",
tmp_dir.path().to_string_lossy());
+ let df = ctx.sql("SELECT CAST(1 AS BIGINT) AS id LIMIT 0").await?;
+ df.write_json(&path, crate::dataframe::DataFrameWriteOptions::new(),
None)
+ .await?;
+ // Expected the file to exist
+ assert!(std::path::Path::new(&path).exists());
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn test_write_empty_json_from_record_batch() -> Result<()> {
Review Comment:
The test functions `test_write_empty_*_from_sql` and
`test_write_empty_*_from_record_batch` share nearly identical structure across
csv, json, parquet, arrow file formats.
If we extract a generic test helper in a common test utilities module, this
would reduce maintenance burden of updating 4 separate locations.
--
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]