Skip to content

Commit af2be4c

Browse files
Gaurang033Gaurang Shah
authored and
Gaurang Shah
committed
feat: add support dataset.max_time_travel_hours
1 parent 5ceed05 commit af2be4c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

google/cloud/bigquery/dataset.py

+20
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,33 @@ class Dataset(object):
527527
"friendly_name": "friendlyName",
528528
"default_encryption_configuration": "defaultEncryptionConfiguration",
529529
"storage_billing_model": "storageBillingModel",
530+
"max_time_travel_hours": "maxTimeTravelHours",
530531
}
531532

532533
def __init__(self, dataset_ref) -> None:
533534
if isinstance(dataset_ref, str):
534535
dataset_ref = DatasetReference.from_string(dataset_ref)
535536
self._properties = {"datasetReference": dataset_ref.to_api_repr(), "labels": {}}
536537

538+
@property
539+
def max_time_travel_hours(self):
540+
"""
541+
Optional[int]: Defines the time travel window in hours. The value can be from 48 to 168 hours (2 to 7 days).
542+
The default value is 168 hours if this is not set.
543+
"""
544+
return self._properties.get("maxTimeTravelHours")
545+
546+
@max_time_travel_hours.setter
547+
def max_time_travel_hours(self, hours):
548+
if not isinstance(hours, int):
549+
raise ValueError("Pass the int value")
550+
if hours < 2 * 24 or hours > 7 * 24:
551+
raise ValueError(
552+
"Time Travel Window should be from 48 to 168 hours (2 to 7 days)"
553+
)
554+
555+
self._properties["maxTimeTravelHours"] = hours
556+
537557
@property
538558
def project(self):
539559
"""str: Project ID of the project bound to the dataset."""

tests/system/test_client.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ def test_create_dataset(self):
238238
self.assertEqual(dataset.dataset_id, DATASET_ID)
239239
self.assertEqual(dataset.project, Config.CLIENT.project)
240240

241+
def test_create_dataset_max_time_travel_hours(self):
242+
DATASET_ID = _make_dataset_id("create_ci_dataset")
243+
dataset = self.temp_dataset(DATASET_ID, max_time_travel_hours=24 * 2)
244+
self.assertEqual(int(dataset.max_time_travel_hours), 24 * 2)
245+
241246
def test_get_dataset(self):
242247
dataset_id = _make_dataset_id("get_dataset")
243248
client = Config.CLIENT
@@ -2286,12 +2291,14 @@ def test_nested_table_to_arrow(self):
22862291
self.assertTrue(pyarrow.types.is_list(record_col[1].type))
22872292
self.assertTrue(pyarrow.types.is_int64(record_col[1].type.value_type))
22882293

2289-
def temp_dataset(self, dataset_id, location=None):
2294+
def temp_dataset(self, dataset_id, *args, **kwargs):
22902295
project = Config.CLIENT.project
22912296
dataset_ref = bigquery.DatasetReference(project, dataset_id)
22922297
dataset = Dataset(dataset_ref)
2293-
if location:
2294-
dataset.location = location
2298+
if kwargs.get("location"):
2299+
dataset.location = kwargs.get("location")
2300+
if kwargs.get("max_time_travel_hours"):
2301+
dataset.max_time_travel_hours = kwargs.get("max_time_travel_hours")
22952302
dataset = helpers.retry_403(Config.CLIENT.create_dataset)(dataset)
22962303
self.to_delete.append(dataset)
22972304
return dataset

0 commit comments

Comments
 (0)