Skip to content

Add write support to Avro format - #24925

Merged
kosiew merged 4 commits into
apache:mainfrom
pepijnve:avro_writer
Sep 10, 2026
Merged

kosiew merged 4 commits into
apache:mainfrom
pepijnve:avro_writer

Conversation

@pepijnve

@pepijnve pepijnve commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The avro integration was still missing the necessary glue code to support writing. This MR adds the missing bits.

What changes are included in this PR?

  • Adds a write physical plan in the avro file format

This MR was authored using Claude Code and subsequently reviewed by myself.

What is the testing strategy for this PR?

  • Added SLTs to verify Avro roundtripping
  • Manual testing

Are there any user-facing changes?

Yes, COPY ... TO ... STORED AS AVRO now works.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) datasource Changes to the datasource crate labels Sep 3, 2026
@codecov-commenter

codecov-commenter commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.45161% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.74%. Comparing base (1038d35) to head (85609f3).
⚠️ Report is 147 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/datasource-avro/src/file_format.rs 56.45% 20 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24925      +/-   ##
==========================================
+ Coverage   81.45%   81.74%   +0.28%     
==========================================
  Files        1120     1128       +8     
  Lines      401289   416706   +15417     
  Branches   401289   416706   +15417     
==========================================
+ Hits       326874   340626   +13752     
- Misses      55296    56013     +717     
- Partials    19119    20067     +948     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pepijnve
pepijnve marked this pull request as ready for review September 3, 2026 21:24
@github-actions github-actions Bot added the auto detected api change Auto detected API change label Sep 3, 2026
@pepijnve

pepijnve commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

This MR does not yet support the capability to specify compression. Should that be added as well?

@kosiew kosiew left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pepijnve,

Thanks for working on this. The Avro write support looks good overall. I have one non-blocking suggestion around testing the buffered flush path.

This MR does not yet support the capability to specify compression. Should that be added as well?

This can be a follow up PR.

.write(&batch)
.map_err(|e| internal_datafusion_err!("{e}"))?;
let mut buff_to_flush = shared_buffer.buffer.try_lock().unwrap();
if buff_to_flush.len() > BUFFER_FLUSH_BYTES {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a round-trip test where the encoded Avro output exceeds BUFFER_FLUSH_BYTES, ideally across multiple input batches? The current tests don't appear to exercise the path where SharedBuffer is cleared and later Avro blocks are appended to the object-store writer. It would be good to cover this boundary to make sure larger, multi-block files aren't accidentally truncated or malformed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I was kind of lazy here and pretty much copy/pasted from the datasource-arrow crate. I don't think that has a test covering exceeding the buffer limit either.
Good idea to make sure this code path is actually covered by tests. Just a test that writes the same batch in a loop enough times so that the threshold is crossed at least once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added an SLT that triggers the flush code path multiple times and reads back the result.

@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Sep 8, 2026
@kosiew

kosiew commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚀
@pepijnve
Thank you for your contribution.

@kosiew
kosiew added this pull request to the merge queue Sep 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 9, 2026
@kosiew
kosiew added this pull request to the merge queue Sep 10, 2026
Merged via the queue into apache:main with commit a7ea120 Sep 10, 2026
39 checks passed
@alamb

alamb commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Amazing

@alamb alamb mentioned this pull request Sep 16, 2026
5 of 22 tasks
@martin-g

Copy link
Copy Markdown
Member

Kudos, @pepijnve !

@pepijnve
pepijnve deleted the avro_writer branch September 16, 2026 21:19
@alamb

alamb commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This is so cool. We can make tpch data in avro format 🎉

andrewlamb@Andrews-MacBook-Pro-3:~/Downloads$ tpchgen-cli parquet --tables lineitem
lineitem               [==================] (100%)                                                                                                          andrewlamb@Andrews-MacBook-Pro-3:~/Downloads$ datafusion-cli
DataFusion CLI v55.1.0
> COPY (SELECT * FROM 'lineitem.parquet') to 'lineitem.avro';
+---------+
| count   |
+---------+
| 6001215 |
+---------+
1 row(s) fetched.
Elapsed 0.956 seconds.

>
\q
andrewlamb@Andrews-MacBook-Pro-3:~/Downloads$ ls -ltr lineitem.*
-rw-r--r--@ 1 andrewlamb  staff   221M Sep 16 17:25 lineitem.parquet
-rw-r--r--@ 1 andrewlamb  staff   456M Sep 16 17:25 lineitem.avro
andrewlamb@Andrews-MacBook-Pro-3:~/Downloads$

@pepijnve

Copy link
Copy Markdown
Contributor Author

Standing on the shoulders of giants. Credit goes to everyone who contributed to the Avro writer in arrow-rs.

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) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support AVRO Format for Write Queries

6 participants