Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(rust): Introduce Writeable and AsyncWriteable #21599

Merged
merged 5 commits into from
Mar 6, 2025

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Mar 5, 2025

Prepares for cloud support on new-streaming

Also implements AsyncWrite onto the CloudWriter.

A Writeable can generally be directly used for writing:

image

It can be Derefed if a trait object is needed:

image

(similarly with AsyncWriteable)

@github-actions github-actions bot added internal An internal refactor or improvement rust Related to Rust Polars labels Mar 5, 2025
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 54.48718% with 71 lines in your changes missing coverage. Please review.

Project coverage is 80.15%. Comparing base (b3a3349) to head (29382bb).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-io/src/utils/file.rs 49.51% 52 Missing ⚠️
crates/polars-io/src/cloud/adaptors.rs 64.15% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21599      +/-   ##
==========================================
- Coverage   80.24%   80.15%   -0.10%     
==========================================
  Files        1604     1604              
  Lines      231329   231401      +72     
  Branches     2639     2639              
==========================================
- Hits       185635   185483     -152     
- Misses      45085    45309     +224     
  Partials      609      609              

☔ View full report in Codecov by Sentry.
📢 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.

eprintln!("try_get_writeable: forced async converted path: {}", path)
pub fn close(self) -> PolarsResult<()> {
match self {
// @RAISE_FILE_CLOSE_ERR
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Mar 5, 2025

Choose a reason for hiding this comment

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

Left this todo for now // @RAISE_FILE_CLOSE_ERR (here and 1 place down below)

It can be updated after #21588

Copy link
Member

Choose a reason for hiding this comment

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

Ready to rebase. :)

@nameexhaustion nameexhaustion marked this pull request as ready for review March 5, 2025 09:24
@nameexhaustion nameexhaustion marked this pull request as draft March 5, 2025 12:42
///
/// Also see: `Writeable::into_async_writeable` and `AsyncWriteable`.
pub enum Writeable {
Local(std::fs::File),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we theoretically (in a follow up PR) add an in-memory buffer to this? This would allow sinks to also output to in-memory buffers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be, we can do it later when we decide to implement sinking to memory

Ok(()) => {},
e @ Err(_) => {
if std::thread::panicking() {
eprintln!("ERROR: CloudWriter errored on close: {:?}", e)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

drive-by, just print an error message if already panicking to avoid abort

eprintln!("try_get_writeable: forced async converted path: {}", path)
pub fn close(self) -> std::io::Result<()> {
match self {
Self::Local(v) => ClosableFile::from(v).close(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Local files closed here

match self {
Self::Local(v) => async {
let f = v.into_std().await;
ClosableFile::from(f).close()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Local files closed here (AsyncWriteable)

@nameexhaustion nameexhaustion marked this pull request as ready for review March 6, 2025 08:04
@ritchie46 ritchie46 merged commit a599b9e into pola-rs:main Mar 6, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants