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

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

                Author: ASF GitHub Bot
            Created on: 30/Apr/18 23:15
            Start Date: 30/Apr/18 23:15
    Worklog Time Spent: 10m 
      Work Description: pabloem closed pull request #5199: [BEAM-2163] Remove 
the dependency on examples from ptransform_test
URL: https://github.com/apache/beam/pull/5199
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sdks/python/apache_beam/io/utils.py 
b/sdks/python/apache_beam/io/utils.py
new file mode 100644
index 00000000000..d6b312d7a67
--- /dev/null
+++ b/sdks/python/apache_beam/io/utils.py
@@ -0,0 +1,65 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""Utils for the io library.
+* CountingSource: Subclass of iobase.BoundedSource. Used
+on transforms.ptransform_test.test_read_metrics.
+"""
+
+from apache_beam.io import iobase
+from apache_beam.io.range_trackers import OffsetRangeTracker
+from apache_beam.metrics import Metrics
+
+
+class CountingSource(iobase.BoundedSource):
+
+  def __init__(self, count):
+    self.records_read = Metrics.counter(self.__class__, 'recordsRead')
+    self._count = count
+
+  def estimate_size(self):
+    return self._count
+
+  def get_range_tracker(self, start_position, stop_position):
+    if start_position is None:
+      start_position = 0
+    if stop_position is None:
+      stop_position = self._count
+
+    return OffsetRangeTracker(start_position, stop_position)
+
+  def read(self, range_tracker):
+    for i in range(self._count):
+      if not range_tracker.try_claim(i):
+        return
+      self.records_read.inc()
+      yield i
+
+  def split(self, desired_bundle_size, start_position=None,
+            stop_position=None):
+    if start_position is None:
+      start_position = 0
+    if stop_position is None:
+      stop_position = self._count
+
+    bundle_start = start_position
+    while bundle_start < self._count:
+      bundle_stop = max(self._count, bundle_start + desired_bundle_size)
+      yield iobase.SourceBundle(weight=(bundle_stop - bundle_start),
+                                source=self,
+                                start_position=bundle_start,
+                                stop_position=bundle_stop)
+      bundle_start = bundle_stop
diff --git a/sdks/python/apache_beam/transforms/ptransform_test.py 
b/sdks/python/apache_beam/transforms/ptransform_test.py
index 350a19f42e3..e23fad7a78f 100644
--- a/sdks/python/apache_beam/transforms/ptransform_test.py
+++ b/sdks/python/apache_beam/transforms/ptransform_test.py
@@ -182,7 +182,7 @@ def 
test_do_with_multiple_outputs_maintains_unique_name(self):
 
   @attr('ValidatesRunner')
   def test_read_metrics(self):
-    from apache_beam.examples.snippets.snippets import CountingSource
+    from apache_beam.io.utils import CountingSource
 
     class CounterDoFn(beam.DoFn):
       def __init__(self):
@@ -197,7 +197,7 @@ def process(self, element):
     (pipeline | Read(CountingSource(100)) | beam.ParDo(CounterDoFn()))
     res = pipeline.run()
     res.wait_until_finish()
-    # This counter is defined in snippets.CountingSource.
+    # This counter is defined in utils.CountingSource.
     metric_results = res.metrics().query(MetricsFilter()
                                          .with_name('recordsRead'))
     outputs_counter = metric_results['counters'][0]


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 96878)
    Time Spent: 1h 20m  (was: 1h 10m)

> Remove the dependency on examples from ptransform_test
> ------------------------------------------------------
>
>                 Key: BEAM-2163
>                 URL: https://issues.apache.org/jira/browse/BEAM-2163
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-core
>            Reporter: Sourabh Bajaj
>            Priority: Major
>              Labels: newbie, starter
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> https://github.com/apache/beam/blob/master/sdks/python/apache_beam/transforms/ptransform_test.py#L176
> This validates runner test depends on the Counting source snippet and the 
> source should be copied here instead of this dependency.
> The actual beam code should not depend on the examples package at all.



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

Reply via email to