Skip to content

Commit 728b07c

Browse files
steffnayparthea
andauthored
feat: add destination_expiration_time property to copy job (#1277)
* feat: add destination_expiration_time property to copy job * update test * refactor test * remove unused import * Update google/cloud/bigquery/job/copy_.py Co-authored-by: Anthonios Partheniou <[email protected]> * Update google/cloud/bigquery/job/copy_.py Co-authored-by: Anthonios Partheniou <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 51c1f37 commit 728b07c

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

google/cloud/bigquery/job/copy_.py

+14
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ def operation_type(self, value: Optional[str]):
126126
value = OperationType.OPERATION_TYPE_UNSPECIFIED
127127
self._set_sub_prop("operationType", value)
128128

129+
@property
130+
def destination_expiration_time(self) -> str:
131+
"""google.cloud.bigquery.job.DestinationExpirationTime: The time when the
132+
destination table expires. Expired tables will be deleted and their storage reclaimed.
133+
134+
See
135+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.destination_expiration_time
136+
"""
137+
return self._get_sub_prop("destinationExpirationTime")
138+
139+
@destination_expiration_time.setter
140+
def destination_expiration_time(self, value: str):
141+
self._set_sub_prop("destinationExpirationTime", value)
142+
129143

130144
class CopyJob(_AsyncJob):
131145
"""Asynchronous job: copy data into a table from other tables.

tests/system/test_client.py

+5
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,11 @@ def test_table_snapshots(dataset_id):
21532153
copy_config = CopyJobConfig()
21542154
copy_config.operation_type = OperationType.SNAPSHOT
21552155

2156+
today = datetime.date.today()
2157+
destination_expiration_time = f"{today.year + 1}-01-01T00:00:00Z"
2158+
2159+
copy_config.destination_expiration_time = destination_expiration_time
2160+
21562161
copy_job = client.copy_table(
21572162
sources=source_table_path,
21582163
destination=snapshot_table_path,

tests/unit/job/test_copy.py

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from .helpers import _Base
2020
from .helpers import _make_client
2121

22+
import datetime
23+
2224

2325
class TestCopyJobConfig(_Base):
2426
JOB_TYPE = "copy"
@@ -36,6 +38,7 @@ def test_ctor_defaults(self):
3638

3739
assert config.create_disposition is None
3840
assert config.write_disposition is None
41+
assert config.destination_expiration_time is None
3942
assert config.destination_encryption_configuration is None
4043
assert config.operation_type == OperationType.OPERATION_TYPE_UNSPECIFIED
4144

@@ -48,15 +51,22 @@ def test_ctor_w_properties(self):
4851
write_disposition = WriteDisposition.WRITE_TRUNCATE
4952
snapshot_operation = OperationType.SNAPSHOT
5053

54+
today = datetime.date.today()
55+
destination_expiration_time = f"{today.year + 1}-01-01T00:00:00Z"
56+
5157
config = self._get_target_class()(
5258
create_disposition=create_disposition,
5359
write_disposition=write_disposition,
5460
operation_type=snapshot_operation,
61+
destination_expiration_time=destination_expiration_time,
5562
)
5663

5764
self.assertEqual(config.create_disposition, create_disposition)
5865
self.assertEqual(config.write_disposition, write_disposition)
5966
self.assertEqual(config.operation_type, snapshot_operation)
67+
self.assertEqual(
68+
config.destination_expiration_time, destination_expiration_time
69+
)
6070

6171
def test_to_api_repr_with_encryption(self):
6272
from google.cloud.bigquery.encryption_configuration import (

0 commit comments

Comments
 (0)