[ 
https://issues.apache.org/jira/browse/BEAM-2939?focusedWorklogId=232461&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-232461
 ]

ASF GitHub Bot logged work on BEAM-2939:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Apr/19 01:06
            Start Date: 25/Apr/19 01:06
    Worklog Time Spent: 10m 
      Work Description: pabloem commented on pull request #8338: [BEAM-2939] 
Initial SyntheticSDF as Source and add an Synthetic pipeline to sdf test
URL: https://github.com/apache/beam/pull/8338#discussion_r278366751
 
 

 ##########
 File path: sdks/python/apache_beam/testing/synthetic_pipeline.py
 ##########
 @@ -250,6 +252,95 @@ def default_output_coder(self):
         [beam.coders.BytesCoder(), beam.coders.BytesCoder()])
 
 
+class SyntheticSDFSourceRestrictionProvider(RestrictionProvider):
+  """A `RestrictionProvider` for SyntheticSDFAsSource.
+
+  In initial_restriction(element) and split(element), element means source
+  description.
+  A typical element is like:
+
+    {
+      'key_size': 1,
+      'value_size': 1,
+      'initial_splitting_num_bundles': 2,
+      'initial_splitting_desired_bundle_size': 2,
+      'sleep_per_input_record_sec': 0,
+      'initial_splitting' : 'const'
+
+    }
+
+  """
+
+  def initial_restriction(self, element):
+    return (0, element['num_records'])
+
+  def create_tracker(self, restriction):
+    return restriction_trackers.OffsetRestrictionTracker(
+        restriction[0], restriction[1])
+
+  def split(self, element, restriction):
+    start_position, stop_position = restriction
+    element_size = element['key_size'] + element['value_size']
+    estimate_size = element_size * element['num_records']
+    if element['initial_splitting'] == 'zipf':
+      desired_num_bundles = (
+          element['initial_splitting_num_bundles'] or
+          math.ceil(float(estimate_size) /
+                    element['initial_splitting_desired_bundle_size']))
+      samples = np.random.zipf(
+          element['initial_splitting_distribution_parameter'],
+          desired_num_bundles)
+      total = sum(samples)
+      relative_bundle_sizes = [(float(sample) / total) for sample in samples]
+      bundle_ranges = []
+      start = start_position
+      index = 0
+      while start < stop_position:
+        if index == desired_num_bundles - 1:
+          bundle_ranges.append((start, stop_position))
+          break
+        stop = start + int(
+            element['num_records'] * relative_bundle_sizes[index])
+        bundle_ranges.append((start, stop))
+        start = stop
+        index += 1
+    else:
+      if element['initial_splitting_num_bundles']:
+        bundle_size_in_elements = max(1, int(
+            element['num_records'] /
+            element['initial_splitting_num_bundles']))
+      else:
+        bundle_size_in_elements = (max(
+            div_round_up(
+                element['initial_splitting_desired_bundle_size'], 
element_size),
+            int(math.floor(math.sqrt(element['num_records'])))))
+      bundle_ranges = []
+      for start in range(start_position, stop_position,
+                         bundle_size_in_elements):
+        stop = min(start + bundle_size_in_elements, stop_position)
+        bundle_ranges.append((start, stop))
+    return bundle_ranges
+
+  def restriction_size(self, element, restriction):
+    return ((element['key_size'] + element['value_size'])
+            * (restriction[1] - restriction[0]))
+
+
+class SyntheticSDFAsSource(beam.DoFn):
+  """A SDF that generates records like a source"""
 
 Review comment:
   Perhaps provide more documentation for what sort of distributions / valid 
input as a source is supported here? And maybe Pydoc more specific to this 
transform e.g. `A DoFn that takes in synthetic source specifications, and 
provides elements ...` something like that? : )
 
----------------------------------------------------------------
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 232461)
    Time Spent: 16h 50m  (was: 16h 40m)

> Fn API SDF support
> ------------------
>
>                 Key: BEAM-2939
>                 URL: https://issues.apache.org/jira/browse/BEAM-2939
>             Project: Beam
>          Issue Type: Improvement
>          Components: beam-model
>            Reporter: Henning Rohde
>            Assignee: Luke Cwik
>            Priority: Major
>              Labels: portability, triaged
>          Time Spent: 16h 50m
>  Remaining Estimate: 0h
>
> The Fn API should support streaming SDF. Detailed design TBD.
> Once design is ready, expand subtasks similarly to BEAM-2822.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to