Skip to content

Commit 866c4a8

Browse files
authored
Add 'ExtractTableStorageJob.destination_uri_file_counts' property. (#3803)
1 parent e57b152 commit 866c4a8

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

bigquery/google/cloud/bigquery/job.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,22 @@ def __init__(self, name, source, destination_uris, client):
10261026
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.extract.printHeader
10271027
"""
10281028

1029+
@property
1030+
def destination_uri_file_counts(self):
1031+
"""Return file counts from job statistics, if present.
1032+
1033+
See:
1034+
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.extract.destinationUriFileCounts
1035+
1036+
:rtype: int or None
1037+
:returns: number of DML rows affectd by the job, or None if job is not
1038+
yet complete.
1039+
"""
1040+
result = self._job_statistics().get('destinationUriFileCounts')
1041+
if result is not None:
1042+
result = int(result)
1043+
return result
1044+
10291045
def _populate_config_resource(self, configuration):
10301046
"""Helper for _build_resource: copy config properties to resource"""
10311047
if self.compression is not None:

bigquery/tests/unit/test_job.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,23 @@ def test_ctor(self):
12341234
self.assertIsNone(job.field_delimiter)
12351235
self.assertIsNone(job.print_header)
12361236

1237+
def test_destination_uri_file_counts(self):
1238+
file_counts = 23
1239+
client = _Client(self.PROJECT)
1240+
source = _Table(self.SOURCE_TABLE)
1241+
job = self._make_one(self.JOB_NAME, source, [self.DESTINATION_URI],
1242+
client)
1243+
self.assertIsNone(job.destination_uri_file_counts)
1244+
1245+
statistics = job._properties['statistics'] = {}
1246+
self.assertIsNone(job.destination_uri_file_counts)
1247+
1248+
extract_stats = statistics['extract'] = {}
1249+
self.assertIsNone(job.destination_uri_file_counts)
1250+
1251+
extract_stats['destinationUriFileCounts'] = str(file_counts)
1252+
self.assertEqual(job.destination_uri_file_counts, file_counts)
1253+
12371254
def test_from_api_repr_missing_identity(self):
12381255
self._setUpConstants()
12391256
client = _Client(self.PROJECT)

0 commit comments

Comments
 (0)