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

[scio-core](feature) Sample SCollection with max weight #5352

Merged
merged 5 commits into from
May 17, 2024

Conversation

RustedBones
Copy link
Contributor

Create a sampling API with weighted limit and and byte size limit

@RustedBones RustedBones force-pushed the sample-weighted branch 3 times, most recently from 20fc05d to 6baf89c Compare May 2, 2024 11:33
val observer = new ElementByteSizeObserver {
override def reportElementSize(elementByteSize: Long): Unit = size += elementByteSize
}
bCoder.registerByteSizeObserver(e, observer)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is better than CoderUtils.encodeToByteArray(beamCoder, v).length because it uses a new CountingOutputStream(ByteStreams.nullOutputStream())) behind the scene.

The code can be factorized with batchByteSized moving out of draft state

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 92.68293% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 61.30%. Comparing base (ea6d9e3) to head (b3e6780).
Report is 12 commits behind head on main.

Files Patch % Lines
...otify/scio/values/SampleSCollectionFunctions.scala 91.66% 2 Missing ⚠️
...in/scala/com/spotify/scio/values/SCollection.scala 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5352      +/-   ##
==========================================
+ Coverage   61.22%   61.30%   +0.07%     
==========================================
  Files         302      303       +1     
  Lines       10846    10876      +30     
  Branches      761      780      +19     
==========================================
+ Hits         6641     6667      +26     
- Misses       4205     4209       +4     

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

val observer = new ElementByteSizeObserver {
override def reportElementSize(elementByteSize: Long): Unit = size += elementByteSize
}
bCoder.registerByteSizeObserver(e, observer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@RustedBones RustedBones marked this pull request as ready for review May 6, 2024 06:28
def sample(sampleSize: Int): SCollection[Iterable[T]] = this.transform {
_.pApply(Sample.fixedSizeGlobally(sampleSize)).map(_.asScala)
}
// TODO move to implicit
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to resolve this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be binary breaking. it is a reminder for later. maybe worth an issue with milestone

@RustedBones RustedBones merged commit d235906 into main May 17, 2024
11 checks passed
@RustedBones RustedBones deleted the sample-weighted branch May 17, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants