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

[BEAM-8575] Added two unit tests to CombineTest class to test that Co… #10190

Merged
merged 17 commits into from Jan 10, 2020

Conversation

bumblebee-coming
Copy link
Contributor

…mbinePerKey works with a simple customized CombineFn.

Added two unit tests to CombineTest class to test that CombinePerKey works with a simple customized CombineFn, namely ConcatIntCombineFn.

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • 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.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- Build Status --- --- Build Status
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Build Status
Build Status
Python Build Status
Build Status
Build Status
Build Status
--- Build Status
Build Status
Build Status
Build Status
--- --- Build Status
XLang --- --- --- Build Status --- --- ---

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website
Non-portable Build Status Build Status
Build Status
Build Status Build Status
Portable --- Build Status --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@bumblebee-coming
Copy link
Contributor Author

Its Java parity is the
testSimpleCombine
testSimpleCombineEmpty
in file
sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java

link:
https://github.com/apache/beam/blob/master/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CombineTest.java#L660

@robertwb
Copy link
Contributor

The mean combine fn already covers this test case completely.

@bumblebee-coming
Copy link
Contributor Author

This test (test_ConcatIntCombineFn_combine) is very similar to #10173 (test_MeanCombineFn_combine), except that it is supposed to be used to test counters.

We can either continue to add this test (test_ConcatIntCombineFn_combine) and then write the counter test using this pipeline,
or skip this test and write the counter test using #10173 (test_MeanCombineFn_combine) instead.
Do you think which one is better?

(An email with more details is sent to the reviewer.)

@bumblebee-coming
Copy link
Contributor Author

bumblebee-coming commented Dec 6, 2019

As discussed in the email, I re-implemented the tests to set three different kinds of metrics (counter, distribution and gauge) in a CombineFn and then extract and verify their values from the result returned by pipeline.run().

@bumblebee-coming
Copy link
Contributor Author

R: @robertwb

@bumblebee-coming
Copy link
Contributor Author

Run PythonLint PreCommit

Copy link
Contributor

@robertwb robertwb left a comment

Choose a reason for hiding this comment

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

Thanks. Just some minor comments on non-determinism.

sdks/python/apache_beam/transforms/combiners_test.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/transforms/combiners_test.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/transforms/combiners_test.py Outdated Show resolved Hide resolved
@bumblebee-coming
Copy link
Contributor Author

Run Python PreCommit

@chamikaramj
Copy link
Contributor

Retest this please

@bumblebee-coming
Copy link
Contributor Author

Retest this please

1 similar comment
@angoenka
Copy link
Contributor

angoenka commented Jan 9, 2020

Retest this please

@angoenka
Copy link
Contributor

angoenka commented Jan 9, 2020

Run Python PreCommit

@chamikaramj
Copy link
Contributor

Retest this please

1 similar comment
@chamikaramj
Copy link
Contributor

Retest this please

@angoenka
Copy link
Contributor

angoenka commented Jan 9, 2020

Retest this please

@angoenka
Copy link
Contributor

angoenka commented Jan 9, 2020

Run Python PreCommit

@bumblebee-coming
Copy link
Contributor Author

Retest this please

1 similar comment
@tvalentyn
Copy link
Contributor

Retest this please

Copy link
Contributor

@robertwb robertwb left a comment

Choose a reason for hiding this comment

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

Just some minor changes.

result.wait_until_finish()

# Verify the concatenated strings are correct.
expected_concat_per_key = [('c', 'ginoru'), ('d', 'abeemsstt')]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it's really hard to tell from reading this whether it is correct. Maybe make the input something like

('key1': 'a'), ('key1': 'ab'), .., ('key2', 'xyz'), ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -50,6 +52,39 @@
from apache_beam.utils.timestamp import Timestamp


class CounterIncrememtingCombineFn(beam.CombineFn):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call this SortedConcatWithCounters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

self.last_word_len.set(len(element))

# ''.join() converts the list to a string.
return ''.join(sorted(acc + element))
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to sort here, just return acc + element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return ''.join(sorted(acc + element))

def merge_accumulators(self, accs):
return ''.join(sorted(''.join(accs)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, return sum(accs, '')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sum(accs, ' ') doesn't work, because sum couldn't concatenate strings.

return ''.join(sorted(''.join(accs)))

def extract_output(self, acc):
return acc
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd do the sorting here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once sorted, acc became a list again. So I use ''.join() to convert it back to a string.

global_concat = (input
| beam.Values()
| beam.CombineGlobally(CounterIncrememtingCombineFn())
| "sort global result" >> _SortLists)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need for _SortLists anywhere here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted.

@angoenka
Copy link
Contributor

Retest this please

@chamikaramj
Copy link
Contributor

Retest this please

1 similar comment
@chamikaramj
Copy link
Contributor

Retest this please

@tvalentyn
Copy link
Contributor

retest this please

@robertwb robertwb merged commit d64759d into apache:master Jan 10, 2020
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

5 participants