【发布时间】:2021-03-12 08:21:09
【问题描述】:
想要检查帖子“https://stackoverflow.com/questions/37298504/google-dataflow-job-and-bigquery-failing-on-different-regions?rq=”中也提到的类似错误1"
我在数据流作业中遇到了类似的问题,出现如下错误
2021-03-10T06:02:26.115216545ZWorkflow failed. Causes: S01:Read File from GCS/Read+String To BigQuery Row+Write to BigQuery/NativeWrite failed., BigQuery import job "dataflow_job_15712075439082970546-B" failed., BigQuery job "dataflow_job_15712075439082970546-B" in project "whr-asia-datalake-prod" finished with error(s): errorResult: Cannot read and write in different locations: source: US, destination: asia-south1, error: Cannot read and write in different locations: source: US, destination: asia-south1
这是我尝试使用云函数触发器运行代码时出现的错误。请在下面找到云功能代码。我的源数据和目标大查询数据集都位于 asia south 1
"""
Google cloud funtion used for executing dataflow jobs.
"""
from googleapiclient.discovery import build
import time
def df_load_function(file, context):
filesnames = [
'5667788_OPTOUT_',
'WHR_AD_EMAIL_CNSNT_RESP_'
]
# Check the uploaded file and run related dataflow jobs.
for i in filesnames:
if 'inbound/{}'.format(i) in file['name']:
print("Processing file: {filename}".format(filename=file['name']))
project = '<my project>'
inputfile = 'gs://<my bucket>/inbound/' + file['name']
job = 'df_load_wave1_{}'.format(i)
template = 'gs://<my bucket>/template/df_load_wave1_{}'.format(i)
location = 'us-central1'
dataflow = build('dataflow', 'v1b3', cache_discovery=False)
request = dataflow.projects().locations().templates().launch(
projectId=project,
gcsPath=template,
location=location,
body={
'jobName': job,
"environment": {
"workerZone": "us-central1-a"
}
}
)
# Execute the dataflowjob
response = request.execute()
job_id = response["job"]["id"]
我将 location 和 workerzone 分别保留为 us-central1 和 us-central1-a。由于一些资源问题,我需要在 us central 1 中运行我的数据流作业,但从 asia-south1 读取和写入数据。我还需要在云功能中添加什么,以便区域和区域都是 us-central1,但数据是从 asia south 1 读取和写入的。
但是,当我使用以下命令使用 cloud shell 手动运行我的作业时,它可以正常工作并加载数据。这里 region 和 zone 都是 us-central1
python -m <python script where the data is read from bucket and load big query> \
--project <my_project> \
--region us-central1 \
--runner DataflowRunner \
--staging_location gs://<bucket_name>/staging \
--temp_location gs://<bucket_name>/temp \
--subnetwork https://www.googleapis.com/compute/v1/projects/whr-ios-network/regions/us-central1/subnetworks/<subnetwork> \
--network projects/whr-ios-network/global/networks/<name> \
--zone us-central1-a \
--save_main_session
请帮助任何人。一直在努力解决这个问题。
【问题讨论】:
-
你好@cahen,我知道你也有类似的问题。你能告诉我你是怎么解决的吗?
-
将来自不同区域的资源用于源数据和目标数据并不是最佳做法。这会大大减慢你的进程。我建议您应该将数据源和目标迁移到另一个没有资源问题的区域。
标签: google-bigquery google-cloud-functions google-cloud-dataflow