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

Commita097631

Browse files
docs: revise sample for nested schema (#1446)
* docs: revise sample for nested schema* 🦉 Updates from OwlBot post-processorSeehttps://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md* added TODOCo-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent093cc68 commita097631

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

‎docs/snippets.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def test_create_client_default_credentials():
118118
assertclientisnotNone
119119

120120

121+
# TODO(Mattix23): After code sample from https://github.com/googleapis/python-bigquery/pull/1446
122+
# is updated from cloud.google.com delete this.
121123
deftest_create_table_nested_repeated_schema(client,to_delete):
122124
dataset_id="create_table_nested_repeated_{}".format(_millis())
123125
project=client.project
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
defnested_schema(table_id:str)->None:
17+
orig_table_id=table_id
18+
# [START bigquery_nested_repeated_schema]
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+
schema= [
27+
bigquery.SchemaField("id","STRING",mode="NULLABLE"),
28+
bigquery.SchemaField("first_name","STRING",mode="NULLABLE"),
29+
bigquery.SchemaField("last_name","STRING",mode="NULLABLE"),
30+
bigquery.SchemaField("dob","DATE",mode="NULLABLE"),
31+
bigquery.SchemaField(
32+
"addresses",
33+
"RECORD",
34+
mode="REPEATED",
35+
fields=[
36+
bigquery.SchemaField("status","STRING",mode="NULLABLE"),
37+
bigquery.SchemaField("address","STRING",mode="NULLABLE"),
38+
bigquery.SchemaField("city","STRING",mode="NULLABLE"),
39+
bigquery.SchemaField("state","STRING",mode="NULLABLE"),
40+
bigquery.SchemaField("zip","STRING",mode="NULLABLE"),
41+
bigquery.SchemaField("numberOfYears","STRING",mode="NULLABLE"),
42+
],
43+
),
44+
]
45+
# [END bigquery_nested_repeated_schema]
46+
47+
table_id=orig_table_id
48+
49+
# [START bigquery_nested_repeated_schema]
50+
table=bigquery.Table(table_id,schema=schema)
51+
table=client.create_table(table)# API request
52+
53+
print(f"Created table{table.project}.{table.dataset_id}.{table.table_id}.")
54+
# [END bigquery_nested_repeated_schema]
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+
importnested_repeated_schema
18+
19+
iftyping.TYPE_CHECKING:
20+
importpytest
21+
22+
23+
deftest_create_table(
24+
capsys:"pytest.CaptureFixture[str]",
25+
random_table_id:str,
26+
)->None:
27+
28+
nested_repeated_schema.nested_schema(random_table_id)
29+
30+
out,_=capsys.readouterr()
31+
assert"Created"inout
32+
assertrandom_table_idinout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp