【问题标题】:Does Dataflow templating supports template input for BigQuery sink options?Dataflow 模板是否支持 BigQuery 接收器选项的模板输入?
【发布时间】:2017-11-06 10:33:34
【问题描述】:

由于我有一个正在运行的静态数据流,我想从这个模板创建一个模板,让我可以轻松地重用数据流,而无需输入任何命令行。

按照官方的Creating Templates 教程没有提供模板输出的示例。

我的数据流以 BigQuery 接收器结束,它接受一些参数,例如用于存储的目标表。这个确切的参数是我想在我的模板中提供的参数,允许我在运行流程后选择目标存储。

但是,我无法让这个工作。下面我粘贴了一些代码 sn-ps 可以帮助解释我遇到的确切问题。

class CustomOptions(PipelineOptions):
    @classmethod
    def _add_argparse_args(cls, parser):
        parser.add_value_provider_argument(
            '--input',
            default='gs://my-source-bucket/file.json')
        parser.add_value_provider_argument(
            '--table',
            default='my-project-id:some-dataset.some-table')

pipeline_options = PipelineOptions()

pipe = beam.Pipeline(options=pipeline_options)

custom_options = pipeline_options.view_as(CustomOptions)

(...)

# store
processed_pipe | beam.io.Write(BigQuerySink(
    table=custom_options.table.get(),
    schema='a_column:STRING,b_column:STRING,etc_column:STRING',
    create_disposition=BigQueryDisposition.CREATE_IF_NEEDED,
    write_disposition=BigQueryDisposition.WRITE_APPEND
))

创建模板时,我没有提供任何参数。瞬间,我收到以下错误消息:

apache_beam.error.RuntimeValueProviderError: RuntimeValueProvider(option: table, type: str, default_value: 'my-project-id:some-dataset.some-table').get() not called from a runtime context

当我在创建模板时添加--table 参数时,正在创建模板,但--table 参数值随后被硬编码在模板中,并且不会被table 的任何给定模板值覆盖。

当我将 table=custom_options.table.get(), 替换为 table=StaticValueProvider(str, custom_options.table.get()) 时,我遇到了同样的错误。

是否有人已经使用可自定义的 BigQuerySink 参数构建了可模板化的数据流?我很想得到一些提示。

【问题讨论】:

  • 稍后我会为您解答。

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


【解决方案1】:

Python 目前仅支持 FileBasedSource IO 的 ValueProvider 选项。您可以通过单击您提到的链接上的 Python 选项卡来查看: https://cloud.google.com/dataflow/docs/templates/creating-templates

在“管道 I/O 和运行时参数”部分下。

与 Java 中发生的情况不同,Python 中的 BigQuery 不使用自定义源。换句话说,它没有在 SDK 中完全实现,但也包含后端的部分(因此它是“原生源”)。只有自定义来源可以使用模板。有计划将 BigQuery 添加为自定义源:issues.apache.org/jira/browse/BEAM-1440

【讨论】:

  • 这有什么更新吗?我正在从事的项目需要此功能...
  • 我欢迎有关 python BigQuerySink 的动态表名称方法的更新。这阻止了我创建暂存模板,因为表名在运行时没有得到评估。
  • 这方面有什么更新吗?现在是 2020 年,我也遇到了同样的问题..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-29
  • 1970-01-01
  • 2012-08-16
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 1970-01-01
相关资源
最近更新 更多