Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何使用当前日期作为输入创建梁模板(每天更新)[从GET请求创建]_Templates_Apache Beam_Dataflow_Apache Beam Io_Value Provider - Fatal编程技术网

Templates 如何使用当前日期作为输入创建梁模板(每天更新)[从GET请求创建]

Templates 如何使用当前日期作为输入创建梁模板(每天更新)[从GET请求创建],templates,apache-beam,dataflow,apache-beam-io,value-provider,Templates,Apache Beam,Dataflow,Apache Beam Io,Value Provider,我正在尝试创建一个每天使用云调度器运行的数据流作业。我需要使用get请求从外部API获取数据,因此我需要当前日期作为输入。但是,当我将数据流作业导出为调度模板时,日期输入保持在执行时,而不是每天更新。我一直在寻找解决方案,遇到了ValueProvider,但我的管道使用了apache\u beam.transforms.Create始终返回一个错误“RuntimeValueProvider(option:test,type:str,default\u value:'killme')。未指定Val

我正在尝试创建一个每天使用云调度器运行的数据流作业。我需要使用get请求从外部API获取数据,因此我需要当前日期作为输入。但是,当我将数据流作业导出为调度模板时,日期输入保持在执行时,而不是每天更新。我一直在寻找解决方案,遇到了ValueProvider,但我的管道使用了
apache\u beam.transforms.Create
始终返回一个错误“RuntimeValueProvider(option:test,type:str,default\u value:'killme')。未指定ValueProvider时,get()未从运行时上下文调用”


我有没有办法克服这个问题?这似乎是一个如此简单的问题,但我无法使它工作,无论如何。如果有任何想法,我将不胜感激

您可以使用ValueProvider接口将运行时参数传递给管道,要在DoFn中访问它,您需要将其作为参数传递进来。与下面的示例类似:

您可能还想看看Flex模板:


谢谢您的帮助!
class LogValueProvidersFn(beam.DoFn):
  def __init__(self, string_vp):
    self.string_vp = string_vp

  # Define the DoFn that logs the ValueProvider value.
  # The DoFn is called when creating the pipeline branch.
  # This example logs the ValueProvider value, but
  # you could store it by pushing it to an external database.
  def process(self, an_int):
    logging.info('The string_value is %s' % self.string_vp.get())
    # Another option (where you don't need to pass the value at all) is:
    logging.info(
        'The string value is %s' %
        RuntimeValueProvider.get_value('string_value', str, ''))

  | beam.Create([None])
  | 'LogValueProvs' >> beam.ParDo(
      LogValueProvidersFn(my_options.string_value)))