问题描述
我计划有一个 Cloud Scheduler,每天早上 8 点调用 GCP 工作流。我的 GCP 工作流将有大约 15 个不同的 steps
,并且只是 BigQuery 上的转换(更新、删除、添加)。有些查询会很长,我想知道是否有办法将 .sql
文件加载到 GCP 工作流 task1.yaml
中?
#workflow entrypoint
ProcessItem:
params: [project,gcsPath]
steps:
- initialize:
assign:
- dataset: wf_samples
- input: ${gcsPath}
- sqlQuery: QUERY HERE
...
解决方法
您需要做类似的事情:(当然您可以将其分配给像 input
这样的变量)
#workflow entrypoint
main:
steps:
- getSqlfile:
call: http.get
args:
url: https://raw.githubusercontent.com/jisaw/sqlzoo-solutions/master/select-in-select.sql
headers:
Content-Type: "text/plain"
result: queryFromFile
- final:
return: ${queryFromFile.body}
对于可能如下所示的云存储:
call: http.get
args:
url: https://storage.cloud.google.com/................./q1.sql
headers:
Content-Type: "text/plain"
auth:
type: OIDC
result: queryFromFile
或者这种格式的事件(不同的 URL 语法 + OAuth2)
call: http.get
args:
url: https://storage.googleapis.com/................./q1.sql
headers:
Content-Type: "text/plain"
auth:
type: OAuth2
result: queryFromFile
确保调用者具有访问 Cloud Storage 文件的正确权限。
注意:在进一步测试中,这可以正常工作text/plain
必须在 GCS 文件中设置 mime-type。