【问题标题】:ValueProvider type parameters not getting honored at the template execution timeValueProvider 类型参数在模板执行时未得到遵守
【发布时间】:2018-09-10 18:20:05
【问题描述】:

我正在尝试传递 BigTable tableId、instanceId 和 projectId,它们在执行时在 TemplateOption 类中定义为 ValueProvider,因为它们是运行时值,但它们不会得到新值的认可。管道使用构建管道时定义的旧值执行。我应该进行哪些更改以使其在运行时尊重值?

Pipeline p = Pipeline.create(options);
com.google.cloud.bigtable.config.BigtableOptions.Builder optionsBuilder =
        new com.google.cloud.bigtable.config.BigtableOptions.Builder().
                setProjectId("my-project");   

PCollection<com.google.bigtable.v2.Row> row = p.apply("filtered read", org.apache.beam.sdk.io.gcp.bigtable.BigtableIO.read().withBigtableOptions(optionsBuilder).withoutValidation().withInstanceId(options.getInstanceId()).withProjectId(options.getProjectId()).withTableId(options.getTableId()));
PCollection<KV<Integer,String>> convertToKV = row.apply(ParDo.of(new ConvertToKV()));  

我的 Option 类看起来像:--

@Default.String("my-project")
@Description("The Google Cloud project ID for the Cloud Bigtable instance.")
ValueProvider<String> getProjectId();
void setProjectId(ValueProvider<String> projectId);

@Default.String("my-instance")
@Description("The Google Cloud Bigtable instance ID .")
ValueProvider<String> getInstanceId();
void setInstanceId(ValueProvider<String> instanceId);

@Default.String("my-test")
@Description("The Cloud Bigtable table ID in the instance." )
ValueProvider<String> getTableId();
void setTableId(ValueProvider<String> tableId);

@Description("bucket name")
@Default.String("mybucket")
ValueProvider<String> getBucketName();
void setBucketName(ValueProvider<String> bucketName);

任何帮助将不胜感激。

【问题讨论】:

  • 不要在构建时指定值。施工时指定的内容,保持在指定的内容;未指定的内容将在运行时取值。
  • 如果我没有指定 ValueProvider 类型的 tableId、instanceId 和 projectId 的值,则会在构造时引发错误...这是我得到的错误...。由:java.lang.IllegalArgumentException:在 org.apache.beam.sdk.io.gcp.bigtable.BigtableIO$BigtableSource.validate 的 com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) 中未提供 tableId (BigtableIO.java:995) 在 org.apache.beam.sdk.io.Read$Bounded.expand(Read.java:98)
  • 这是我用来构造的... mvn -X compile exec:java -Dexec.mainClass=com.grid.GridProcessingPipeline -Dexec.args="--runner=DataflowRunner --project =my-project --stagingLocation=gs://my-bucket/staging --tempLocation=gs://my-bucket/temp/ --templateLocation=gs://my-bucket/templates/MyTemplate"
  • 啊。这是 BigtableIO 中的一个错误。您介意在issues.apache.org/jira/browse/BEAM 提交 JIRA 或通过电子邮件发送给 user@beam.apache.org 邮件列表吗?

标签: google-cloud-dataflow apache-beam google-cloud-bigtable


【解决方案1】:

我确实认为在构建时验证运行时参数是一个问题。但是,我不明白的是不遵守使用模板执行管道时传递的运行时参数。

如何传递运行时参数? 应该是这样的:

  public interface WordCountOptions extends PipelineOptions {
    @Description("Path of the file to read from")
    @Default.String("gs://dataflow-samples/shakespeare/kinglear.txt")
    ValueProvider<String> getInputFile();
    void setInputFile(ValueProvider<String> value);
  }

    public static void main(String[] args) {
        WordCountOptions options =
              PipelineOptionsFactory.fromArgs(args).withValidation()
                .as(WordCountOptions.class);
        Pipeline p = Pipeline.create(options);

详见“创建模板”:https://cloud.google.com/dataflow/docs/templates/creating-templates

构建模板后,您可以使用运行时参数执行管道。例如:

gcloud beta dataflow jobs run test-run1 \
        --gcs-location gs://my_template/templates/DemoTemplate \
        --parameters inputFile=/path/to/my-file

详见“执行模板”:https://cloud.google.com/dataflow/docs/templates/executing-templates

注意:如果在执行管道时不传递运行时参数,则参数将具有默认值或 null。

希望这会有所帮助!

【讨论】:

【解决方案2】:

我相信--inputFiles 是在创建模板时与模板捆绑在一起的。

请参阅注释1:“除了模板文件,模板化管道执行还依赖于在创建模板时暂存和引用的文件。如果暂存文件被移动或删除,您的管道执行将失败。”

这个帖子似乎也很相关2

【讨论】:

    【解决方案3】:

    更新:

    使用 Flex 模板,我们可以轻松地在运行时传递值

    https://cloud.google.com/dataflow/docs/guides/templates/using-flex-templates#top_of_page

    旧:

    我们也遇到了同样的异常,为了解决这个问题,我们为 ValueProvider 配置添加了虚拟默认值,而不是在编译时传递值,只在运行时传递,它工作正常。

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2010-11-03
      相关资源
      最近更新 更多