Skip to content

fix: preserve COPY TO format options during plan serialization - #27825

Open
Ilhan-Personal wants to merge 3 commits into
apache:mainfrom
Ilhan-Personal:ilu/preserve-copy-top-options
Open

Ilhan-Personal wants to merge 3 commits into
apache:mainfrom
Ilhan-Personal:ilu/preserve-copy-top-options

Conversation

@Ilhan-Personal

Copy link
Copy Markdown

Important

Fork CI setup: For pull requests from a fork to main, enable workflows in your fork's Actions tab before you push.
See the fork CI setup guide.

Which issue does this PR close?

Related to apache/datafusion-ballista#2966.

Rationale for this change

The same COPY TO CSV statement can write different files depending on how it runs. For example, a user who requests no header and no quotes gets the expected output when running DataFusion directly. When Ballista sends the query to its scheduler, the file includes a header and every field is quoted. The CSV should honor the user’s settings in both cases. See apache/datafusion-ballista#2966.

What changes are included in this PR?

  • Preserve the selected CSV quoting mode when sending a plan. Previously, “quote only when needed” could become “quote every field.”
  • Pass SQL format options to CSV, JSON, and Parquet writers using the names they expect, such as has_header for format.has_header.
  • Handle execution.keep_partition_by_columns in the planner so file writers don’t reject it as an unknown option.

What is the testing strategy for this PR?

The regression test executes the same COPY plan directly and after a protobuf round trip, then compares the CSV files byte for byte. It covers default quoting, Never with headers disabled, NonNumeric, and execution.keep_partition_by_columns. A separate assertion checks that an explicitly configured Always quote style survives serialisation.

Are there any user-facing changes?

Yes. A serialized COPY TO CSV plan now writes the same header and quoting as direct execution. For example, format.has_header = false and format.quote_style = Never produce an unquoted data row with no header in both cases.

@github-actions github-actions Bot added core Core DataFusion crate proto Related to proto crate datasource Changes to the datasource crate labels Nov 28, 2026
@Ilhan-Personal
Ilhan-Personal force-pushed the ilu/preserve-copy-top-options branch from 871106d to 5aa52b7 Compare November 28, 2026 13:47
@Ilhan-Personal Ilhan-Personal changed the title Ilu/preserve copy top options fix: preserve format options when sending plan Nov 28, 2026
@Ilhan-Personal Ilhan-Personal changed the title fix: preserve format options when sending plan fix: preserve COPY TO format options during plan serialization Nov 28, 2026
let mut parquet_options = parquet_options.clone();
for (k, v) in format_options {
parquet_options.set(k, v)?;
parquet_options.set(k.strip_prefix("format.").unwrap_or(k), v)?;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I couldn't find an existing constant to reuse here

the SQL planner builds keys with format!("format.{key}") so I'm just following existing convention

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

Labels

core Core DataFusion crate datasource Changes to the datasource crate proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY TO CSV ignores format options after a logical plan protobuf round trip

1 participant