尝试 运行 美国中部 1 区域的数据流作业,但源和目标位于 asia-south1

Trying to run a data flow job in us central 1 region but source and target is in asia-south1

想检查 post“ 中也提到的类似错误

我在数据流作业中遇到了类似的问题,出现如下错误

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

这是我尝试 运行 使用云函数触发器的代码时出现的错误。请在下面找到云功能代码。我的源数据和目标大查询数据集都位于亚洲南部 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 读取和写入数据。我还需要在云功能中添加什么,以便 region 和 zone 都是 us-central1 但数据是从 asia south 1 读取和写入的。

但是,当我 运行 使用以下命令手动使用云 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

请帮助任何人。一直在为这个问题苦苦挣扎。

我能够修复以下错误 “2021-03-10T06:02:26.115216545ZWorkflow 失败。原因:S01:Read 文件从 GCS/Read+ 字符串到 BigQuery 行+写入 BigQuery/NativeWrite 失败。,BigQuery 导入作业“dataflow_job_15712075439082970546-B”失败。项目“whr-asia-datalake-prod”中的 BigQuery 作业“dataflow_job_15712075439082970546-B”已完成,但出现错误:错误结果:无法在不同位置读取和写入:来源:美国,目的地:亚洲-south1,错误:无法在不同位置读写:来源:美国,目的地:asia-south1

我刚刚通过云功能更改为添加我的 asia-south 存储桶位置的临时位置,因为虽然我在创建模板时提供了 asia-south1 的 tmp 位置,但我的数据流作业中的 bigquery IO 正在尝试使用 us-central1 而不是 asia-south1 的临时位置,因此出现上述错误。