Skip to content

Conversation

bert-beyondloops
Copy link
Contributor

@bert-beyondloops bert-beyondloops commented Oct 15, 2025

Which issue does this PR close?

COPY TO does not produce a single output file for an empty set

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 file containing 0 rows will be created now

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) datasource Changes to the datasource crate labels Oct 15, 2025
};

// 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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rephrased it. Last sentence was indeed not complete.

@bert-beyondloops bert-beyondloops force-pushed the copy-to-empty-query-no-file branch from 09173f8 to 373f969 Compare October 16, 2025 08:35
@bert-beyondloops
Copy link
Contributor Author

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.

@bert-beyondloops bert-beyondloops changed the title Fix COPY TO does not produce single output file for zero rows query Fix COPY TO does not produce an output file for the empty set Oct 16, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @bert-beyondloops 🙏

The behavior of writing empty files has come up several times before and I worry we will go back and forth on the implementation if we don't have the expected results written down somewhere

Could you also please add some documentation to the top of this module / the demuxer tasks to make it clearer what behavior is expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY TO does not produce an output file for the empty set

3 participants