Skip to content

Commit 2ea7a6a

Browse files
tseavertswast
authored andcommitted
Add 'ExtractTableStorageJob.destination_uri_file_counts' property. (#3803)
1 parent c5f5f12 commit 2ea7a6a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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
@@ -1266,6 +1266,23 @@ def test_ctor(self):
12661266
self.assertIsNone(job.field_delimiter)
12671267
self.assertIsNone(job.print_header)
12681268

1269+
def test_destination_uri_file_counts(self):
1270+
file_counts = 23
1271+
client = _Client(self.PROJECT)
1272+
source = _Table(self.SOURCE_TABLE)
1273+
job = self._make_one(self.JOB_NAME, source, [self.DESTINATION_URI],
1274+
client)
1275+
self.assertIsNone(job.destination_uri_file_counts)
1276+
1277+
statistics = job._properties['statistics'] = {}
1278+
self.assertIsNone(job.destination_uri_file_counts)
1279+
1280+
extract_stats = statistics['extract'] = {}
1281+
self.assertIsNone(job.destination_uri_file_counts)
1282+
1283+
extract_stats['destinationUriFileCounts'] = str(file_counts)
1284+
self.assertEqual(job.destination_uri_file_counts, file_counts)
1285+
12691286
def test_from_api_repr_missing_identity(self):
12701287
self._setUpConstants()
12711288
client = _Client(self.PROJECT)

0 commit comments

Comments
 (0)