【问题标题】:bigquery DataFlow Error: Cannot read and write in different locations while reading and writing in EUbigquery DataFlow 错误:在欧盟读写时无法在不同位置读写
【发布时间】:2017-10-15 10:11:05
【问题描述】:

我有一个简单的 Google DataFlow 任务。它从 BigQuery 表中读取数据并写入另一个表,如下所示:

(p
 |  beam.io.Read( beam.io.BigQuerySource(
        query='select dia, import from DS1.t_27k where true', 
        use_standard_sql=True))
 |  beam.io.Write(beam.io.BigQuerySink(
                  output_table,
                  dataset='DS1', 
                  project=project, 
                  schema='dia:DATE, import:FLOAT',
                  create_disposition=CREATE_IF_NEEDED,
                      write_disposition=WRITE_TRUNCATE
                     )
                )

我想问题是,这条管道似乎需要一个临时数据集才能完成工作。而且我无法为这个临时数据集强制定位。因为我的 DS1 在欧盟 (#EUROPE-WEST1) 并且临时数据集在美国(我猜),所以任务失败:

WARNING:root:Dataset m-h-0000:temp_dataset_e433a0ef19e64100000000000001a does not exist so we will create it as temporary with location=None
WARNING:root:A task failed with exception.
 HttpError accessing <https://www.googleapis.com/bigquery/v2/projects/m-h-000000/queries/b8b2f00000000000000002bed336369d?alt=json&maxResults=10000>: response: <{'status': '400', 'content-length': '292', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'expires': 'Sat, 14 Oct 2017 20:29:15 GMT', 'vary': 'Origin, X-Origin', 'server': 'GSE', '-content-encoding': 'gzip', 'cache-control': 'private, max-age=0', 'date': 'Sat, 14 Oct 2017 20:29:15 GMT', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'quic=":443"; ma=2592000; v="39,38,37,35"', 'content-type': 'application/json; charset=UTF-8'}>, content <{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Cannot read and write in different locations: source: EU, destination: US"
   }
  ],
  "code": 400,
  "message": "Cannot read and write in different locations: source: EU, destination: US"
 }
}

管道选项:

options = PipelineOptions()

google_cloud_options = options.view_as(GoogleCloudOptions)
google_cloud_options.project = 'm-h'
google_cloud_options.job_name = 'myjob3'
google_cloud_options.staging_location = r'gs://p_df/staging'  #EUROPE-WEST1
google_cloud_options.region=r'europe-west1'
google_cloud_options.temp_location = r'gs://p_df/temp' #EUROPE-WEST1
options.view_as(StandardOptions).runner =   'DirectRunner'  #'DataflowRunner'

p = beam.Pipeline(options=options)

如何避免此错误?

注意错误仅在我以DirectRunner 运行时出现。

【问题讨论】:

    标签: python google-bigquery google-cloud-dataflow apache-beam


    【解决方案1】:

    错误Cannot read and write in different locations 很容易解释,可能是因为:

    • BigQuery 数据集位于欧盟,您在美国运行 DataFlow
    • 您的 GCS 存储桶位于欧盟,您正在美国运行 DataFlow

    正如您在问题中指定的那样,您在欧盟的 GCS 中创建了临时位置,并且您的 BigQuery 数据集也位于欧盟,因此您也必须在欧盟运行 DataFlow 作业。

    为了实现这一点,你需要在PipelineOptions中指定zone参数,像这样:

    options = PipelineOptions()
    
    wo = options.view_as(WorkerOptions)  # type: WorkerOptions
    wo.zone = "europe-west1-b"
    
    
    # rest of your options:
    google_cloud_options = options.view_as(GoogleCloudOptions)
    google_cloud_options.project = 'm-h'
    google_cloud_options.job_name = 'myjob3'
    google_cloud_options.staging_location = r'gs://p_df/staging'  # EUROPE-WEST1
    google_cloud_options.region = r'europe-west1'
    google_cloud_options.temp_location = r'gs://p_df/temp'  # EUROPE-WEST1
    options.view_as(StandardOptions).runner = 'DataFlowRunner'
    
    p = beam.Pipeline(options=options)
    

    【讨论】:

    • 您好,非常感谢您的帖子。默认情况下,任务在 EU 上运行,当我作为 DataflowRunner 执行它时,我对它们没有任何问题。仅在我在 DirectRun 上执行时出现问题。很抱歉不要在我的问题上强调它。
    • 这很奇怪。您在欧盟吗?
    • 是的。不过看一下msg:we will create it as temporary with location=None我漏掉了一种参数temporary location=EU
    • 您能尝试在BigQuerySource 中明确指定datasetprojecttable 吗?
    • 嗨马尔辛。您可以在 Question 上看到所有代码。有没有办法为临时操作指定数据集?像 temp_location 但对于 bigquery?
    【解决方案2】:

    Python DirectRunner 中使用的 BigQuerySource 转换不会自动确定临时表的位置。有关问题,请参阅 BEAM-1909

    当使用 DataflowRunner 时,这应该可以工作。

    【讨论】:

    猜你喜欢
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多