From fb8c802ae7e3401c4ba20ab908fab3c00c3305d8 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 23 Apr 2019 13:20:25 -0700 Subject: [PATCH] Refactor QueryJob.query to read from resource dictionary (#7763) This explicitly documents the QueryJob.query property and also aligns it with the other resource properties in the BigQuery client. --- bigquery/google/cloud/bigquery/job.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 90461513c0cc..d14119b1f1b1 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -2357,7 +2357,10 @@ def __init__(self, job_id, query, client, job_config=None): if job_config.use_legacy_sql is None: job_config.use_legacy_sql = False - self.query = query + _helpers._set_sub_prop( + self._properties, ["configuration", "query", "query"], query + ) + self._configuration = job_config self._query_results = None self._done_timeout = None @@ -2424,6 +2427,17 @@ def priority(self): """ return self._configuration.priority + @property + def query(self): + """str: The query text used in this query job. + + See: + https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query.query + """ + return _helpers._get_sub_prop( + self._properties, ["configuration", "query", "query"] + ) + @property def query_parameters(self): """See @@ -2516,7 +2530,6 @@ def to_api_repr(self): def _copy_configuration_properties(self, configuration): """Helper: assign subclass configuration properties in cleaned.""" self._configuration._properties = copy.deepcopy(configuration) - self.query = _helpers._get_sub_prop(configuration, ["query", "query"]) @classmethod def from_api_repr(cls, resource, client):