Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,21 @@ def num_dml_affected_rows(self):
query_stats = self._query_statistics()
return query_stats.get('numDmlAffectedRows')

@property
def undeclared_query_paramters(self):
"""Return undeclared query parameters from job statistics, if present.

See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.undeclaredQueryParamters

:rtype: list of dict

This comment was marked as spam.

:returns: mappings describing the undeclared parameters, or an empty
list if the query has not yet completed.
"""
query_stats = self._query_statistics()
undeclared = query_stats.get('undeclaredQueryParamters', ())
return [copy.deepcopy(parameter) for parameter in undeclared]

def query_results(self):
"""Construct a QueryResults instance, bound to this job.

Expand Down
35 changes: 35 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,41 @@ def test_num_dml_affected_rows(self):
query_stats['numDmlAffectedRows'] = num_rows
self.assertEqual(job.num_dml_affected_rows, num_rows)

def test_undeclared_query_paramters(self):
undeclared = [{
"name": 'my_scalar',
"parameterType": {
"type": 'STRING',
},
}, {
"name": 'my_array',
"parameterType": {
"type": 'ARRAY',
"arrayType": 'INT64',
},
}, {
"name": 'my_struct',
"parameterType": {
"type": 'STRUCT',
"structTypes": [{
"name": 'count',
"type": 'INT64',
}],
},
}]
client = _Client(self.PROJECT)
job = self._make_one(self.JOB_NAME, self.QUERY, client)
self.assertEqual(job.undeclared_query_paramters, [])

statistics = job._properties['statistics'] = {}
self.assertEqual(job.undeclared_query_paramters, [])

query_stats = statistics['query'] = {}
self.assertEqual(job.undeclared_query_paramters, [])

query_stats['undeclaredQueryParamters'] = undeclared
self.assertEqual(job.undeclared_query_paramters, undeclared)

def test_query_results(self):
from google.cloud.bigquery.query import QueryResults

Expand Down