示例#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')
示例#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')
示例#3
0
    def load_table_from_storage(self, name, destination, *source_uris):
        """Construct a job for loading data into a table from CloudStorage.

        :type name: string
        :param name: Name of the job.

        :type destination: :class:`gcloud.bigquery.table.Table`
        :param destination: Table into which data is to be loaded.

        :type source_uris: sequence of string
        :param source_uris: URIs of data files to be loaded.

        :rtype: :class:`gcloud.bigquery.job.LoadTableFromStorageJob`
        :returns: a new ``LoadTableFromStorageJob`` instance
        """
        return LoadTableFromStorageJob(name,
                                       destination,
                                       source_uris,
                                       client=self)
示例#4
0
    def load_table_from_storage(self, job_name, destination, *source_uris):
        """Construct a job for loading data into a table from CloudStorage.

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

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

        :type destination: :class:`gcloud.bigquery.table.Table`
        :param destination: Table into which data is to be loaded.

        :type source_uris: sequence of string
        :param source_uris: URIs of data files to be loaded; in format
                            ``gs://<bucket_name>/<object_name_or_glob>``.

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