beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEAM-1630) Add Splittable DoFn to Python SDK
Date Sat, 02 Dec 2017 00:28:12 GMT

    [ https://issues.apache.org/jira/browse/BEAM-1630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16275282#comment-16275282
] 

ASF GitHub Bot commented on BEAM-1630:
--------------------------------------

chamikaramj commented on a change in pull request #4064: [BEAM-1630] Adds support for processing
Splittable DoFns using DirectRunner.
URL: https://github.com/apache/beam/pull/4064#discussion_r154233854
 
 

 ##########
 File path: sdks/python/apache_beam/runners/sdf_common.py
 ##########
 @@ -0,0 +1,161 @@
+#
+# 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.
+#
+
+"""This module contains Splittable DoFn logic that's common to all runners."""
+
+import uuid
+
+import apache_beam as beam
+from apache_beam import pvalue
+from apache_beam.coders import typecoders
+from apache_beam.pipeline import AppliedPTransform
+from apache_beam.pipeline import PTransformOverride
+from apache_beam.runners.common import DoFnInvoker
+from apache_beam.runners.common import DoFnSignature
+from apache_beam.transforms.core import ParDo
+from apache_beam.transforms.ptransform import PTransform
+
+
+class SplittableParDoOverride(PTransformOverride):
+  """A transform override for ParDo transformss of SplittableDoFns.
+
+  Replaces the ParDo transform with a SplittableParDo transform that performs
+  SDF specific logic.
+  """
+
+  def get_matcher(self):
+    def _matcher(applied_ptransform):
+      assert isinstance(applied_ptransform, AppliedPTransform)
+      transform = applied_ptransform.transform
+      if isinstance(transform, ParDo):
+        signature = DoFnSignature(transform.fn)
+        return signature.is_splittable_dofn()
+
+    return _matcher
+
+  def get_replacement_transform(self, ptransform):
+    assert isinstance(ptransform, ParDo)
+    do_fn = ptransform.fn
+    signature = DoFnSignature(do_fn)
+    if signature.is_splittable_dofn():
+      return SplittableParDo(ptransform)
+    else:
+      return ptransform
+
+
+class SplittableParDo(PTransform):
+  """A transform that processes a PCollection using a Splittable DoFn."""
+
+  def __init__(self, ptransform):
+    assert isinstance(ptransform, ParDo)
+    self._ptransform = ptransform
+
+  def expand(self, pcoll):
+    sdf = self._ptransform.fn
+    signature = DoFnSignature(sdf)
+    invoker = DoFnInvoker.create_invoker(signature, process_invocation=False)
+
+    element_coder = typecoders.registry.get_coder(pcoll.element_type)
+    restriction_coder = invoker.invoke_restriction_coder()
+
+    keyed_elements = (pcoll
+                      | 'pair' >> ParDo(PairWithRestrictionFn(sdf))
+                      | 'split' >> ParDo(SplitRestrictionFn(sdf))
+                      | 'explode' >> ParDo(ExplodeWindowsFn())
 
 Review comment:
   Not sure I get this. Are you saying that I won't be getting a 'WindowedValue' on ProcessFn
since I explode windows here ?

----------------------------------------------------------------
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:
users@infra.apache.org


> Add Splittable DoFn to Python SDK
> ---------------------------------
>
>                 Key: BEAM-1630
>                 URL: https://issues.apache.org/jira/browse/BEAM-1630
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-core
>            Reporter: Chamikara Jayalath
>            Assignee: Chamikara Jayalath
>
> Splittable DoFn [1] is currently being implemented for Java SDK [2]. We should add this
to Python SDK as well.
> Following document proposes an API for this.
> https://docs.google.com/document/d/1h_zprJrOilivK2xfvl4L42vaX4DMYGfH1YDmi-s_ozM/edit?usp=sharing
> [1] https://s.apache.org/splittable-do-fn
> [2] https://lists.apache.org/thread.html/0ce61ac162460a149d5c93cdface37cc383f8030fe86ca09e5699b18@%3Cdev.beam.apache.org%3E



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message