Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit14ae1f2

Browse files
Mattix23gcf-owl-bot[bot]tswast
authored
docs: revise label table code samples (#1451)
* docs: revise label table code samples* 🦉 Updates from OwlBot post-processorSeehttps://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md* added TODO to clean up snippets.pyCo-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>Co-authored-by: Tim Swast <swast@google.com>
1 parented1de4f commit14ae1f2

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

‎docs/snippets.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ def test_manage_table_labels(client, to_delete):
250250
table=bigquery.Table(dataset.table(table_id),schema=SCHEMA)
251251
table=client.create_table(table)
252252

253+
# TODO(Mattix23): After code sample from https://github.com/googleapis/python-bigquery/pull/1451
254+
# is updated from cloud.google.com delete this.
255+
253256
# [START bigquery_label_table]
254257
# from google.cloud import bigquery
255258
# client = bigquery.Client()

‎samples/snippets/label_table.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
deflabel_table(table_id:str)->None:
17+
orig_table_id=table_id
18+
# [START bigquery_label_table]
19+
fromgoogle.cloudimportbigquery
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]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
importtyping
16+
17+
importlabel_table
18+
19+
iftyping.TYPE_CHECKING:
20+
importpytest
21+
22+
23+
deftest_label_table(
24+
capsys:"pytest.CaptureFixture[str]",
25+
table_id:str,
26+
)->None:
27+
28+
label_table.label_table(table_id)
29+
30+
out,_=capsys.readouterr()
31+
assert"color"inout
32+
asserttable_idinout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp