google-cloud-dataflow - DataflowPipelineOptions:在 arg 解析后使用 .setRunner 显式设置运行器
问题描述
在数据流 SDK 2.4.0 中,我曾经能够运行:
PipelineOptionsFactory.register(MyPipelineOptions.class);
MyPipelineOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().create().as(MyPipelineOptions.class);
options.setRunner(DataflowRunner.class);
但是,在 Apache Beam SDK 2.9.0 中,我需要使用 args 设置运行器--runner=DataflowRunner
,否则它会失败create()
(第二行)。setRunner
这是期望的行为,还是在从 args 读取其他选项后仍然可以设置跑步者使用?
使用的 Maven 依赖项:
<dependencies>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
解决方案
显然,如果在创建选项对象时没有指定运行器,则默认为 DirectRunner。因此,即使稍后使用 setRunner 定义另一个运行器,只是为了能够创建未指定运行器的选项对象,DirectRunner 也需要在类路径中。
要使其工作,您只需添加依赖项即可在您的类路径中包含 DirectRunner
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-direct-java</artifactId>
<version>2.9.0</version>
</dependency>
推荐阅读
- python - 使用 Tkinter 和 Matplotlib 单击时,如何显示 2 条不同曲线的 y 值?
- java - Java中的SQLite(要求用户输入字符串并将所有数据输出到表中)
- ruby-on-rails - Heroku 部署:Rails 应用程序错误(检测 rails 配置失败)
- c - 如何使用 C 在 Linux 上设置非阻塞命名管道?
- r - EPEL & Codeready-builder AWS EC2 RHEL8
- javascript - d3.v5.min.js:2 Uncaught TypeError:无法将未定义或空值转换为对象
- r - 如何摆脱 R 中字符串中的一个反斜杠?
- php - 使用 jquery 和 ajax 从组合框中获取数据
- javascript - 如何在 WordPress Woo-Commerce 插件上获取所有包含的产品
- javascript - 我想在每次用户单击按钮时更改 src,我该怎么做?