使用bigquery table GET api获取表的最后修改日期

Swe*_*eta 3 python google-bigquery

我正在尝试使用bigquery REST API 获取表列表及其last_modified_date。
在 bigquery API 资源管理器中,我正确获取了所有字段,但是当我使用 Python 代码中的 api 时,它返回“无”修改日期。
这是用 python 编写的相同代码

from google.cloud import bigquery
client = bigquery.Client(project='temp')
datasets = list(client.list_datasets())

for dataset in datasets:
    print dataset.dataset_id

for dataset in datasets:
    for table in dataset.list_tables():
        print table.table_id
        print table.created
        print table.modified
Run Code Online (Sandbox Code Playgroud)

在此代码中,我正确获取了创建日期,但所有表的修改日期均为“无”。

Wil*_*uks 6

不太确定您使用的是哪个版本的 API,但我怀疑最新版本没有该方法dataset.list_tables()

尽管如此,这是获取最后修改字段的一种方法,看看这是否适合您(或者为您提供有关如何获取此数据的一些想法):

from google.cloud import bigquery
client = bigquery.Client.from_service_account_json('/key.json')

dataset_list = list(client.list_datasets())
for dataset_item in dataset_list:
    dataset = client.get_dataset(dataset_item.reference)
    tables_list = list(client.list_tables(dataset))

    for table_item in tables_list:
        table = client.get_table(table_item.reference)
        print "Table {} last modified: {}".format(
            table.table_id, table.modified)
Run Code Online (Sandbox Code Playgroud)