Skip to content

Conversation

@gonzojive
Copy link
Contributor

When writing tests for spittable DoFns that need to seek within files, it's
helpful to use memfs. Before this change, memfs returned an io.ReadCloser that
did not implement io.Seeker.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

When writing tests for spittable DoFns that need to seek within files, it's
helpful to use memfs. Before this change, memfs returned an io.ReadCloser that
did not implement io.Seeker.
@asf-ci
Copy link

asf-ci commented Jun 18, 2022

Can one of the admins verify this patch?

4 similar comments
@asf-ci
Copy link

asf-ci commented Jun 18, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 18, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 18, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 18, 2022

Can one of the admins verify this patch?

@codecov
Copy link

codecov bot commented Jun 18, 2022

Codecov Report

Merging #21942 (6d5935a) into master (525a169) will increase coverage by 0.04%.
The diff coverage is 75.94%.

@@            Coverage Diff             @@
##           master   #21942      +/-   ##
==========================================
+ Coverage   73.98%   74.02%   +0.04%     
==========================================
  Files         702      703       +1     
  Lines       92845    92996     +151     
==========================================
+ Hits        68687    68843     +156     
+ Misses      22903    22881      -22     
- Partials     1255     1272      +17     
Flag Coverage Δ
go 51.11% <75.94%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
sdks/go/pkg/beam/io/textio/textio.go 64.85% <37.50%> (+9.69%) ⬆️
sdks/go/pkg/beam/io/filesystem/memfs/memory.go 88.63% <85.71%> (-3.37%) ⬇️
sdks/go/pkg/beam/io/fhirio/execute_bundles.go 56.71% <0.00%> (ø)
sdks/go/pkg/beam/runners/dataflow/dataflow.go 59.77% <0.00%> (+1.11%) ⬆️
sdks/go/pkg/beam/core/runtime/graphx/serialize.go 27.51% <0.00%> (+1.23%) ⬆️
sdks/go/pkg/beam/io/fhirio/read.go 82.75% <0.00%> (+2.75%) ⬆️
sdks/go/pkg/beam/core/runtime/graphx/user.go 42.30% <0.00%> (+42.30%) ⬆️
sdks/go/pkg/beam/io/fhirio/common.go 59.45% <0.00%> (+59.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 525a169...6d5935a. Read the comment docs.

@github-actions
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @jrmccluskey for label go.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@gonzojive
Copy link
Contributor Author

I can add a test if desired.

@jrmccluskey
Copy link
Contributor

I would definitely like to see a unit test to demonstrate the functionality you're adding.

@jrmccluskey
Copy link
Contributor

Having thought about it more, a runnable example demonstrating the usage you're proposing would also be really helpful (totally up to you.)

@gonzojive
Copy link
Contributor Author

I added tests and revised the implementation. I noticed there is another gotcha with memfs: open readers don't see the results of writers. I addressed this in the code as well and added tests for it (that break before the commits).

Having thought about it more, a runnable example demonstrating the usage you're proposing would also be really helpful (totally up to you.)

Done. Please see the updated implementation of TextIO that uses Seek to dramatically reduce the total # of read bytes.

When making a change like that in TextIO, it's helpful if memfs behaves very similarly to a local file system and also implements io.Seeker.

Copy link
Contributor

@jrmccluskey jrmccluskey left a comment

Choose a reason for hiding this comment

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

LGTM, going to loop in @lostluck for a second set of eyes.

return nil
}

// bytesReader implements io.Reader, io.Seeker, io.Cloer for memfs "files."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// bytesReader implements io.Reader, io.Seeker, io.Cloer for memfs "files."
// bytesReader implements io.Reader, io.Seeker, io.Closer for memfs "files."

@gonzojive
Copy link
Contributor Author

gonzojive commented Jun 27, 2022 via email

@lostluck
Copy link
Contributor

One idea is to update the interface of the memfa package to expose bytes read rather than copying a lot of the memfs implementation into the TextIO test.

I like that better than duplicating logic into the textio test. Memfs is at best intended for simple tests and demos, so this would be an appropriate extension.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2022

Reminder, please take a look at this pr: @jrmccluskey

@jrmccluskey
Copy link
Contributor

I'm cool with merging this once the branch conflicts are resolved

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 3, 2023
@github-actions
Copy link
Contributor

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions bot closed this Mar 10, 2023
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.

4 participants