python - 使用 PYTHON 运行 Google 数据流模板
问题描述
我想使用 PYTHON 执行 Google 数据流模板。实际上,我一直在使用Dataflow REST API
或Cloud Functions
集成来执行数据流模板。这是我在 Postman 中执行的数据流模板:
网址: https://dataflow.googleapis.com/v1b3/projects/{{my-project-id}}/templates:launch?gcsPath=gs://{{my-cloud-storage-bucket}}/temp/cloud-dataprep-template
{
"jobName": "test-datfalow-job",
"parameters": {
"inputLocations" : "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-folder/**/*\"}",
"outputLocations": "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-output/output.csv\"}"
},
"environment": {
"tempLocation": "gs://{{my-cloud-storage-bucket}}/tmp",
"zone": "us-central1-f"
}
}
我不知道是否有机会使用 google-api-python-client 或者我必须使用 python 的 requests.post 和 Google Cloud Authentication 执行这个 HTTP POST
解决方案
您可以使用Python 的 Dataflow API 客户端库中的模板启动方法来执行此操作,如下所示:
import googleapiclient.discovery
from oauth2client.client import GoogleCredentials
project = PROJECT_ID
location = LOCATION
credentials = GoogleCredentials.get_application_default()
dataflow = googleapiclient.discovery.build('dataflow', 'v1b3', credentials=credentials)
result = dataflow.projects().templates().launch(
projectId=project,
body={
"environment": {
"zone": "us-central1-f",
"tempLocation": "gs://{{my-cloud-storage-bucket}}/tmp"
},
"parameters": {
"inputLocations" : "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-folder/**/*\"}",
"outputLocations": "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-output/output.csv\"}"
},
"jobName": SOME_NAME
},
gcsPath = PATH_TO_TEMPLATE
).execute()
推荐阅读
- flask - 我在哪里可以设置 Keycloak 标头有效期
- java - JFileChooser 在 Mac 中不显示窗口
- c# - 如何在物体产生几秒钟后摧毁它?
- regex - 如何使用 Rust 正则表达式拆分字符串并保留分隔符?
- php - 使用 cron 作业每天从数组中获取 3 个项目
- jquery - 如何使预加载器图像首先加载
- angularjs - Angularjs - 使用“角度方式”在新选项卡中打开图像
- abap - 选择不明确/无效的列运行时错误
- android - 如何在没有引号的情况下写入数据库,java
- python - 更改其他 DataFrame 中的 DataFrame 行的值?