【发布时间】:2017-11-21 16:22:58
【问题描述】:
以官方文档《创建模板》为例: https://cloud.google.com/dataflow/docs/templates/creating-templates
class WordcountOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
# Use add_value_provider_argument for arguments to be templatable
# Use add_argument as usual for non-templatable arguments
parser.add_value_provider_argument(
'--input',
default='gs://dataflow-samples/shakespeare/kinglear.txt',
help='Path of the file to read from')
parser.add_argument(
'--output',
required=True,
help='Output file to write results to.')
pipeline_options = PipelineOptions(['--output', 'some/output_path'])
p = beam.Pipeline(options=pipeline_options)
wordcount_options = pipeline_options.view_as(WordcountOptions)
lines = p | 'read' >> ReadFromText(wordcount_options.input)
wordcount_options.input 是一个 RuntimeValueProvider。我想使用运行时指定的值(执行模板),所以我需要使用wordcount_options.input.value。但是,它在创建模板时没有属性“值”。它只有“default_value”。我尝试在创建模板时指定一个值(以便我现在和以后都可以使用它),但无论我在运行时指定什么值,它都只使用我在创建模板时指定的先前值。
(基本上,我的输入是一个pickle文件,所以我不能直接使用wordcount_options.input。)
【问题讨论】:
标签: python google-cloud-dataflow apache-beam