feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The command group for Google BigQuery Tables."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Tables(base.Group):
"""Interact with and manage Google BigQuery tables."""

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group for managing Google BigQuery table configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Google BigQuery table configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Google BigQuery table.
description: |
*{command}* exports the configuration for a Google BigQuery table.
Table configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
tables within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a table, run:
$ {command} my-table
To export the configuration for a table to a file, run:
$ {command} my-table --path=/path/to/dir/
To export the configuration for a table in Terraform
HCL format, run:
$ {command} my-table --resource-format=terraform
To export the configurations for all tables within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Table to export the configuration for.
spec: !REF googlecloudsdk.command_lib.bq.resources:table

View File

@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""BQ copy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bq import util as api_util
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bq import command_utils
from googlecloudsdk.command_lib.bq import hooks
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Copy(base.Command):
"""Bq Copy Command."""
detailed_help = {
'brief': 'Copy one BigQuery table to another.',
'DESCRIPTION': """\
*{command}* Copies one BigQuery table to another.
""",
'EXAMPLES': """\
The following copies table `my-table` to table `my-other-table`, in dataset `my-dataset`
overwriting destination if it exists:
$ {command} --source my-table --destination my-other-table --source-dataset my-dataset --overwrite
""",
}
@staticmethod
def Args(parser):
base.ASYNC_FLAG.AddToParser(parser)
base.Argument(
'--overwrite',
action='store_true',
default=False,
required=False,
help='Overwrite if the resource already exists.').AddToParser(parser)
base.Argument(
'--job-id',
required=False,
default='',
help='A unique job ID to use for the request. '
'If not specified a unique job id will '
'be generated.').AddToParser(parser)
concept_parser = command_utils.GetTableCopyResourceArgs()[0]
concept_parser.AddToParser(parser)
def Run(self, args):
job_id = hooks.JobIdProcessor(args.job_id)
requests_type = api_util.GetApiMessage('BigqueryJobsInsertRequest')
request = requests_type()
project = args.project or properties.VALUES.core.project.Get(required=True)
request.projectId = project
request = command_utils.ProcessTableCopyConfiguration(None, args, request)
request = command_utils.ProcessTableCopyOverwrite(None, args, request)
arg_utils.SetFieldInMessage(request, 'job.jobReference.jobId', job_id)
arg_utils.SetFieldInMessage(request, 'job.jobReference.projectId', project)
client = api_util.GetApiClient()
job_service = client.jobs
job = client.jobs.Insert(request)
source_ref = args.CONCEPTS.source.Parse()
destination_ref = args.CONCEPTS.destination.Parse()
copy_message = 'Copying {0}:{1} to {2}:{3}.'.format(
source_ref.Parent().Name(), source_ref.Name(),
destination_ref.Parent().Name(), destination_ref.Name())
if not args.async_:
log.CreatedResource(job.id, kind='Job', details=copy_message)
return job
result_service = client.tables
poller = command_utils.BqJobPoller(job_service, result_service)
job_ref = resources.REGISTRY.Parse(job.jobReference.jobId,
params={'projectId': project},
collection='bigquery.jobs')
result = waiter.WaitFor(poller=poller, operation_ref=job_ref,
message=copy_message)
log.status.Print('Copied {0}:{1} to {2}:{3}.'.format(
source_ref.Parent().Name(), source_ref.Name(),
destination_ref.Parent().Name(), destination_ref.Name()))
return result

View File

@@ -0,0 +1,120 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Create a new BigQuery table.
description: |-
Create a new BigQuery table.
Create a table or view with a specified name. A view is a collection of rows
selected by a query in a flag, and manipulated as a table. The dataset to contain
the table or view must already exist, and must not contain a table or view with
the specified name.
examples: |
The following command creates a table with ID `my-table` in `my-dataset`:
$ {command} /projects/myproject/datasets/my-dataset/tables/my-table --description 'My New Table'
The following command creates a view with ID `my-view` in dataset `my-other-dataset`:
$ {command} my-view --dataset my-other-dataset \
--view 'SELECT field1, field3 FROM `my-project.my-other-dataset.my-table`'
request:
collection: bigquery.tables
method: insert
modify_request_hooks:
- googlecloudsdk.command_lib.bq.hooks:ProcessTableOverwrite
- googlecloudsdk.command_lib.bq.hooks:SetViewParameters
- googlecloudsdk.command_lib.util.hooks.request_modifiers:SetFieldFromName:api_field=table.tableReference.tableId
arguments:
resource:
help_text: The BigQuery table you want to create.
spec: !REF googlecloudsdk.command_lib.bq.resources:table
params:
- _REF_: googlecloudsdk.command_lib.bq.flags:overwrite
- _REF_: googlecloudsdk.command_lib.bq.flags:table.description
- _REF_: googlecloudsdk.command_lib.bq.flags:table.expiration
- group:
mutex: true
required: false
help_text: Specify the table schema.
params:
- arg_name: schema
metavar: FIELD_NAME=FIELD_TYPE
api_field: table.schema.fields
type:
arg_dict:
flatten: true
spec:
- api_field: name
- api_field: type
help_text: |-
A comma-separated list of entries of the form FIELD_NAME[=FIELD_TYPE] specifying field names
and types for the table being created. FIELD_TYPE defaults to string if not present.
Possible FIELD_TYPES are `string`, `integer`, `float`, `boolean`, `record`, and `timestamp`.
For more details on BigQuery schemas see: https://cloud.google.com/bigquery/docs/schemas.
- arg_name: schema-file
api_field: table.schema
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
processor: googlecloudsdk.command_lib.bq.hooks:BqTableSchemaFileProcessor
help_text: |-
The name of a JSON file containing a single object containing an array each element
of which is an object with properties name, type, and, optionally a
mode (one of: `NULLABLE`, `REQUIRED` or `REPEATED`), specifying a schema for the table
being created. If mode is omitted the default is 'NULLABLE'.
For example:
{
'schema':
[
{
'name': 'field1',
'type': 'string',
'mode': 'REQUIRED'
},
{
'name': 'field2',
'type': 'integer',
'mode': 'REPEATED'
},
[
{
'name': 'fieldN',
'type': TYPE,
['mode': MODE]
}
...
]
]
}
For more details on BigQuery schemas see: https://cloud.google.com/bigquery/docs/schemas.
- group:
help_text: Create a view instead of regular table.
required: false
params:
- api_field: table.view.query
arg_name: view
required: true
help_text: |-
Create a view with this SQL query. (If this flag is not specified, a table is created.)
- api_field: table.view.useLegacySql
arg_name: use-legacy-sql
action: store_true
help_text: |-
If specified, query will use BigQuery's legacy SQL syntax. If not specified, query will use
BigQuery's standard SQL dialect by default (https://cloud.google.com/bigquery/sql-reference/).

View File

@@ -0,0 +1,29 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Delete a BigQuery table.
description: Delete a BigQuery table.
examples: |
The following command deletes a table with ID `my-table`
$ {command} my-table
request:
collection: bigquery.tables
arguments:
resource:
help_text: The BigQuery table you want to delete.
spec: !REF googlecloudsdk.command_lib.bq.resources:table

View File

@@ -0,0 +1,29 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Describe a BigQuery table.
description: Describe a BigQuery table.
examples: |
The following command fetches details about a table with ID `my-table`
$ {command} my-table
request:
collection: bigquery.tables
arguments:
resource:
help_text: The BigQuery table you want to describe.
spec: !REF googlecloudsdk.command_lib.bq.resources:table

View File

@@ -0,0 +1,50 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Insert records specified into an existing table.
description: |-
Insert records specified into an existing table.
examples: |
The following command inserts rows from `data_file.json` into `my-table` in `my-dataset`:
$ {command} --table /projects/myproject/datasets/my-dataset/tables/my-table --data data_file.json
request:
collection: bigquery.tabledata
method: insertAll
arguments:
resource:
help_text: The BigQuery table you want to insert data into.
override_resource_collection: true
spec: !REF googlecloudsdk.command_lib.bq.resources:table
params:
- arg_name: data
api_field: tableDataInsertAllRequest.rows
required: true
repeated: false
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
processor: googlecloudsdk.command_lib.bq.hooks:BqTableDataFileProcessor
help_text: |-
The file containing the newline-delimited array of JSON objects representing rows to insert.
* For example:
[
{"string_col": "value1", "bool_col": false},
{"string_col": "value2", "bool_col": true},
{"string_col": "value3", "bool_col": false},
{"string_col": "value4", "bool_col": true},
{"string_col": "value5", "bool_col": false},
]

View File

@@ -0,0 +1,39 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: List all BigQuery tables and views in a dataset.
description: List all BigQuery tables and views in a dataset.
examples: |
The following command list all tables the specified dataset
$ {command} --dataset my-dataset
request:
collection: bigquery.tables
arguments:
resource:
help_text: The BigQuery dataset you want to list datasets for.
spec: !REF googlecloudsdk.command_lib.bq.resources:dataset
output:
format: |
table(
tableReference.datasetId,
tableReference.tableId,
creationTime.date(unit=1000, tz_default=UTC),
expirationTime.date(unit=1000, tz_default=UTC),
type
)

View File

@@ -0,0 +1,43 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Display selected rows in a specified table or view.
description: |-
Display selected rows in a specified table or view.
examples: |
The following command displays 150 rows of `my-table` in `my-dataset` starting from row 10:
$ {command} --table /projects/myproject/datasets/my-dataset/tables/my-table --limit 150 --start 10
request:
collection: bigquery.tabledata
method: list
arguments:
resource:
help_text: The BigQuery table you want to fetch rows from.
override_resource_collection: true
spec: !REF googlecloudsdk.command_lib.bq.resources:table
params:
- arg_name: limit
api_field: maxResults
required: false
default: 100
help_text: How many rows to return in the result.
- arg_name: start
api_field: startIndex
required: false
default: 0
help_text: First row to return in the result.

View File

@@ -0,0 +1,110 @@
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- release_tracks: [ALPHA]
help_text:
brief: Update a new BigQuery table.
description: |-
Create a new BigQuery table.
Updates one or more attributes of a table or view.
examples: |
The following command updates the description on a table with ID `my-table` in `my-dataset`:
$ {command} /projects/myproject/datasets/my-dataset/tables/my-table --description 'My New Table'
The following command changes the schema mode from `REQUIRED` to `NULLABLE` on the `value`
and `tags` columns in a table with ID `my-other-table` in dataset `my-other-dataset`:
$ {command} my-other-table --dataset my-other-dataset \
--relax-columns name,tags
request:
collection: bigquery.tables
method: patch
modify_request_hooks:
- googlecloudsdk.command_lib.util.hooks.request_modifiers:SetFieldFromName:api_field=table.tableReference.tableId
- googlecloudsdk.command_lib.bq.hooks:ProcessSchemaUpdate
arguments:
resource:
help_text: The BigQuery table you want to update.
spec: !REF googlecloudsdk.command_lib.bq.resources:table
params:
- _REF_: googlecloudsdk.command_lib.bq.flags:table.description
- _REF_: googlecloudsdk.command_lib.bq.flags:table.expiration
- arg_name: relax-columns
required: false
metavar: FIELD_NAME
type: 'googlecloudsdk.calliope.arg_parsers:ArgList:'
help_text: |
A comma-separated list of field names in the current schema that should have their mode
changed from REQUIRED to NULLABLE.
For more details on updating and managing BigQuery schemas see:
https://cloud.google.com/bigquery/docs/managing-table-schemas
- group:
mutex: true
required: false
help_text: Specify changes to the table schema.
params:
- arg_name: add-columns
metavar: FIELD_NAME=FIELD_TYPE
api_field: table.schema.fields
type:
arg_dict:
flatten: true
spec:
- api_field: name
- api_field: type
help_text: |-
A comma-separated list of entries of the form FIELD_NAME[=FIELD_TYPE] specifying field names
and types for the columns being added to the table. FIELD_TYPE defaults to string if not present.
Possible FIELD_TYPES are `string`, `integer`, `float`, `boolean`, `record`, and `timestamp`.
For more details on BigQuery schemas see: https://cloud.google.com/bigquery/docs/schemas.
- arg_name: add-columns-file
api_field: table.schema
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
processor: googlecloudsdk.command_lib.bq.hooks:BqTableSchemaFileProcessor
help_text: |-
The name of a JSON file containing a single object containing an array each element
of which is an object with properties name, type, and, optionally a
mode (one of: `NULLABLE` or `REPEATED`), specifying the columns to be added
to the table. If mode is omitted the default is 'NULLABLE'.
For example:
{
'schema':
[
{
'name': 'field1',
'type': 'string',
'mode': 'REQUIRED'
},
{
'name': 'field2',
'type': 'integer',
'mode': 'REPEATED'
},
[
{
'name': 'fieldN',
'type': TYPE,
['mode': MODE]
}
...
]
]
}
For more details on BigQuery schemas see: https://cloud.google.com/bigquery/docs/schemas.