我有一个用下面的命令创建的数据流模板
python scrap.py --setup_file /home/deepak_verma/setup.py
--temp_location gs://visualization-dev/temp
--staging_location gs://visualization-dev/stage
--project visualization-dev --job_name scrap-job
--subnetwork regions/us-east1/subnetworks/dataflow-internal
--region us-east1 --input sentiment_analysis.table_view
--output gs://visualization-dev/incoming
--runner DataflowRunner
--template_location gs://visualization-dev/template/scrap
我的数据流管道接受输入和输出参数作为值提供者,如下所示
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
'--input', dest='input', required=True,
help='Input view. sentiment_analysis.table_view',
)
parser.add_value_provider_argument(
'--output', dest='output', required=True,
help='output gcs file path'
)
我把它当做
beam.io.Read(beam.io.BigQuerySource(query=read_query.format(
table=options.input.get(), limit=(LIMIT and "limit " + str(LIMIT) or '')), use_standard_sql=True)))
where read_query is defined as `SELECT upc, max_review_date FROM `{table}`
现在,当我使用不同的输入参数调用这个模板时
template_body = {
'jobName': job_name,
'parameters': {'input': 'table_view2'}
}
credentials = GoogleCredentials.get_application_default()
service = build('dataflow', 'v1b3', credentials=credentials)
request = service.projects().locations().templates().launch(projectId=constants.GCP_PROJECT_ID, location=constants.REGION, gcsPath=template_gcs_path, body=template_body)
数据流不会为table_view2调用此函数,而是使用此作业的table_view。
发布于 2019-02-06 19:45:01
问题是,在暂存模板时,您已经传递了一个input
值,而这正是要解决的问题。运行第一个命令时删除--input sentiment_analysis.table_view
,并将其保留为空。仅在使用'parameters': {'input': 'sentiment_analysis.table_view2'}
执行模板时将其指定为参数。
如果您仍然需要默认值,可以在添加value provider参数时使用,就像在this example中一样
parser.add_value_provider_argument(
'--input', dest='input', required=True,
help='Input view. sentiment_analysis.table_view',
default='sentiment_analysis.table_view'
)
发布于 2019-03-22 22:46:21
您需要的是能够将查询作为ValueProvider传递,而不是作为已经格式化的字符串。这在Beam中是不可能的。
这里有一个开放的特性请求:https://issues.apache.org/jira/browse/BEAM-1440
https://stackoverflow.com/questions/54559079
复制