[英]How to transform bounded pcollection to unbounded in Python with Apache Beam?
[英]Apache Beam in python: How to reuse exactly the same transform on another PCollection
我的幾個 PCollections(來自不同來源)必須以相同的方式解碼。
hits = (msgs | 'Parse' >> beam.Map(parse)
| 'Decode' >> beam.Map(decode_hit))
然后:
dummy_hits = (dummy_msgs | 'Parse' >> beam.Map(parse)
| 'Decode' >> beam.Map(decode_hit))
多虧了我之前給它們的名字,如果我可以重用這些轉換,那就太好了。 我天真地嘗試了這個:
dummy_hits = (dummy_msgs | 'Parse'
| 'Decode')
但我的管道不會建立。 (類型錯誤:需要一個 PTransform 對象,得到解析)。
我認為有可能作為管道模塊的文檔說明:“如果需要應用相同的轉換實例,則應使用右移運算符來指定新名稱(例如input | "label" >> my_tranform
)”
這樣做的方法是什么? 只有這可能嗎?
名稱必須是唯一的,但由於您的步驟順序相同,因此您可能想要創建這樣的復合變換
https://beam.apache.org/get-started/wordcount-example/#creating-composite-transforms
所以這樣做:
class ParseDecode(beam.PTransform):
def expand(self, pcoll):
return (pcoll
| 'Parse' >> beam.Map(parse)
| 'Decode' >> beam.Map(decode_hit))
這樣你就可以做到這一點:
hits = (msgs | 'Parse msgs' >> ParseDecode()
然后這個:
dummy_hits = (dummy_msgs | 'Parse dummy msgs' >> ParseDecode()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.