Skip to content

GH-36247: [R] Add write_csv_dataset - #36436

Merged
thisisnic merged 18 commits into
apache:mainfrom
dgreiss:gh-36247-write-csv-dataset
Aug 25, 2023
Merged

thisisnic merged 18 commits into
apache:mainfrom
dgreiss:gh-36247-write-csv-dataset

Conversation

@dgreiss

@dgreiss dgreiss commented Jul 2, 2023 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Create a convenience wrapper around write_dataset for csv files.

What changes are included in this PR?

Adds a write_csv_dataset()

Are these changes tested?

Yes a few tests were added.

Are there any user-facing changes?

Yes a new function has been added. If this looks good I can add more to the docs as well.

@github-actions

github-actions Bot commented Jul 2, 2023

Copy link
Copy Markdown

⚠️ GitHub issue #36247 has been automatically assigned in GitHub to PR creator.

@thisisnic thisisnic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for making this PR!

This is looking good so far, and have added some comments about potential changes.

One thought I had is that when I was designing open_csv_dataset() etc, the parameters in that function are different to those in open_dataset() as they are intended to reflect those in read_csv_arrow(). read_csv_arrow() in turn mirrors the parameters in readr::read_csv(). The idea behind this is that you can use the same code as you would if you were using readr for the workflows.

The implementation of write_csv_arrow() doesn't do this (maybe it should, but that hasn't been done yet), but we could do those things here.

In the implementation of open_csv_dataset(), I also intentionally don't allow extra things to be passed in via the ..., to try to keep things simpler to reason about (advanced users can use open_dataset() and pass in whatever they like there, if they need to).

What I'm wondering is, if we want to take the opportunity to expose the options differently here, to create an API for users that is easier to reason about.

For example, readr::write_csv has the following options exposed in its parameters:

  • na
  • append
  • col_names
  • quote
  • escape
  • eol

We could take these, work out if they map to the Arrow options nicely, and do the hard work inside of the function to convert them for the user, a bit like we do for the CSV reader.

What do you think? I appreciate that this sounds like a whole lot of work, so I'd be happy to break it down into smaller tasks and do some bits myself if you didn't want to do the whole lot.

Comment thread r/R/csv.R Resolved
Comment thread r/R/csv.R Resolved
Comment thread r/R/csv.R Resolved
Comment thread r/R/dataset-format.R Resolved
Comment thread r/R/dataset-write.R Resolved
@dgreiss

dgreiss commented Jul 15, 2023

Copy link
Copy Markdown
Contributor Author

The implementation of write_csv_arrow() doesn't do this (maybe it should, but that hasn't been done yet), but we could do those things here.

Got it, I created a separate issue #36700 to add the other functions write_delim_arrow() and write_tsv_arrow()

In the implementation of open_csv_dataset(), I also intentionally don't allow extra things to be passed in via the ..., to try to keep things simpler to reason about (advanced users can use open_dataset() and pass in whatever they like there, if they need to).

Makes sense, I'll update it to follow that convention.

What I'm wondering is, if we want to take the opportunity to expose the options differently here, to create an API for users that is easier to reason about.

For example, readr::write_csv has the following options exposed in its parameters:

  • na
  • append
  • col_names
  • quote
  • escape
  • eol

We could take these, work out if they map to the Arrow options nicely, and do the hard work inside of the function to convert them for the user, a bit like we do for the CSV reader.

Right now na, eol and delim map to Arrow's null_string, eol and delimiter and I've exposed all of them in the PR. I can make sure those options get added as well in #36700.

The mapping of readr options does complicate things if a user uses both Arrow and readr options (eg. write_dataset(ds, file, delim = ',', delimiter = ';')). So we'll have to handle that possibility by either throwing an error or defaulting to the Arrow option.

@dgreiss
dgreiss marked this pull request as ready for review July 17, 2023 02:12
@dgreiss
dgreiss requested a review from paleolimbot as a code owner July 17, 2023 02:12
@dgreiss

dgreiss commented Jul 17, 2023

Copy link
Copy Markdown
Contributor Author

@thisisnic I think it's ready for another review.

@thisisnic

Copy link
Copy Markdown
Member

Thanks for all your work on this @dgreiss. I think that before we push ahead much further, it'd be worth addressing the discrepancies with write_csv_arrow(); I've opened #36864 for discussion first.

@thisisnic thisisnic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks - had a look at this with the conversation from the last package dev meeting in mind, and added a few comments below. Lots of this is looking done and I think we'll just need to iron out details.

Comment thread r/R/csv.R Resolved
Comment thread r/R/csv.R Resolved
Comment thread r/R/csv.R Resolved
Comment thread r/R/dataset-write.R Resolved
Comment thread r/R/dataset-write.R Resolved
Comment thread r/R/dataset-write.R Resolved
@dgreiss
dgreiss requested a review from thisisnic August 7, 2023 15:49

@thisisnic thisisnic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great work, thanks @dgreiss! I've made a few final suggestions, but keen to get this merged soon once they are resolved unless there's anything big I've missed.

Comment thread r/tests/testthat/test-dataset-write.R Resolved
Comment thread r/tests/testthat/test-dataset-write.R Resolved
Comment thread r/tests/testthat/test-dataset-write.R Resolved
Comment thread r/_pkgdown.yml Resolved
dgreiss and others added 2 commits August 17, 2023 14:26
Co-authored-by: Nic Crane <thisisnic@gmail.com>
Co-authored-by: Nic Crane <thisisnic@gmail.com>
@dgreiss

dgreiss commented Aug 17, 2023

Copy link
Copy Markdown
Contributor Author

Thanks I've accepted the changes and it should be good to go.

Comment thread r/tests/testthat/test-dataset-write.R Resolved

@thisisnic thisisnic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good to merge now!

@thisisnic
thisisnic merged commit 8f347c5 into apache:main Aug 25, 2023
@dgreiss
dgreiss deleted the gh-36247-write-csv-dataset branch August 25, 2023 19:27
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 8f347c5.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them.

loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request Nov 13, 2023
### Rationale for this change

Create a convenience wrapper around `write_dataset` for csv files. 

### What changes are included in this PR?

Adds a `write_csv_dataset()` 

### Are these changes tested?

Yes a few tests were added. 

### Are there any user-facing changes?

Yes a new function has been added. If this looks good I can add more to the docs as well. 
* Closes: apache#36247

Lead-authored-by: David Greiss <david.dgreiss@gmail.com>
Co-authored-by: Nic Crane <thisisnic@gmail.com>
Co-authored-by: David Greiss <dgreiss@users.noreply.github.com>
Signed-off-by: Nic Crane <thisisnic@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[R] Add function write_csv_dataset()

4 participants