boyuanzz commented on a change in pull request #11060: [BEAM-9454] Create
Deduplication transform based on user timer/state
URL: https://github.com/apache/beam/pull/11060#discussion_r392038085
##########
File path: sdks/python/apache_beam/runners/sdf_utils.py
##########
@@ -244,3 +251,63 @@ def get_estimator_state(self):
return None
return _NoOpWatermarkEstimator()
+
+
+class DeduplictaionWithinDuration(ptransform.PTransform):
+ """ A PTransform which deduplicate input records over a time domain and
+ threshold. Values in different windows will NOT be considered duplicates of
+ each other. Deduplication is best effort.
+
+ The durations specified may impose memory and/or storage requirements within
+ a runner and care might need to be used to ensure that the deduplication time
+ limit is long enough to remove duplicates but short enough to not cause
+ performance problems within a runner. Each runner may provide an optimized
+ implementation of their choice using the deduplication time domain and
+ threshold specified.
+
+ Does not preserve any order the input PCollection might have had.
+ """
+ def __init__(
+ self,
+ time_domain=userstate.TimeDomain.REAL_TIME,
+ duration=Duration(10 * 60)):
+ self.time_domain = time_domain
+ self.duration = duration
+
+ def _create_deduplicate_fn(self):
+ timer_spec = userstate.TimerSpec('expiry_timer', self.time_domain)
+ state_spec = userstate.BagStateSpec('seen', BooleanCoder())
+ duration = self.duration
+ domain = self.time_domain
+
+ class DeduplicationFn(DoFn):
+ def process(
+ self,
+ element,
+ ts=DoFn.TimestampParam,
+ seen_state=DoFn.StateParam(state_spec),
+ expiry_timer=DoFn.TimerParam(timer_spec)):
+ if True not in seen_state.read():
+ if domain is userstate.TimeDomain.REAL_TIME:
Review comment:
When writing this part, I think we should update user-face timer API in
python to do similar thing as Java, which makes life easier a lot.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services