Skip to content

[BEAM-8335] Make TestStream to/from runner_api include the output_tags property.#10892

Merged
lukecwik merged 1 commit intoapache:masterfrom
rohdesamuel:teststream_merge
Feb 26, 2020
Merged

[BEAM-8335] Make TestStream to/from runner_api include the output_tags property.#10892
lukecwik merged 1 commit intoapache:masterfrom
rohdesamuel:teststream_merge

Conversation

@rohdesamuel
Copy link
Contributor

@rohdesamuel rohdesamuel commented Feb 18, 2020

The TestStream has the "output_tags" property which keeps track of which events go to which PCollection. A TestStream going through a round-trip to/from proto won't have these fields set. To do this, a modification to the from_runner_api_parameter is needed to include the parent PTransform proto to retrieve the information from the outputs.


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

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.

@rohdesamuel rohdesamuel force-pushed the teststream_merge branch 7 times, most recently from 677e777 to c5fb23e Compare February 19, 2020 18:35
@rohdesamuel rohdesamuel marked this pull request as ready for review February 19, 2020 19:01
@rohdesamuel
Copy link
Contributor Author

R: @davidyan74

@rohdesamuel rohdesamuel requested a review from lukecwik February 19, 2020 19:08
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why the string 'None' is used as the tag here (instead of just None)? Is there a way to distinguish between a non-existent tag and a tag named "None"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking through the codebase, it seems that 'None' is the special keyword used in the Python SDK to represent a tag that is specifically None. This keeps with the current style of the rest of the Python SDK. @lukecwik is this true?

Copy link
Member

@lukecwik lukecwik Feb 26, 2020

Choose a reason for hiding this comment

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

This is a general problem with python tag naming where there is ambiguity. It was worked around for Dataflow by using out for None and out_<tag> for tag until it was removed in #10971

Unfortunately this name mangling was applied inconsistently throughout the codebase which lead to arbitrary fix-ups and bugs.

Copy link
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.

Looks pretty good, some questions about TestStream constructor contract.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to declare output_tags here?
Are you trying to allow for outputs that have no events, otherwise shouldn't the tags come from the list of events?

The answer here impacts what we should be doing in expand in the no output_tags case in expand below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you trying to allow for outputs that have no events, otherwise shouldn't the tags come from the list of events?

Yep! The TestStreamService will allow users to define a TestStream with the output_tags specified at creation time and the events supplied at runtime.

@lukecwik
Copy link
Member

retest this please

Copy link
Contributor Author

@rohdesamuel rohdesamuel left a comment

Choose a reason for hiding this comment

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

Thanks for the quick review!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking through the codebase, it seems that 'None' is the special keyword used in the Python SDK to represent a tag that is specifically None. This keeps with the current style of the rest of the Python SDK. @lukecwik is this true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you trying to allow for outputs that have no events, otherwise shouldn't the tags come from the list of events?

Yep! The TestStreamService will allow users to define a TestStream with the output_tags specified at creation time and the events supplied at runtime.

* This also moves the DirectRunner's TestStream implementation to a
replacement transform. This is because the TestStream relies on getting
the output_tags from the PTransform.

Change-Id: Ibd80b0d25cd8cc5ff5c28e127f7313638e6664da
@rohdesamuel
Copy link
Contributor Author

rohdesamuel commented Feb 24, 2020

retest this please

EDIT: dang, doesn't work yet

@lukecwik
Copy link
Member

retest this please


def expand(self, pbegin):
"""Expands the TestStream into the DirectRunner implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Copy link
Member

@lukecwik lukecwik Feb 26, 2020

Choose a reason for hiding this comment

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

This is a general problem with python tag naming where there is ambiguity. It was worked around for Dataflow by using out for None and out_<tag> for tag until it was removed in #10971

Unfortunately this name mangling was applied inconsistently throughout the codebase which lead to arbitrary fix-ups and bugs.

def to_runner_api(self, unused_element_coder):
tag = 'None' if self.tag is None else self.tag

# Assert that no prevision is lost.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Assert that no prevision is lost.
# Assert that no precision is lost.


# Assert that no prevision is lost.
assert 1000 * (
self.new_watermark.micros // 1000) == self.new_watermark.micros
Copy link
Member

Choose a reason for hiding this comment

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

nit: This would be clearer by checking % has no remainder

output.
"""
def __init__(self, coder=coders.FastPrimitivesCoder(), events=None):
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

Please add pydoc comments mentioning the few important pieces:

  1. specifying the output_tags allows for adding outputs that produce no events
  2. output_tags must be a superset of tags found in events if events is specified

@@ -171,13 +184,20 @@ class TestStream(PTransform):
time. After all of the specified elements are emitted, ceases to produce
Copy link
Member

Choose a reason for hiding this comment

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

State that if only the default output or only one output tag has been specified, then a PCollection will be returned otherwise a dictionary of output name to PCollection.

@lukecwik lukecwik merged commit 7a4cdec into apache:master Feb 26, 2020
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.

3 participants