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

Don't re-encode byte[] values in SortValues transform #31025

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

clairemcginty
Copy link
Contributor

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, 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
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

Comment on lines 173 to 178
@FunctionalInterface
private interface ThrowingFunction<T, U> {
U apply(T t) throws IOException, CoderException;
}

private class KvByteTranslator {
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 feels like a particularly inelegant solution but I didn't have a better idea 😅

Copy link
Contributor

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 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).

Copy link
Contributor

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

@Abacn
Copy link
Contributor

Abacn commented Apr 25, 2024

thanks, will take a look

Copy link
Contributor

github-actions bot commented May 3, 2024

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

Copy link
Contributor

github-actions bot commented May 7, 2024

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 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)

Copy link
Contributor

@damondouglas damondouglas left a 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:

  1. 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);
  }
  1. 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()))
    );
}
  1. Refactoring DecodingIterator's next with:
SecondaryKeyT secondaryKey = elementOf(keyCoder, next.getKey());
ValueT value = elementOf(valueCoder, next.getValue());
return KV.of(secondaryKey, value);

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.

None yet

3 participants