简体   繁体   English

apache beam 中的管道语法是如何实现的?

[英]How is pipe syntax implemented in apache beam?

I am now studying apache beam and out of curiosity, I would like to ask below question.我现在正在研究apache beam ,出于好奇,我想问以下问题。

In advance, I have read below documents and threads.事先,我已阅读以下文档和线程。

https://beam.apache.org/documentation/programming-guide/#applying-transforms https://beam.apache.org/documentation/programming-guide/#applying-transforms

Explain Apache Beam python syntax 解释 Apache Beam python 语法

I understand that pipe( | ) is the python version of .apply of java.我知道 pipe( | ) 是.apply的 python 版本。 However, I am curious to know how does python interpret __or__ operator as processor which processes each pcollection element that goes through from left to right.但是,我很想知道 python 如何将__or__运算符解释为处理从左到右通过的每个 pcollection 元素的处理器。

I appreciate if someone could educate me and point me the reference of code.如果有人可以教育我并指出代码参考,我将不胜感激。

Thanks, Yu谢谢,于

I would like to mark @Kolban 's reply as answer.我想将@Kolban 的回复标记为答案。

I did a Google search on "python operator overloading" and found a bunch of good references that seem likely.我在 Google 上搜索了“python 运算符重载”,发现了一堆看起来很有可能的很好的参考资料。 Searching the Github repository, it looks likely that this may be the actual code: https://github.com/apache/beam/blob/master/sdks/python/apache_beam/transforms/ptransform.py#L470搜索 Github 存储库,看起来这可能是实际代码: https ://github.com/apache/beam/blob/master/sdks/python/apache_beam/transforms/ptransform.py#L470

It does so via operator overloading :它通过运算符重载来实现:

def __or__(self, right):
  """Used to compose PTransforms, e.g., ptransform1 | ptransform2."""
  if isinstance(right, PTransform):
    return _ChainedPTransform(self, right)
  return NotImplemented

Piping (|) is used to compose PTransforms , eg, ptransform1 | ptransform2管道 (|) 用于组成PTransforms ,例如ptransform1 | ptransform2 ptransform1 | ptransform2 . ptransform1 | ptransform2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM