简体   繁体   English

使用python从bigquery调用外部表

[英]Calling external table from bigquery with python

While I trying to reach the external table's data, I'm getting error like as below.当我尝试访问外部表的数据时,出现如下错误。 I can not solve this issue.我无法解决这个问题。 Here are the details about the situation;以下是有关情况的详细信息;

google.api_core.exceptions.NotFound: 404 Not found: Files /gdrive/id/id123456id google.api_core.exceptions.NotFound: 404 Not found: Files /gdrive/id/id123456id

PS: id123456id is a dummy id. PS:id123456id 是一个虚拟 ID。

The file with ID id123456 id exists in my Google Drive. ID 为 id123456 id 的文件存在于我的 Google 云端硬盘中。 Bigquery table looking this id.查找此 ID 的 Bigquery 表。

bq_test.json -> service account credential's JSON file. bq_test.json -> 服务帐户凭据的 JSON 文件。 This service account has those roles;此服务帐户具有这些角色;

  • BigQuery Data Editor BigQuery 数据编辑器
  • BigQuery Data Owner BigQuery 数据所有者
  • BigQuery Data Viewer BigQuery 数据查看器
  • BigQuery User BigQuery 用户
  • Owner所有者

Here is my code block:这是我的代码块:

from google.cloud import bigquery
from google.oauth2.service_account import Credentials

scopes = (
        'https://www.googleapis.com/auth/bigquery',
        'https://www.googleapis.com/auth/cloud-platform',
        'https://www.googleapis.com/auth/drive'
)
credentials = Credentials.from_service_account_file('bq_test.json')
credentials = credentials.with_scopes(scopes)
client = bigquery.Client(credentials=credentials)

QUERY = (
        """SELECT * FROM
            `project_name.dataset_name.ext_table`
            LIMIT 5"""
        )
query_job = client.query(QUERY)
rows = query_job.result()

for row in rows:
    print(row.name)

I solved the problem as follows;我解决了以下问题;

This flow provides the solution in my case.这个流程为我提供了解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM