You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "bert-beyondloops (via GitHub)" <gi...@apache.org> on 2025/10/15 12:12:46 UTC

[PR] Fix COPY TO does not produce single output file for zero rows query [datafusion]

bert-beyondloops opened a new pull request, #18074:
URL: https://github.com/apache/datafusion/pull/18074

   ## Which issue does this PR close?
   
   COPY TO does not produce a single output file for a zero rows query
   
   - Closes #18073
   
   ## Rationale for this change
   
   Executing following sql does not effectively create a single output file on disk :
   
   COPY (SELECT 1 AS id WHERE FALSE) TO 'table_no_rows.parquet';
   
   I would expect it creates a parquet file containing 0 rows including the schema metadata.
   
   The fact you can still query the schema of such a table is still valuable information.
   
   ## What changes are included in this PR?
   
   
   
   ## Are these changes tested?
   
   Additional COPY TO test added in the copy.slt sqllogictests
   
   ## Are there any user-facing changes?
   
   A zero rows file will be created now
   
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce single output file for zero rows query [datafusion]

Posted by "bert-beyondloops (via GitHub)" <gi...@apache.org>.
bert-beyondloops commented on PR #18074:
URL: https://github.com/apache/datafusion/pull/18074#issuecomment-3409844982

   Quick question about multi-file output behavior (non-partitioned case):
   
   Do we want to guarantee at least one file on disk here too?
   
   If so, we'd just need to remove the `if single_file_output {` condition from this PR.
   
   
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce an output file for the empty set [datafusion]

Posted by "bert-beyondloops (via GitHub)" <gi...@apache.org>.
bert-beyondloops commented on PR #18074:
URL: https://github.com/apache/datafusion/pull/18074#issuecomment-3421783755

   @alamb 
   
   I've added documentation clarifying the minimum number of files written for each output scenario.
   
   I believe that for non-partitioned multi-file output, we should respect the minimum_parallel_output_files setting. However, with partitioned output, we cannot pre-create files because the partition key values are unknown until data is processed.
   
   
   
   
   
   
   
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce an output file for the empty set [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #18074:
URL: https://github.com/apache/datafusion/pull/18074


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce single output file for zero rows query [datafusion]

Posted by "bert-beyondloops (via GitHub)" <gi...@apache.org>.
bert-beyondloops commented on code in PR #18074:
URL: https://github.com/apache/datafusion/pull/18074#discussion_r2435060620


##########
datafusion/datasource/src/write/demux.rs:
##########
@@ -171,6 +171,22 @@ async fn row_count_demuxer(
         max_rows_per_file
     };
 
+    // Single-file output requires creating at least one file stream in advance.
+    // If no record batches are present in the input stream (zero-row scenario),

Review Comment:
   rephrased it. Last sentence was indeed not complete.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce an output file for the empty set [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18074:
URL: https://github.com/apache/datafusion/pull/18074#discussion_r2448777187


##########
datafusion/datasource/src/write/demux.rs:
##########
@@ -68,6 +68,11 @@ pub type DemuxedStreamReceiver = UnboundedReceiver<(Path, RecordBatchReceiver)>;
 /// be written with the extension from the path. Otherwise the default extension
 /// will be used and the output will be split into multiple files.
 ///
+/// Output file guarantees:

Review Comment:
   👍 



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix COPY TO does not produce single output file for zero rows query [datafusion]

Posted by "pepijnve (via GitHub)" <gi...@apache.org>.
pepijnve commented on code in PR #18074:
URL: https://github.com/apache/datafusion/pull/18074#discussion_r2432378501


##########
datafusion/datasource/src/write/demux.rs:
##########
@@ -171,6 +171,22 @@ async fn row_count_demuxer(
         max_rows_per_file
     };
 
+    // Single-file output requires creating at least one file stream in advance.
+    // If no record batches are present in the input stream (zero-row scenario),

Review Comment:
   I think there might a bit missing from this comment. Sentence doesn't seem complete.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org