docs: revise delete label table code sample, add TODO to clean up sni… · TheNeuralBit/python-bigquery@0dab7d2 · GitHub
Skip to content

Commit 0dab7d2

Browse files
Mattix23aribrayparthea
authored
docs: revise delete label table code sample, add TODO to clean up sni… (googleapis#1466)
* docs: revise delete label table code sample, add TODO to clean up snippets.py * changed name of test function to align with file name Co-authored-by: aribray <45905583+aribray@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent bdfe888 commit 0dab7d2

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

docs/snippets.py

Lines changed: 2 additions & 0 deletions
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
from google.cloud import bigquery
16+
17+
18+
def delete_label_table(table_id: str, label_key: str) -> bigquery.Table:
19+
orig_table_id = table_id
20+
orig_label_key = label_key
21+
# [START bigquery_delete_label_table]
22+
from google.cloud import bigquery
23+
24+
client = bigquery.Client()
25+
26+
# TODO(dev): Change table_id to the full name of the table you wish to delete from.
27+
table_id = "your-project.your_dataset.your_table_name"
28+
# TODO(dev): Change label_key to the name of the label you want to remove.
29+
label_key = "color"
30+
# [END bigquery_delete_label_table]
31+
table_id = orig_table_id
32+
label_key = orig_label_key
33+
# [START bigquery_delete_label_table]
34+
table = client.get_table(table_id) # API request
35+
36+
# To delete a label from a table, set its value to None
37+
table.labels[label_key] = None
38+
39+
table = client.update_table(table, ["labels"]) # API request
40+
41+
print(f"Deleted label '{label_key}' from {table_id}.")
42+
# [END bigquery_delete_label_table]
43+
return table
Lines changed: 34 additions & 0 deletions

0 commit comments

Comments
 (0)