You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "robertwb (via GitHub)" <gi...@apache.org> on 2024/03/29 21:46:11 UTC
[PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
robertwb opened a new pull request, #30807:
URL: https://github.com/apache/beam/pull/30807
------------------------
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](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on code in PR #30807:
URL: https://github.com/apache/beam/pull/30807#discussion_r1546878370
##########
sdks/python/apache_beam/runners/dataflow/dataflow_runner.py:
##########
@@ -465,6 +465,8 @@ def run_pipeline(self, pipeline, options, pipeline_proto=None):
'min_cpu_platform=' + worker_options.min_cpu_platform)
self.job = apiclient.Job(options, self.proto_pipeline)
+ print(self.proto_pipeline)
Review Comment:
leftover?
##########
sdks/python/apache_beam/transforms/util.py:
##########
@@ -1644,3 +1645,39 @@ def _process(element):
yield r
return pcoll | FlatMap(_process)
+
+
+@typehints.with_input_types(T)
+@typehints.with_output_types(T)
+class WaitOn(PTransform):
+ """Delays processing of a {@link PCollection} until another set of
+ PCollections has finished being processed. For example::
+
+ X | WaitOn(Y, Z) | SomeTransform()
+
+ would ensure that PCollections Y and Z (and hence their producing transforms)
+ are complete before SomeTransform gets executed on the elements of X.
+ This can be especially useful the waited-on PCollections are the outputs
+ of transforms that interact with external systems (such as writing to a
+ database or other sink).
+
+ For streaming, this delay is done on a per-window basis, i.e.
+ the corresponding window of each waited-on PCollection is computed before
+ elements are passed through the main collection.
+
+ This barrier often induces a fusion break.
+ """
+ def __init__(self, *to_be_waited_on):
+ self._to_be_waited_on = to_be_waited_on
+
+ def expand(self, pcoll):
+ # All we care about is the watermark, not the data itself.
+ # The GroupByKey avoids writing empty files for each shard, and also
+ # ensures the respective window finishes before advancing the timestamp.
+ sides = [
+ pvalue.AsIter(
+ pcoll
+ | f"WaitFor{ix}" >> (beam.FlatMap(lambda x: ()) | GroupByKey()))
+ for (ix, pcoll) in enumerate(self._to_be_waited_on)
Review Comment:
for readability purposes, let's disambiguate two `pcoll`s.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on code in PR #30807:
URL: https://github.com/apache/beam/pull/30807#discussion_r1546905552
##########
sdks/python/apache_beam/transforms/util.py:
##########
@@ -1644,3 +1645,39 @@ def _process(element):
yield r
return pcoll | FlatMap(_process)
+
+
+@typehints.with_input_types(T)
+@typehints.with_output_types(T)
+class WaitOn(PTransform):
+ """Delays processing of a {@link PCollection} until another set of
+ PCollections has finished being processed. For example::
+
+ X | WaitOn(Y, Z) | SomeTransform()
+
+ would ensure that PCollections Y and Z (and hence their producing transforms)
+ are complete before SomeTransform gets executed on the elements of X.
+ This can be especially useful the waited-on PCollections are the outputs
+ of transforms that interact with external systems (such as writing to a
+ database or other sink).
+
+ For streaming, this delay is done on a per-window basis, i.e.
+ the corresponding window of each waited-on PCollection is computed before
+ elements are passed through the main collection.
+
+ This barrier often induces a fusion break.
+ """
+ def __init__(self, *to_be_waited_on):
+ self._to_be_waited_on = to_be_waited_on
+
+ def expand(self, pcoll):
+ # All we care about is the watermark, not the data itself.
+ # The GroupByKey avoids writing empty files for each shard, and also
+ # ensures the respective window finishes before advancing the timestamp.
+ sides = [
+ pvalue.AsIter(
+ pcoll
+ | f"WaitFor{ix}" >> (beam.FlatMap(lambda x: ()) | GroupByKey()))
Review Comment:
Interesting, so given that your test passes, we don't need to make sure that transform apply tags `WaitFor{ix}` are unique when WaitOn is used multiple times? I thought those tags should be unique within the entire pipeline.
(nit) not sure if you intentionally use WaitFor instead of WaitOn.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on code in PR #30807:
URL: https://github.com/apache/beam/pull/30807#discussion_r1546905552
##########
sdks/python/apache_beam/transforms/util.py:
##########
@@ -1644,3 +1645,39 @@ def _process(element):
yield r
return pcoll | FlatMap(_process)
+
+
+@typehints.with_input_types(T)
+@typehints.with_output_types(T)
+class WaitOn(PTransform):
+ """Delays processing of a {@link PCollection} until another set of
+ PCollections has finished being processed. For example::
+
+ X | WaitOn(Y, Z) | SomeTransform()
+
+ would ensure that PCollections Y and Z (and hence their producing transforms)
+ are complete before SomeTransform gets executed on the elements of X.
+ This can be especially useful the waited-on PCollections are the outputs
+ of transforms that interact with external systems (such as writing to a
+ database or other sink).
+
+ For streaming, this delay is done on a per-window basis, i.e.
+ the corresponding window of each waited-on PCollection is computed before
+ elements are passed through the main collection.
+
+ This barrier often induces a fusion break.
+ """
+ def __init__(self, *to_be_waited_on):
+ self._to_be_waited_on = to_be_waited_on
+
+ def expand(self, pcoll):
+ # All we care about is the watermark, not the data itself.
+ # The GroupByKey avoids writing empty files for each shard, and also
+ # ensures the respective window finishes before advancing the timestamp.
+ sides = [
+ pvalue.AsIter(
+ pcoll
+ | f"WaitFor{ix}" >> (beam.FlatMap(lambda x: ()) | GroupByKey()))
Review Comment:
Interesting, so given that your test passes, we don't need to make sure that transform apply tags `WaitFor{ix}` are unique when WaitOn is used multiple times? I thought those should be unique within the entire pipeline.
(nit) not sure if you intentionally use WaitFor instead of WaitOn.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "robertwb (via GitHub)" <gi...@apache.org>.
robertwb merged PR #30807:
URL: https://github.com/apache/beam/pull/30807
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #30807:
URL: https://github.com/apache/beam/pull/30807#issuecomment-2027795019
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @tvalentyn for label python.
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).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add WaitOn transform to Python, analogous to Java's Wait.on. [beam]
Posted by "robertwb (via GitHub)" <gi...@apache.org>.
robertwb commented on code in PR #30807:
URL: https://github.com/apache/beam/pull/30807#discussion_r1546911384
##########
sdks/python/apache_beam/transforms/util.py:
##########
@@ -1644,3 +1645,39 @@ def _process(element):
yield r
return pcoll | FlatMap(_process)
+
+
+@typehints.with_input_types(T)
+@typehints.with_output_types(T)
+class WaitOn(PTransform):
+ """Delays processing of a {@link PCollection} until another set of
+ PCollections has finished being processed. For example::
+
+ X | WaitOn(Y, Z) | SomeTransform()
+
+ would ensure that PCollections Y and Z (and hence their producing transforms)
+ are complete before SomeTransform gets executed on the elements of X.
+ This can be especially useful the waited-on PCollections are the outputs
+ of transforms that interact with external systems (such as writing to a
+ database or other sink).
+
+ For streaming, this delay is done on a per-window basis, i.e.
+ the corresponding window of each waited-on PCollection is computed before
+ elements are passed through the main collection.
+
+ This barrier often induces a fusion break.
+ """
+ def __init__(self, *to_be_waited_on):
+ self._to_be_waited_on = to_be_waited_on
+
+ def expand(self, pcoll):
+ # All we care about is the watermark, not the data itself.
+ # The GroupByKey avoids writing empty files for each shard, and also
+ # ensures the respective window finishes before advancing the timestamp.
+ sides = [
+ pvalue.AsIter(
+ pcoll
+ | f"WaitFor{ix}" >> (beam.FlatMap(lambda x: ()) | GroupByKey()))
Review Comment:
Good call. Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org