Dataflow 中的自定义 Apache Beam Python 版本

Posted

技术标签:

【中文标题】Dataflow 中的自定义 Apache Beam Python 版本【英文标题】:Custom Apache Beam Python version in Dataflow 【发布时间】:2018-01-03 01:50:36 【问题描述】:

我想知道是否可以在 Google Dataflow 中运行自定义 Apache Beam Python 版本。公共存储库中不可用的版本(撰写本文时:0.6.0 和 2.0.0)。例如,来自 Apache Beam 官方存储库的 HEAD 版本,或与此相关的特定标签。

我知道按照官方documentation 中的描述打包自定义包(例如本地私有包)的可能性。有回答是questions 这里关于如何为其他一些脚本执行此操作。甚至还有一个 GIST guiding。

但是我还没有设法获得其官方存储库的主分支中可用的当前 Apache Beam 开发版本(或标记的版本)来打包并与我的脚本一起发送到 Google Dataflow。 例如,对于最新的可用标签,其 PiP 处理的链接为:git+https://github.com/apache/beam.git@v2.1.0-RC2#egg=apache_beam[gcp]&subdirectory=sdks/python 我得到如下信息:

INFO:root:Executing command: ['.../bin/python', '-m', 'pip', 'install', '--download', '/var/folders/nw/m_035l9d7f1dvdbd7rr271tcqkj80c/T/tmpJhCkp8', 'apache-beam==2.1.0', '--no-binary', ':all:', '--no-deps']
DEPRECATION: pip install --download has been deprecated and will be removed in the future. Pip now has a download command that should be used instead.
Collecting apache-beam==2.1.0
  Could not find a version that satisfies the requirement apache-beam==2.1.0 (from versions: 0.6.0, 2.0.0)
No matching distribution found for apache-beam==2.1.0

有什么想法吗? (我想知道这是否可能,因为 Google Dataflow 可能已经修复了可以运行到官方发布的版本的 Apache Beam。

【问题讨论】:

【参考方案1】:

当我在我一直在帮助的一个 Apache Beam 的 JIRA 上得到这个问题的答案时,我会回答自己。

如果您想在 Google Cloud Dataflow 中使用自定义 Apache Beam Python 版本(即,使用--runner DataflowRunner 运行您的管道,则在运行您的管道时必须使用选项--sdk_location <apache_beam_v1.2.3.tar.gz>;其中<apache_beam_v1.2.3.tar.gz> 是您要使用的对应打包版本的位置。

例如,在撰写本文时,如果您检查了 Apache Beam 的 git repository 的 HEAD 版本,则必须首先通过使用 cd beam/sdks/python 导航到 Python SDK 来打包存储库,然后运行python setup.py sdist(将在dist子目录中创建一个压缩的tar文件)。

之后你可以像这样运行你的管道:

python your_pipeline.py [...your_options...] --sdk_location beam/sdks/python/dist/apache-beam-2.2.0.dev0.tar.gz

Google Cloud Dataflow 将使用提供的 SDK。

【讨论】:

感谢您发布此信息 - 他们告诉您使用 gradle 进行构建,但与您建议的运行香草 sdist 相比,这是巨大的过度杀伤力。 是否也可以指定Python版本?

以上是关于Dataflow 中的自定义 Apache Beam Python 版本的主要内容,如果未能解决你的问题,请参考以下文章

防止 Apache Beam / Dataflow 流 (python) 管道中的融合以消除管道瓶颈

我可以在多个键(连接条件)上连接 Dataflow(Apache Beam)中的两个表吗?

apache spark中的自定义分区器

如何在Apache Beam / Google Dataflow中使用ParseJsons?

Apache Beam/Google Dataflow - 将数据从 Google Datastore 导出到 Cloud Storage 中的文件

Eclipse 上带有 Dataflow Runner 的 Apache Beam MinimalWordcount 示例