import re
from google.cloud import bigquery
from google.cloud.bigquery.table import Table
MATCH_ALL = r'.*'
MATCH_NONE = r'^$'
client = bigquery.Client(project="your-project")
def list_table_id(dataset_id, include_pattern=MATCH_ALL, exclude_pattern=MATCH_NONE):
dataset_ref = client.dataset(dataset_id)
tables = list(client.list_tables(dataset_ref))
ret = []
for table in tables:
if re.search(include_pattern, table.table_id) and not re.search(exclude_pattern, table.table_id):
ret.append(table.table_id)
return ret
if __name__ == "__main__":
datasets = list(client.list_datasets())
for dataset in datasets:
dataset_id = dataset.dataset_id
try:
for table_id in list_table_id(dataset_id):
try:
dataset_ref = client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
table: Table = client.get_table(table_ref)
print(f"{dataset_id}\t{table_id}\t{table.num_bytes}")
except Exception as e:
print(f"{dataset_id}\t{table_id}\terror\t{e}")
except Exception as e:
print(f"{dataset_id}\terror\t{e}")
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme