def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespeace, All the arguments that were provided to this command invocation. Yields: TableList.TablesValueListEntry messages. """ apitools_client = self.context[commands.APITOOLS_CLIENT_KEY] bigquery_messages = self.context[commands.BIGQUERY_MESSAGES_MODULE_KEY] resource_parser = self.context[commands.BIGQUERY_REGISTRY_KEY] resource = resource_parser.Parse(args.dataset_name, collection='bigquery.datasets') reference = message_conversions.DatasetResourceToReference( bigquery_messages, resource) request = bigquery_messages.BigqueryTablesListRequest( projectId=reference.projectId, datasetId=reference.datasetId) try: for resource in list_pager.YieldFromList( apitools_client.tables, request, batch_size=None, # Use server default. field='tables'): yield resource except exceptions.HttpError as server_error: raise bigquery.Error.ForHttpError(server_error)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespeace, All the arguments that were provided to this command invocation. Returns: None """ apitools_client = self.context[commands.APITOOLS_CLIENT_KEY] bigquery_messages = self.context[commands.BIGQUERY_MESSAGES_MODULE_KEY] resource_parser = self.context[commands.BIGQUERY_REGISTRY_KEY] resource = resource_parser.Parse(args.dataset_name, collection='bigquery.datasets') reference = message_conversions.DatasetResourceToReference( bigquery_messages, resource) request = bigquery_messages.BigqueryDatasetsPatchRequest( dataset=bigquery_messages.Dataset( datasetReference=bigquery_messages.DatasetReference( projectId=reference.projectId, datasetId=reference.datasetId), description=args.description), projectId=reference.projectId, datasetId=reference.datasetId) apitools_client.datasets.Patch(request) log.UpdatedResource(resource)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace, All the arguments that were provided to this command invocation. Raises: ToolException: when user cancels dataset removal. Returns: Some value that we want to have printed later. """ apitools_client = self.context[commands.APITOOLS_CLIENT_KEY] bigquery_messages = self.context[commands.BIGQUERY_MESSAGES_MODULE_KEY] resource_parser = self.context[commands.BIGQUERY_REGISTRY_KEY] resource = resource_parser.Parse(args.dataset_name, collection='bigquery.datasets') reference = message_conversions.DatasetResourceToReference( bigquery_messages, resource) if not args.quiet: dataset_exists = bigquery_client_helper.DatasetExists( apitools_client, bigquery_messages, reference) if dataset_exists: removal_confirmed = console_io.PromptContinue( message='About to remove dataset {0}.'.format(resource)) if not removal_confirmed: raise exceptions.ToolException('canceled by user') request = bigquery_messages.BigqueryDatasetsDeleteRequest( projectId=reference.projectId, datasetId=reference.datasetId, deleteContents=args.remove_tables) try: apitools_client.datasets.Delete(request) log.DeletedResource(resource) except apitools_exceptions.HttpError as server_error: try: raise bigquery.Error.ForHttpError(server_error) except bigquery.NotFoundError: if args.ignore_not_found: log.status.Print( 'Dataset {0} did not exist.'.format(resource)) else: raise
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace, All the arguments that were provided to this command invocation. Returns: Some value that we want to have printed later. Raises: bigquery.DuplicateError: dataset exists """ apitools_client = self.context[commands.APITOOLS_CLIENT_KEY] bigquery_messages = self.context[commands.BIGQUERY_MESSAGES_MODULE_KEY] resource_parser = self.context[commands.BIGQUERY_REGISTRY_KEY] project_id = properties.VALUES.core.project.Get(required=True) resource = resource_parser.Parse( args.dataset_name, collection='bigquery.datasets') reference = message_conversions.DatasetResourceToReference( bigquery_messages, resource) if bigquery_client_helper.DatasetExists( apitools_client, bigquery_messages, reference): message = 'Dataset {0} already exists.'.format(resource) if args.if_exists == 'skip': log.status.write(message + '\n') return else: raise bigquery.DuplicateError(message, None, None) request = bigquery_messages.BigqueryDatasetsInsertRequest( dataset=bigquery_messages.Dataset( datasetReference=reference, description=args.description), projectId=project_id) try: apitools_client.datasets.Insert(request) except bigquery.DuplicateError: if args.if_exists == 'skip': raise log.CreatedResource(resource)