Don't re-encode byte[] values in SortValues transform
A small optimization for SortValues transform to avoid doubly roundtrip encoding values that are already byte[]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:
- [ ] 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, commentfixes #<ISSUE NUMBER>instead. - [ ] Update
CHANGES.mdwith 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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.
Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:
R: @Abacn for label java.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting 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).
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 assign to next reviewer:
R: @damondouglas for label java.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting 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)
Reminder, please take a look at this pr: @damondouglas
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);
Thanks for the review @damondouglas ! Sorry for the late reply, I've been out of office, but will apply these suggestions today or tomorrow 👍
Thanks for the review @damondouglas ! Sorry for the late reply, I've been out of office, but will apply these suggestions today or tomorrow 👍
Updated! your suggestions are much clearer -- my original approach constructed the custom functions up-front so that we wouldn't have to do the type-checking on every individual element, but I think the readability/clarity was just not worth it.
Reminder, please take a look at this pr: @damondouglas
@clairemcginty
Updated! your suggestions are much clearer -- my original approach constructed the custom functions up-front so that we wouldn't have to do the type-checking on every individual element, but I think the readability/clarity was just not worth it.
Thank you so much for listening! Apologies as I was taking a week off last week and will review now.