コード例 #1
0
ファイル: direct_runner.py プロジェクト: yoreyuan/beam
 def visit_transform(self, applied_ptransform):
   transform = applied_ptransform.transform
   # The FnApiRunner does not support streaming execution.
   if isinstance(transform, TestStream):
     self.supported_by_fnapi_runner = False
   # The FnApiRunner does not support reads from NativeSources.
   if (isinstance(transform, beam.io.Read) and
       isinstance(transform.source, NativeSource)):
     self.supported_by_fnapi_runner = False
   # The FnApiRunner does not support the use of _NativeWrites.
   if isinstance(transform, _NativeWrite):
     self.supported_by_fnapi_runner = False
   if isinstance(transform, beam.ParDo):
     dofn = transform.dofn
     # The FnApiRunner does not support execution of SplittableDoFns.
     if DoFnSignature(dofn).is_splittable_dofn():
       self.supported_by_fnapi_runner = False
     # The FnApiRunner does not support execution of DoFns with timers.
     if DoFnSignature(dofn).has_timers():
       self.supported_by_fnapi_runner = False
     # The FnApiRunner does not support execution of CombineFns with
     # deferred side inputs.
     if isinstance(dofn, CombineValuesDoFn):
       args, kwargs = transform.raw_side_inputs
       args_to_check = itertools.chain(args,
                                       kwargs.values())
       if any(isinstance(arg, ArgumentPlaceholder)
              for arg in args_to_check):
         self.supported_by_fnapi_runner = False
コード例 #2
0
 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
コード例 #3
0
ファイル: sdf_common.py プロジェクト: aaltay/incubator-beam
 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
コード例 #4
0
ファイル: common_test.py プロジェクト: junaidsaiyed/beam
  def test_dofn_validate_process_error(self):
    class MyDoFn(DoFn):
      def process(self, element, w1=DoFn.WindowParam, w2=DoFn.WindowParam):
        pass

    with self.assertRaises(AssertionError):
      DoFnSignature(MyDoFn())
コード例 #5
0
    def expand(self, pcoll):
        sdf = self._ptransform.fn
        signature = DoFnSignature(sdf)
        restriction_coder = signature.get_restriction_coder()
        element_coder = typecoders.registry.get_coder(pcoll.element_type)

        keyed_elements = (pcoll
                          | 'pair' >> ParDo(PairWithRestrictionFn(sdf))
                          | 'split' >> ParDo(SplitRestrictionFn(sdf))
                          | 'explode' >> ParDo(ExplodeWindowsFn())
                          | 'random' >> ParDo(RandomUniqueKeyFn()))

        return keyed_elements | ProcessKeyedElements(
            sdf, element_coder, restriction_coder, pcoll.windowing,
            self._ptransform.args, self._ptransform.kwargs,
            self._ptransform.side_inputs)
コード例 #6
0
    def test_dofn_get_defaults_kwonly(self):
        class MyDoFn(DoFn):
            def process(self, element, *, w=DoFn.WindowParam):
                pass

        signature = DoFnSignature(MyDoFn())

        self.assertEqual(signature.process_method.defaults, [DoFn.WindowParam])
コード例 #7
0
ファイル: common_test.py プロジェクト: junaidsaiyed/beam
  def test_dofn_validate_finish_bundle_error(self):
    class MyDoFn(DoFn):
      def process(self, element):
        pass

      def finish_bundle(self, w1=DoFn.WindowParam):
        pass

    with self.assertRaises(AssertionError):
      DoFnSignature(MyDoFn())
コード例 #8
0
  def __init__(
      self, sdf, args_for_invoker, kwargs_for_invoker):
    self.sdf = sdf
    self._element_tag = _ValueStateTag('element')
    self._restriction_tag = _ValueStateTag('restriction')
    self.watermark_hold_tag = _ValueStateTag('watermark_hold')
    self._process_element_invoker = None

    self.sdf_invoker = DoFnInvoker.create_invoker(
        DoFnSignature(self.sdf), context=DoFnContext('unused_context'),
        input_args=args_for_invoker, input_kwargs=kwargs_for_invoker)

    self._step_context = None
コード例 #9
0
ファイル: sdf_common.py プロジェクト: zoyahav/beam
    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())
                          | 'random' >> ParDo(RandomUniqueKeyFn()))

        return keyed_elements | ProcessKeyedElements(
            sdf, element_coder, restriction_coder, pcoll.windowing,
            self._ptransform.args, self._ptransform.kwargs)
コード例 #10
0
    def __init__(self, sdf, args_for_invoker, kwargs_for_invoker):
        self.sdf = sdf
        self._element_tag = _ReadModifyWriteStateTag('element')
        self._restriction_tag = _ReadModifyWriteStateTag('restriction')
        self._watermark_state_tag = _ReadModifyWriteStateTag(
            'watermark_estimator_state')
        self.watermark_hold_tag = _ReadModifyWriteStateTag('watermark_hold')
        self._process_element_invoker = None
        self._output_processor = _OutputProcessor()

        self.sdf_invoker = DoFnInvoker.create_invoker(
            DoFnSignature(self.sdf),
            context=DoFnContext('unused_context'),
            output_processor=self._output_processor,
            input_args=args_for_invoker,
            input_kwargs=kwargs_for_invoker)

        self._step_context = None
コード例 #11
0
    def test_unbounded_element_process_fn(self):
        class UnboundedDoFn(DoFn):
            @DoFn.unbounded_per_element()
            def process(self, element):
                pass

        class BoundedDoFn(DoFn):
            def process(self, element):
                pass

        signature = DoFnSignature(UnboundedDoFn())
        self.assertTrue(signature.is_unbounded_per_element())
        signature = DoFnSignature(BoundedDoFn())
        self.assertFalse(signature.is_unbounded_per_element())
コード例 #12
0
 def matches(self, applied_ptransform):
     assert isinstance(applied_ptransform, AppliedPTransform)
     transform = applied_ptransform.transform
     if isinstance(transform, ParDo):
         signature = DoFnSignature(transform.fn)
         return signature.is_splittable_dofn()
コード例 #13
0
ファイル: sdf_common.py プロジェクト: aaltay/incubator-beam
 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()
コード例 #14
0
 def __init__(self, do_fn):
     self._signature = DoFnSignature(do_fn)
コード例 #15
0
 def start_bundle(self):
     signature = DoFnSignature(self._do_fn)
     self._invoker = DoFnInvoker.create_invoker(signature,
                                                process_invocation=False)
コード例 #16
0
ファイル: userstate_test.py プロジェクト: horvathaa/beamTest
 def _validate_dofn(self, dofn):
     # Construction of DoFnSignature performs validation of the given DoFn.
     # In particular, it ends up calling userstate._validate_stateful_dofn.
     # That behavior is explicitly tested below in test_validate_dofn()
     DoFnSignature(dofn)
コード例 #17
0
 def start_bundle(self):
   signature = DoFnSignature(self._do_fn)
   self._invoker = DoFnInvoker.create_invoker(
       signature,
       output_processor=_NoneShallPassOutputProcessor(),
       process_invocation=False)