Google Cloud Dataflow消耗外部资源 [英] Google Cloud Dataflow consume external source

查看:93
本文介绍了Google Cloud Dataflow消耗外部资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,Dataflow背后的概念有点问题.特别是关于管道的构造方式.

So I am having a bit of a issue with the concepts behind Dataflow. Especially regarding the way the pipelines are supposed to be structured.

我正在尝试使用一个外部API,该API提供了索引XML文件以及指向单独XML文件的链接.一旦获得了所有XML文件的内容,就需要将它们拆分为单独的PCollection,以便可以完成其他PTransforms.

I am trying to consume an external API that delivers an index XML file with links to separate XML files. Once I have the contents of all the XML files I need to split those up into separate PCollections so additional PTransforms can be done.

在可以下载和读取产品XML之前,需要先下载并读取第一个xml文件这一事实使我难以为继.正如文档所述,管道以Source开头,以Sink结尾.

It is hard to wrap my head around the fact that the first xml file needs to be downloaded and read, before the product XML's can be downloaded and read. As the documentation states that a pipeline starts with a Source and ends with a Sink.

所以我的问题是:

  • 对于这种任务,Dataflow甚至是正确的工具吗?
  • 自定义来源是要合并整个过程,还是应该在单独的步骤/管道中完成?
  • 可以在管道中处理此问题,然后让另一个管道读取文件吗?
  • 此过程的高层概述如何?

注意事项:我正在为此使用Python SDK,但这可能并不真正相关,因为这更多是架构问题.

Things to note: I am using the Python SDK for this, but that probably isn't really relevant as this is more a architectural problem.

推荐答案

是的,这绝对可以做到.现在,刚开始时有点笨拙,但是即将在名为SplittableDoFn的新原语上进行的工作将使这种模式将来变得更加容易.

Yes, this can absolutely be done. Right now, it's a little klutzy at the beginning, but upcoming work on a new primitive called SplittableDoFn should make this pattern much easier in the future.

  1. 首先使用Create创建一个具有单个元素的虚拟PCollection.
  2. 使用DoFn处理该PCollection,该DoFn下载文件,读出子文件并发出子文件.
  3. [可选]此时,您可能希望并行进行工作.为了使系统易于并行化,您需要执行一个语义上不必要的GroupByKey,然后执行ParDo来撤消"分组.这会将这些文件名具体化到临时存储中,从而使系统可以让不同的工作人员处理每个元素.
  4. 通过读取每个子文件的内容来处理每个子文件,并将其发送到PCollections中.如果要对不同的文件内容进行不同的处理,请使用分区"将它们分类到不同的PCollection中.
  5. 进行相关处理.

这篇关于Google Cloud Dataflow消耗外部资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆