Repository navigation
Conversation
PeriodicImpulse and MatchContinuously used Timestamp.now() as the default value of start_timestamp, which Python evaluates once, when the module is imported. A transform created later (in a long-running launcher process, a notebook kernel, or after slow pipeline setup) therefore started at the import time and immediately emitted a burst of elements with timestamps before the pipeline was built. Default start_timestamp to None and resolve it to Timestamp.now() when the transform is created. Fixes apache#40564
|
Assigning reviewers: R: @jrmccluskey for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
Hi @raams95, thank you for reporting this issue and submitting a fix. After looking closer at the problem, I see that you are highlighting two distinct issues here:
We should definitely fix the docstring to reflect reality, and we can do that in a separate PR. However, we shouldn't change the actual default behavior of PeriodicImpulse as proposed here, since it is widely used and changing the default would be a breaking change for existing pipelines. Thanks again for bringing this up and catching the documentation error! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40565 +/- ##
=============================================
+ Coverage 56.16% 79.94% +23.77%
=============================================
Files 1124 488 -636
Lines 178336 82347 -95989
Branches 1489 0 -1489
=============================================
- Hits 100170 65831 -34339
+ Misses 75645 16516 -59129
+ Partials 2521 0 -2521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks, that makes sense. Opened #40599 to document the import-time default in the docstrings. |
…mestamp (#40599) The default start_timestamp of PeriodicImpulse and MatchContinuously is evaluated once, when the module is imported. As discussed in #40565 the default stays as is, so document it and point to an explicit timestamp or rebase for starting relative to pipeline execution. Fixes #40564 Co-authored-by: JanakiRamChittineni <341781521+raams95@users.noreply.github.com>
Fixes #40564
PeriodicImpulseandMatchContinuouslydeclaredstart_timestamp=Timestamp.now()as a default argument. Python evaluates that once, when the module is imported, so the default start was the import time ofapache_beam, not the time the transform was created. When the transform is created later (a long-running launcher process, a notebook kernel, slow pipeline setup),ImpulseSeqGenDoFnstarts in the past and emits a burst of catch-up elements with timestamps from before the pipeline existed:On master this prints 14 elements, starting 10 seconds before
built_at. With this change it prints the 3 expected ones,built_at,built_at + 1andbuilt_at + 2.The default is now
None, and__init__resolves it toTimestamp.now(). This matches what #35569 assumed when it addedrebase: that aTimestamp.now()start is "the timestamp when the PTransform is expanded (i.e. the pipeline's construction time)". Explicitstart_timestampvalues and therebasemodes behave as before.MatchContinuouslyhad the same default, andReadAllFromTextContinuously/ReadAllFromAvroContinuouslypass through to it, so it gets the same fix.Tests:
periodicsequence_test.test_default_startread the default frominspect.signature, so it tested the import-time value. It now creates the transform withTimestamp.nowpatched to a fixed time and checks the pipeline output starts there.fileio_test.MatchContinuouslyTest.test_default_start_timestampdoes the same forMatchContinuously(has_deduplication=False).Both fail before the change (the default start is the import time, which is later than the given stop, so
initial_restrictionraisesAssertionError) and pass after it.Testing:
pytest apache_beam/transforms/periodicsequence_test.py apache_beam/io/fileio_test.py(71 passed, 3 skipped)pytest apache_beam/io/textio_test.py apache_beam/io/avroio_test.py -k Continuouslyyapf --diffandruff checkon the changed filesThank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123orfixes #456).CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.