diff --git a/samples/geography/requirements.txt b/samples/geography/requirements.txt index 96819343c..7e017e283 100644 --- a/samples/geography/requirements.txt +++ b/samples/geography/requirements.txt @@ -1,4 +1,4 @@ geojson==2.5.0 -google-cloud-bigquery==2.13.1 +google-cloud-bigquery==2.14.0 google-cloud-bigquery-storage==2.1.0 Shapely==1.7.1 diff --git a/samples/snippets/conftest.py b/samples/snippets/conftest.py index 31c6ba104..0d0299ee5 100644 --- a/samples/snippets/conftest.py +++ b/samples/snippets/conftest.py @@ -20,21 +20,29 @@ RESOURCE_PREFIX = "python_bigquery_samples_snippets" +RESOURCE_DATE_FORMAT = "%Y%m%d_%H%M%S" +RESOURCE_DATE_LENGTH = 4 + 2 + 2 + 1 + 2 + 2 + 2 def resource_prefix() -> str: - timestamp = datetime.datetime.utcnow().strftime("%Y%m%d_%H%M%S") + timestamp = datetime.datetime.utcnow().strftime(RESOURCE_DATE_FORMAT) random_string = hex(random.randrange(1000000))[2:] return f"{RESOURCE_PREFIX}_{timestamp}_{random_string}" +def resource_name_to_date(resource_name: str): + start_date = len(RESOURCE_PREFIX) + 1 + date_string = resource_name[start_date : start_date + RESOURCE_DATE_LENGTH] + return datetime.strptime(date_string, RESOURCE_DATE_FORMAT) + + @pytest.fixture(scope="session", autouse=True) def cleanup_datasets(bigquery_client: bigquery.Client): yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1) for dataset in bigquery_client.list_datasets(): if ( dataset.dataset_id.startswith(RESOURCE_PREFIX) - and dataset.created < yesterday + and resource_name_to_date(dataset.dataset_id) < yesterday ): bigquery_client.delete_dataset( dataset, delete_contents=True, not_found_ok=True diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 74a18981e..d7e60f77d 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,4 +1,4 @@ -google-cloud-bigquery==2.13.1 +google-cloud-bigquery==2.14.0 google-cloud-bigquery-storage==2.3.0 google-auth-oauthlib==0.4.4 grpcio==1.37.0