Repository: googleapis/python-bigquery

Issue:
Passing destinationExpirationTime while creating table snapshot
Hi, 

Lib: google-cloud-bigquery==2.32.0

I am trying to create table snapshot but not finding any properties in CopyJob config where i can pass the destintionExpiration time.
I tried passing the expire at destination table but it didn't worked.






Discussion:
Any help?

Resolving patch:
diff --git a/google/cloud/bigquery/job/copy_.py b/google/cloud/bigquery/job/copy_.py
--- a/google/cloud/bigquery/job/copy_.py
+++ b/google/cloud/bigquery/job/copy_.py
@@ -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.


Test patch:
diff --git a/tests/system/test_client.py b/tests/system/test_client.py
--- a/tests/system/test_client.py
+++ b/tests/system/test_client.py
@@ -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,
diff --git a/tests/unit/job/test_copy.py b/tests/unit/job/test_copy.py
--- a/tests/unit/job/test_copy.py
+++ b/tests/unit/job/test_copy.py
@@ -19,6 +19,8 @@
 from .helpers import _Base
 from .helpers import _make_client
 
+import datetime
+
 
 class TestCopyJobConfig(_Base):
     JOB_TYPE = "copy"
@@ -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
 
@@ -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 (