【发布时间】:2020-08-06 18:00:58
【问题描述】:
任何人都可以分享数据流 python 代码来接受参数吗?通过rest API传递的参数我面临同样的问题。我的 df 代码如下:-
def run(argv=None):
parser = argparse.ArgumentParser()
# Specifically we have the input file in CSV format to read and the output BQ table to write.
# This is the final stage of the pipeline, where we define the destination
parser.add_argument(
'--input',
dest='input',
required=False,
help='Input file to read. This can be a local file or '
'a file in a Google Storage Bucket.',
# This example file contains a total of only 10 lines.
# Useful for developing on a small set of data.
default='gs://intient_output/measurementunit.csv')
parser.add_argument(
'--output',
dest='output',
required=False,
help='Output file to be written. This can be a local file or '
'a file in a Google Storage Bucket.',
default='mygcpdataengineerlab:intientpoc.measurementunit'
)
# Parse arguments from the command line.
known_args, pipeline_args = parser.parse_known_args(argv)
data_ingestion = DataIngestion()
project = ''
p = beam.Pipeline(options=PipelineOptions(pipeline_args))
下面的异常堆栈跟踪
Error- response = request.execute()
File "/env/local/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/env/local/lib/python3.7/site-packages/googleapiclient/http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://dataflow.googleapis.com/v1b3/projects/mygcpdataengineerlab/templates:launch?gcsPath=gs%3A%2F%2Fgcp_dataflow_csv_bq_code%2Ftemplates&alt=json returned "(9744cfd1809f74a): The workflow could not be created. Causes: (9744cfd1809fa2d): Found unexpected parameters: ['input' (perhaps you meant 'update'), 'output' (perhaps you meant 'job_port')]">
【问题讨论】:
-
确保将 --input 和 --output 传递给正确的程序。发生此错误是因为您必须以某种方式将 --input 和 --output 传递给 Dataflow 服务。 Dataflow 本身无法识别 --input 和 --output,只有 Python 脚本中的自定义解析器可以识别这些选项。如果您仍然遇到问题,可以提供有关如何运行作业的更多信息。
-
我正在通过云功能运行代码如下:-
-
template_body = { "jobName": job, "parameters": { "input": "gs://input/abc.csv", "output": "project:dataset.table", }, "环境": { "tempLocation": "gs://gcp_dataflow_csv_bq_code/temp", } } request = service.projects().templates().launch(projectId=gcp_project, gcsPath=template_path, body=template_body) 响应= request.execute() 当我删除参数选项时,df 被默认选项触发
-
我还创建了一个 _metadata 文件 { "description": "Dataflow job template to load data from csv to BQ", "name": "parameters", "parameters": [ "name": " input", "name": "output", ] } 根据链接harness.io/2019/10/…
-
我明白了。您的代码与您提供的示例之间的区别在于您直接使用 argparse,而示例正确使用了 Beam 的参数解析器。您将需要创建 Beam 的 PipelineOptions 的子类来定义您的自定义参数,例如他们示例中的 UserOptions。
标签: google-cloud-platform google-cloud-functions google-cloud-dataflow