Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions google/cloud/bigquery/job/copy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ def operation_type(self, value: Optional[str]):
value = OperationType.OPERATION_TYPE_UNSPECIFIED
self._set_sub_prop("operationType", value)

@property
def destination_expiration_time(self) -> str:
"""google.cloud.bigquery.job.DestinationExpirationTime: The time when the
destination table expires. Expired tables will be deleted and their storage reclaimed.

See
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.destination_expiration_time
"""
return self._get_sub_prop("destinationExpirationTime")

@destination_expiration_time.setter
def destination_expiration_time(self, value: str):
self._set_sub_prop("destinationExpirationTime", value)


class CopyJob(_AsyncJob):
"""Asynchronous job: copy data into a table from other tables.
Expand Down
5 changes: 5 additions & 0 deletions tests/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,11 @@ def test_table_snapshots(dataset_id):
copy_config = CopyJobConfig()
copy_config.operation_type = OperationType.SNAPSHOT

today = datetime.date.today()
destination_expiration_time = f"{today.year + 1}-01-01T00:00:00Z"

copy_config.destination_expiration_time = destination_expiration_time

copy_job = client.copy_table(
sources=source_table_path,
destination=snapshot_table_path,
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/job/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from .helpers import _Base
from .helpers import _make_client

import datetime


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

assert config.create_disposition is None
assert config.write_disposition is None
assert config.destination_expiration_time is None
assert config.destination_encryption_configuration is None
assert config.operation_type == OperationType.OPERATION_TYPE_UNSPECIFIED

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

today = datetime.date.today()
destination_expiration_time = f"{today.year + 1}-01-01T00:00:00Z"

config = self._get_target_class()(
create_disposition=create_disposition,
write_disposition=write_disposition,
operation_type=snapshot_operation,
destination_expiration_time=destination_expiration_time,
)

self.assertEqual(config.create_disposition, create_disposition)
self.assertEqual(config.write_disposition, write_disposition)
self.assertEqual(config.operation_type, snapshot_operation)
self.assertEqual(
config.destination_expiration_time, destination_expiration_time
)

def test_to_api_repr_with_encryption(self):
from google.cloud.bigquery.encryption_configuration import (
Expand Down