|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def label_table(table_id: str) -> None: |
| 17 | + orig_table_id = table_id |
| 18 | + # [START bigquery_label_table] |
| 19 | + from google.cloud import bigquery |
| 20 | + |
| 21 | + client = bigquery.Client() |
| 22 | + |
| 23 | + # TODO(dev): Change table_id to the full name of the table you want to create. |
| 24 | + table_id = "your-project.your_dataset.your_table_name" |
| 25 | + |
| 26 | + # [END bigquery_label_table] |
| 27 | + table_id = orig_table_id |
| 28 | + # [START bigquery_label_table] |
| 29 | + table = client.get_table(table_id) # API request |
| 30 | + |
| 31 | + labels = {"color": "green"} |
| 32 | + table.labels = labels |
| 33 | + |
| 34 | + table = client.update_table(table, ["labels"]) # API request |
| 35 | + |
| 36 | + print(f"Added {table.labels} to {table_id}.") |
| 37 | + # [END bigquery_label_table] |
0 commit comments