【发布时间】: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