【发布时间】:2020-11-19 23:49:58
【问题描述】:
我正在尝试了解 Apache Beam。我在关注programming guide,在一个例子中,他们说谈论The following code example joins the two PCollections with CoGroupByKey, followed by a ParDo to consume the result. Then, the code uses tags to look up and format data from each collection.。
我很惊讶,因为我在任何时候都没有看到ParDo 操作,所以我开始怀疑| 是否真的是ParDo。代码如下所示:
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
emails_list = [
('amy', 'amy@example.com'),
('carl', 'carl@example.com'),
('julia', 'julia@example.com'),
('carl', 'carl@email.com'),
]
phones_list = [
('amy', '111-222-3333'),
('james', '222-333-4444'),
('amy', '333-444-5555'),
('carl', '444-555-6666'),
]
pipeline_options = PipelineOptions()
with beam.Pipeline(options=pipeline_options) as p:
emails = p | 'CreateEmails' >> beam.Create(emails_list)
phones = p | 'CreatePhones' >> beam.Create(phones_list)
results = ({'emails': emails, 'phones': phones} | beam.CoGroupByKey())
def join_info(name_info):
(name, info) = name_info
return '%s; %s; %s' %\
(name, sorted(info['emails']), sorted(info['phones']))
contact_lines = results | beam.Map(join_info)
我确实注意到emails 和phones 在管道开始时被读取,所以我猜他们两个是不同的PCollections,对吧?但是ParDo 在哪里执行? “|”是什么意思而“>>”实际上是什么意思?我怎么能看到这个的实际输出? join_info 函数、emails_list 和 phones_list 是否在 DAG 外部定义有关系吗?
【问题讨论】: