robertwb commented on code in PR #23985:
URL: https://github.com/apache/beam/pull/23985#discussion_r1015988455


##########
sdks/python/apache_beam/runners/portability/fn_api_runner/fn_runner_test.py:
##########
@@ -2110,6 +2111,30 @@ def process(
         if expected_groups:
           assert_that(grouped, equal_to(expected_groups), label='CheckGrouped')
 
+  def test_time_based_split_manager(self):
+
+    elements = list(range(100))
+
+    class BundleCountingDoFn(beam.DoFn):
+      def process(self, element) -> Iterator[object]:
+        time.sleep(0.001)
+        yield element
+
+      def finish_bundle(self):
+        yield window.GlobalWindows.windowed_value('endOfBundle')
+
+    with self.create_pipeline() as p:
+      p._options.view_as(DirectOptions).test_splits = {
+          'SplitMarker': {
+              'timings': [0, .05], 'fractions': [0.5, 0.5]
+          }
+      }
+      assert_that(
+          p
+          | beam.Create(elements)
+          | 'SplitMarker' >> beam.ParDo(BundleCountingDoFn()),
+          equal_to(elements + ['endOfBundle'] * 2))

Review Comment:
   Yeah. Done.



##########
sdks/typescript/src/apache_beam/worker/operators.ts:
##########
@@ -234,6 +257,46 @@ class DataSourceOperator implements IOperator {
     throw Error("Data should not come in via process.");
   }
 
+  split(
+    desiredSplit: fnApi.ProcessBundleSplitRequest_DesiredSplit
+  ): fnApi.ProcessBundleSplitResponse_ChannelSplit | undefined {
+    if (!this.started) {
+      return undefined;
+    }
+    const end =
+      this.lastToProcessElement < Infinity
+        ? this.lastToProcessElement
+        : Number(desiredSplit.estimatedInputElements) - 1;
+    console.log(this.lastToProcessElement, this.lastProcessedElement, end);
+    if (this.lastProcessedElement >= end) {
+      return undefined;
+    }
+    var targetLastToProcessElement = Math.floor(
+      this.lastProcessedElement +
+        (end - this.lastProcessedElement) * desiredSplit.fractionOfRemainder
+    );
+    if (desiredSplit.allowedSplitPoints.length) {
+      targetLastToProcessElement =
+        Math.min(
+          ...Array.from(desiredSplit.allowedSplitPoints)
+            .filter((index) => index >= targetLastToProcessElement + 1)

Review Comment:
   Renamed and clarified.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to