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
Don't re-encode byte[] values in SortValues transform #31025
base: master
Are you sure you want to change the base?
Don't re-encode byte[] values in SortValues transform #31025
Conversation
@FunctionalInterface | ||
private interface ThrowingFunction<T, U> { | ||
U apply(T t) throws IOException, CoderException; | ||
} | ||
|
||
private class KvByteTranslator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a particularly inelegant solution but I didn't have a better idea 😅
Assigning reviewers. If you would like to opt out of this review, comment R: @Abacn for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Reminder, please take a look at this pr: @Abacn |
thanks, will take a look |
Reminder, please take a look at this pr: @Abacn |
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @damondouglas for label java. Available commands:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing this! The following three proposals go together and made more sense to provide in one comment, rather than separately. May we consider instead of the new custom class:
- two private static methods as shown below:
private static <T> T elementOf(Coder<T> coder, byte[] bytes) throws CoderException {
if (coder instanceof ByteArrayCoder) {
return (T) bytes;
}
return CoderUtils.decodeFromByteArray(coder, bytes);
}
private static <T> byte[] bytesOf(Coder<T> coder, T element) throws CoderException {
if (element instanceof byte[]) {
return (byte[]) element;
}
return CoderUtils.encodeToByteArray(coder, element);
}
- Refactoring the SortValuesDoFn's processElement method with:
for (KV<SecondaryKeyT, ValueT> record : records) {
sorter.add(KV.of(
bytesOf(keyCoder, record.getKey()),
bytesOf(valueCoder, record.getValue()))
);
}
- Refactoring DecodingIterator's next with:
SecondaryKeyT secondaryKey = elementOf(keyCoder, next.getKey());
ValueT value = elementOf(valueCoder, next.getValue());
return KV.of(secondaryKey, value);
A small optimization for
SortValues
transform to avoid doubly roundtrip encoding values that are alreadybyte[]
s -- they can be passed directly to the Sorter.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
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, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.