2017-11-21 5 views
1

は、一例として 'テンプレートの作成' の公式文書を取る: https://cloud.google.com/dataflow/docs/templates/creating-templates'add_value_provider_argument'を使用してランタイムパラメータを初期化する方法は?

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'のみがあります。私は、テンプレートを作成するときに値を指定しようとするので(今すぐ使用できるように)、実行時に指定する値は何もなく、テンプレートを作成するときに指定した前の値だけが使用されます。

(私は直接wordcount_options.inputを使用することはできませんので、基本的に、私の入力は漬物ファイルです。)

答えて

0

だけリンクされている例以下のセクションUsing ValueProvider in your functionsです。

ドキュメントでは、ValueProviderパラメータの.get()メソッドを使用してランタイム値を取得する方法を示しています。

この値は、テンプレートから挿入されていないため、パイプラインの構築中に使用できないことに注意してください。 DoFn.process()のように、実行時メソッドの内部でValueProvider.get()とだけ呼び出す必要があります。

関連する問題