Joh*_*ohn 3 python google-bigquery google-cloud-platform
如何查询 BigQuery 数据集并获取数据集中所有表的列表?据我所知,我只能使用 BigQuery API,但尽管传递了 API 密钥,但我无法进行身份验证。
url = f"https://bigquery.googleapis.com/bigquery/v2/projects/{params['project_id']}/datasets/{params['dataset_id']}/tables?key={params['api_key']}"
response = requests.get(url)
data = response.json()
pprint.pprint(data)
Run Code Online (Sandbox Code Playgroud)
Joh*_*ohn 11
正如米哈伊尔所说,它在文档中进行了解释。这是答案:
from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# TODO(developer): Set dataset_id to the ID of the dataset that contains
# the tables you are listing.
# dataset_id = 'your-project.your_dataset'
tables = client.list_tables(dataset_id)
print("Tables contained in '{}':".format(dataset_id))
for table in tables:
print("{}.{}.{}".format(table.project, table.dataset_id, table.table_id))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5160 次 |
| 最近记录: |