Ejemplo n.º 1
0
    def _job_from_resource(self, resource):
        """Detect correct job type from resource and instantiate.

        Helper for :meth:`list_jobs`.

        :type resource: dict
        :param resource: one job resource from API response

        :rtype; One of:
                :class:`gcloud.bigquery.job.LoadTableFromStorageJob`,
                :class:`gcloud.bigquery.job.CopyJob,
                :class:`gcloud.bigquery.job.ExtractTableToStorageJob,
                :class:`gcloud.bigquery.job.QueryJob,
                :class:`gcloud.bigquery.job.RunSyncQueryJob
        :returns: the job instance, constructed via the resource
        """
        config = resource['configuration']
        if 'load' in config:
            return LoadTableFromStorageJob.from_api_repr(resource, self)
        elif 'copy' in config:
            return CopyJob.from_api_repr(resource, self)
        elif 'extract' in config:
            return ExtractTableToStorageJob.from_api_repr(resource, self)
        elif 'query' in config:
            return QueryJob.from_api_repr(resource, self)
        raise ValueError('Cannot parse job resource')
Ejemplo n.º 2
0
    def _job_from_resource(self, resource):
        """Detect correct job type from resource and instantiate.

        Helper for :meth:`list_jobs`.

        :type resource: dict
        :param resource: one job resource from API response

        :rtype; One of:
                :class:`gcloud.bigquery.job.LoadTableFromStorageJob`,
                :class:`gcloud.bigquery.job.CopyJob,
                :class:`gcloud.bigquery.job.ExtractTableToStorageJob,
                :class:`gcloud.bigquery.job.QueryJob,
                :class:`gcloud.bigquery.job.RunSyncQueryJob
        :returns: the job instance, constructed via the resource
        """
        config = resource['configuration']
        if 'load' in config:
            return LoadTableFromStorageJob.from_api_repr(resource, self)
        elif 'copy' in config:
            return CopyJob.from_api_repr(resource, self)
        elif 'extract' in config:
            return ExtractTableToStorageJob.from_api_repr(resource, self)
        elif 'query' in config:
            return QueryJob.from_api_repr(resource, self)
        raise ValueError('Cannot parse job resource')
Ejemplo n.º 3
0
    def job(self):
        """Job instance used to run the query.

        :rtype: :class:`gcloud.bigquery.job.QueryJob`, or ``NoneType``
        :returns: Job instance used to run the query (None until
                  ``jobReference`` property is set by the server).
        """
        job_ref = self._properties.get('jobReference')
        if job_ref is not None:
            return QueryJob(job_ref['jobId'], self.query, self._client)
Ejemplo n.º 4
0
    def run_async_query(self, job_name, query):
        """Construct a job for running a SQL query asynchronously.

        See:
        https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query

        :type job_name: str
        :param job_name: Name of the job.

        :type query: str
        :param query: SQL query to be executed

        :rtype: :class:`gcloud.bigquery.job.QueryJob`
        :returns: a new ``QueryJob`` instance
        """
        return QueryJob(job_name, query, client=self)