Dataflow 中的自定义 Apache Beam Python 版本

Custom Apache Beam Python version in Dataflow

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

我知道可以按照官方 documentation. There are answered are questions here on how to do this for some other scripts. And there is even a GIST guiding 中的描述打包自定义包(例如私人本地包)。

但我还没有设法获得当前的 Apache Beam 开发版本(或标记的版本),该版本在其官方存储库的主分支中可用,无法打包并与我的脚本一起发送到 Google Dataflow . 例如,对于最新的可用标签,PiP 处理的 link 将是: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 版本。

我会在我一直在帮助的一个 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 repositoryHEAD 版本,您必须首先通过导航到Python SDK cd beam/sdks/python 然后是 运行 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。