Skip to content

[BEAM-2989] Fixed error when using Void type in WithKeys.#3922

Closed
youngoli wants to merge 2 commits intoapache:masterfrom
youngoli:bug-2989
Closed

[BEAM-2989] Fixed error when using Void type in WithKeys.#3922
youngoli wants to merge 2 commits intoapache:masterfrom
youngoli:bug-2989

Conversation

@youngoli
Copy link
Copy Markdown
Contributor

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

WithKeys had trouble correctly getting a VoidCoder when called with a null input before. This fix makes it so that it now functions when the input is (Void) null. This is done by passing Void.class as the key's class type instead of null, if the inputted key was null. Note that a null input that isn't cast to Void calls the WithKeys.of taking a SerializableFunction instead, so I added a precondition with a warning message to that one.

Also added a unit test to confirm that the fix works as intended, a quick change to VoidCoder to ensure that it doesn't get used inappropriately, and fixed a few warnings in WithKeysTest.

Also added error messages to WithKeys.of and VoidCoder.encode.
@youngoli
Copy link
Copy Markdown
Contributor Author

R: @lukecwik

Copy link
Copy Markdown
Member

@lukecwik lukecwik left a comment

Choose a reason for hiding this comment

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

Minor suggestions, LGTM once the edits are done.

public void encode(Void value, OutputStream outStream) {
public void encode(Void value, OutputStream outStream) throws IOException {
if (value != null) {
throw (new IOException("Attempting to encode non-null value with VoidCoder."));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Drop extraneous brackets:
throw (new IOException("Attempting to encode non-null value with VoidCoder.")); -> throw new IOException("Attempting to encode non-null value with VoidCoder.");

KV.of(100, "bbb")
);

private static final List<KV<Void, String>> WITH_CONST_KEYS_NULL = Arrays.asList(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WITH_CONST_KEYS_NULL -> WITH_CONST_NULL_KEYS

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling ff6ba35 on youngoli:bug-2989 into ** on apache:master**.


@Override
public void encode(Void value, OutputStream outStream) {
public void encode(Void value, OutputStream outStream) throws IOException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It turns out that we don't need this change since the case to the Void type should never work from an arbitrary user type. I remove this change and merged your code.

@asfgit asfgit closed this in 66d7b6f Oct 3, 2017
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.

3 participants