以官方文档“创建模板”为例:
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
。然而,在创建模板时它不具有属性“value”,只有“default_value”。 我尝试在创建模板时指定一个值(以便现在和以后都可以使用它),但无论我在运行时指定什么值,它都只使用我在创建模板时指定的先前值。(基本上,我的输入是一个 pickle 文件,所以不能直接使用 wordcount_options.input
。)