def from_api_repr(cls, resource, client): """Factory: construct a job given its API representation .. note: This method assumes that the project found in the resource matches the client's project. :type resource: dict :param resource: dataset job representation returned from the API :type client: :class:`gcloud.bigquery.client.Client` :param client: Client which holds credentials and project configuration for the dataset. :rtype: :class:`gcloud.bigquery.job.CopyJob` :returns: Job parsed from ``resource``. """ name, config = cls._get_resource_config(resource) dest_config = config['destinationTable'] dataset = Dataset(dest_config['datasetId'], client) destination = Table(dest_config['tableId'], dataset) sources = [] for source_config in config['sourceTables']: dataset = Dataset(source_config['datasetId'], client) sources.append(Table(source_config['tableId'], dataset)) job = cls(name, destination, sources, client=client) job._set_properties(resource) return job
def dataset(self, dataset_name): """Construct a dataset bound to this client. :type dataset_name: str :param dataset_name: Name of the dataset. :rtype: :class:`gcloud.bigquery.dataset.Dataset` :returns: a new ``Dataset`` instance """ return Dataset(dataset_name, client=self)
def list_datasets(self, include_all=False, max_results=None, page_token=None): """List datasets for the project associated with this client. See: https://cloud.google.com/bigquery/docs/reference/v2/datasets/list :type include_all: boolean :param include_all: True if results include hidden datasets. :type max_results: int :param max_results: maximum number of datasets to return, If not passed, defaults to a value set by the API. :type page_token: str :param page_token: opaque marker for the next "page" of datasets. If not passed, the API will return the first page of datasets. :rtype: tuple, (list, str) :returns: list of :class:`gcloud.bigquery.dataset.Dataset`, plus a "next page token" string: if the token is not None, indicates that more datasets can be retrieved with another call (pass that value as ``page_token``). """ params = {} if include_all: params['all'] = True if max_results is not None: params['maxResults'] = max_results if page_token is not None: params['pageToken'] = page_token path = '/projects/%s/datasets' % (self.project, ) resp = self.connection.api_request(method='GET', path=path, query_params=params) datasets = [ Dataset.from_api_repr(resource, self) for resource in resp.get('datasets', ()) ] return datasets, resp.get('nextPageToken')
def list_datasets(self, include_all=False, max_results=None, page_token=None): """List datasets for the project associated with this client. See: https://cloud.google.com/bigquery/docs/reference/v2/datasets/list :type include_all: boolean :param include_all: True if results include hidden datasets. :type max_results: int :param max_results: maximum number of datasets to return, If not passed, defaults to a value set by the API. :type page_token: str :param page_token: opaque marker for the next "page" of datasets. If not passed, the API will return the first page of datasets. :rtype: tuple, (list, str) :returns: list of :class:`gcloud.bigquery.dataset.Dataset`, plus a "next page token" string: if the token is not None, indicates that more datasets can be retrieved with another call (pass that value as ``page_token``). """ params = {} if include_all: params['all'] = True if max_results is not None: params['maxResults'] = max_results if page_token is not None: params['pageToken'] = page_token path = '/projects/%s/datasets' % (self.project,) resp = self.connection.api_request(method='GET', path=path, query_params=params) datasets = [Dataset.from_api_repr(resource, self) for resource in resp.get('datasets', ())] return datasets, resp.get('nextPageToken')
def dataset(self, name): from gcloud.bigquery.dataset import Dataset return Dataset(name, client=self)