-
Notifications
You must be signed in to change notification settings - Fork 1.8k
docs: migrate code from googleapis/python-bigquery #18303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 250 commits
Commits
Show all changes
516 commits
Select commit
Hold shift + click to select a range
f1f6f5a
chore(deps): update all dependencies (#1101)
renovate-bot 3a08d64
chore(python): Noxfile recognizes that tests can live in a folder (#1…
gcf-owl-bot[bot] 92291cb
docs: show common job properties in `get_job` and `cancel_job` sample…
tswast b58a632
chore(deps): update dependency ipython to v8.0.1 [security] (#1126)
renovate-bot d054f73
chore(deps): update dependency ipython [security] (#1154)
renovate-bot 8cee481
samples: remove browser option from user credentials sample (#1147)
busunkim96 4e85774
deps: allow pyarrow 7.0 (#1112)
renovate-bot 7b6126f
chore: Adding support for pytest-xdist and pytest-parallel (#1160)
gcf-owl-bot[bot] 6a70e07
chore(deps): update all dependencies (#1156)
renovate-bot 762e5dd
chore(deps): update all dependencies (#1162)
renovate-bot 22cb16f
chore(deps): update all dependencies (#1163)
renovate-bot a19ab79
fix: upgrade black (#1177)
steffnay d905c2d
fix!: remove out-of-date BigQuery ML protocol buffers (#1178)
tswast 453b61b
chore(deps): update all dependencies (#1164)
renovate-bot 5cd90a3
chore(deps): update all dependencies (#1183)
renovate-bot 45dcf45
chore: use === in requirements.txt for environment specific pins (#1184)
renovate-bot f6db5f0
chore(deps): update all dependencies (#1185)
renovate-bot a8fd2ce
chore(deps): update all dependencies (#1192)
renovate-bot 16d112f
chore(deps): update dependency click to v8.1.2 (#1197)
renovate-bot 3d5d45c
chore(deps): update all dependencies (#1200)
renovate-bot 856f43c
chore(deps): update dependency google-cloud-bigquery-storage to v2.13…
renovate-bot fd72e79
chore(deps): update dependency google-auth to v2.6.3 (#1206)
renovate-bot 014972f
chore(deps): update dependency pyparsing to v3.0.8 (#1210)
renovate-bot ac72116
chore(deps): update dependency google-cloud-core to v2.3.0 (#1211)
renovate-bot 91eb716
chore(deps): update dependency google-auth to v2.6.4 (#1214)
renovate-bot b94b383
chore(deps): update dependency google-api-core to v2.7.2 (#1215)
renovate-bot cd7f687
fix: export bigquery.HivePartitioningOptions (#1217)
jli d886a1d
chore(deps): update dependency google-auth to v2.6.5 (#1219)
renovate-bot 9ff1236
chore(deps): update dependency typing-extensions to v4.2.0 (#1221)
renovate-bot 0d2a680
chore(python): add nox session to sort python imports (#1224)
gcf-owl-bot[bot] 84b228d
chore(deps): update all dependencies (#1227)
renovate-bot 8f5112f
chore(deps): update dependency pytest to v7.1.2 (#1229)
renovate-bot 0c06763
chore(deps): update dependency click to v8.1.3 (#1233)
renovate-bot 29a4a9a
chore(deps): update dependency ipython to v8.3.0 (#1234)
renovate-bot 98bab1c
chore(deps): update dependency google-api-core to v2.7.3 (#1236)
renovate-bot aac1802
chore(deps): update dependency matplotlib to v3.5.2 (#1237)
renovate-bot 9fe8be8
chore(deps): update all dependencies (#1238)
renovate-bot 156c21a
docs: updated variable typo in comment in code sample (#1239)
meredithslota 26bf857
chore: update all dependencies (#1244)
renovate-bot b1870d7
chore(deps): update dependency pyparsing to v3.0.9 (#1246)
renovate-bot 2dd7c63
chore(deps): update dependency libcst to v0.4.3 (#1247)
renovate-bot 813d1dd
chore(deps): update dependency grpcio to v1.46.1 (#1249)
renovate-bot 43ad439
chore(deps): update dependency googleapis-common-protos to v1.56.1 (#…
renovate-bot 96e6211
chore(deps): update all dependencies (#1253)
renovate-bot 52a0d58
chore(deps): update all dependencies (#1255)
renovate-bot 0bd1e37
feat: add support for table clones (#1235)
abecerrilsalas c6202d5
chore(deps): update all dependencies (#1258)
renovate-bot a2d0269
chore(deps): update all dependencies (#1264)
renovate-bot c2d201a
docs(samples): add table snapshot sample (#1274)
steffnay 9bf9889
fix: require python 3.7+ (#1284)
gcf-owl-bot[bot] e40a162
docs(samples): explicitly add bq to samples reqs, upgrade grpc to fix…
leahecole cd43bfd
chore(deps): update all dependencies (#1301)
renovate-bot 0c1c15d
chore(deps): update all dependencies (#1305)
renovate-bot d8cf20f
chore(deps): update all dependencies (#1308)
renovate-bot 87b90c9
chore(deps): update all dependencies (#1313)
renovate-bot e84ccc2
chore(deps): update dependency pytz to v2022.2.1 (#1316)
renovate-bot 4c8ca57
chore(deps): update dependency google-cloud-bigquery-storage to v2.14…
renovate-bot 55891fa
chore(deps): update dependency shapely to v1.8.3 (#1320)
renovate-bot c7f7bf8
chore(deps): update all dependencies (#1322)
renovate-bot 8d3fec4
chore(deps): update all dependencies (#1323)
renovate-bot 0a9a63f
chore(deps): update dependency proto-plus to v1.22.1 (#1330)
renovate-bot a29a5ed
chore(deps): update dependency pandas to v1.4.4 (#1332)
renovate-bot 95872dd
chore(deps): update dependency google-crc32c to v1.5.0 (#1334)
renovate-bot 25fa36f
fix: uses function (create_job) more appropriate to the described sam…
chalmerlowe 5a8291a
chore(deps): update all dependencies (#1339)
renovate-bot 723432e
chore(deps): update dependency google-cloud-bigquery-storage to v2.15…
renovate-bot 45e0b80
chore(deps): update dependency certifi to v2022.6.15.1 (#1346)
renovate-bot 3e47169
chore: detect samples tests in nested directories (#1349)
gcf-owl-bot[bot] 383ec8a
chore(deps): update all dependencies (#1351)
renovate-bot 308a573
chore(deps): update dependency google-api-core to v2.10.1 (#1353)
renovate-bot 0fcff8a
chore(deps): update all dependencies (#1354)
renovate-bot 65592b9
chore(deps): update all dependencies (#1358)
renovate-bot 0852c61
chore(deps): update all dependencies (#1360)
renovate-bot 8d5c8b4
chore(deps): update dependency db-dtypes to v1.0.4 (#1361)
renovate-bot f7b7b4f
chore(deps): update all dependencies (#1363)
renovate-bot ebcd76e
chore(deps): update all dependencies (#1380)
renovate-bot 03038c0
feat: reconfigure tqdm progress bar in %%bigquery magic (#1355)
aribray 1c5ccc8
chore(deps): update all dependencies (#1382)
renovate-bot 1990874
fix: corrects test for non-existent attribute (#1395)
chalmerlowe 3c30111
chore(python): drop flake8-import-order in samples noxfile (#1424)
gcf-owl-bot[bot] d2d5536
docs: created samples for load table and create table from schema fil…
Mattix23 45c29d6
docs: create sample to write schema file from table (#1439)
thejaredchapman 1d529ac
docs: revise sample for nested schema (#1446)
Mattix23 64a57b6
chore: install all sample dependencies when type checking samples (#1…
thejaredchapman 510b598
docs: revise label table code samples (#1451)
Mattix23 8d53168
docs: revise create table cmek sample (#1452)
Mattix23 0c3a4c9
chore(python): add support for python 3.11 [autoapprove] (#1454)
gcf-owl-bot[bot] 0628299
chore(deps): update dependency certifi to v2022.12.7 [security] (#1434)
renovate-bot 3ee6e65
chore(deps): update all dependencies (#1390)
renovate-bot 15a7399
chore(deps): update all dependencies (#1456)
renovate-bot 99cfa25
chore(deps): update all dependencies (#1460)
renovate-bot 32564d5
chore(deps): update all dependencies (#1461)
renovate-bot b53b640
docs: revise get table labels code sample, add TODO to clean up snipp…
Mattix23 cd4a8a8
chore(deps): update dependency packaging to v23 (#1462)
renovate-bot f2676d8
docs: revise delete label table code sample, add TODO to clean up sni…
Mattix23 c28fd69
docs: adds snippet for creating table with external data config (#1420)
aribray 0e2bfb2
chore(deps): update all dependencies (#1471)
renovate-bot f408f74
chore(deps): update all dependencies (#1475)
renovate-bot f90f00d
docs(samples): table variable fix (#1287)
adhiggs 8e258a6
chore(deps): update dependency google-cloud-bigquery-storage to v2.18…
renovate-bot aa510f2
chore(deps): update dependency geojson to v3 (#1478)
renovate-bot cf82ea5
chore(deps): update all dependencies (#1479)
renovate-bot 3ac0032
chore(deps): update dependency shapely to v2.0.1 (#1480)
renovate-bot 6dad5fa
chore(deps): update dependency fiona to v1.9.0 (#1482)
renovate-bot 2a06d6b
chore(deps): update dependency google-cloud-bigquery to v3.5.0 (#1485)
renovate-bot 498d383
chore(deps): update all dependencies to v1 (#1486)
renovate-bot 48a38c8
chore(deps): update all dependencies (#1501)
renovate-bot e72301f
chore(deps): update all dependencies (#1513)
renovate-bot 4275d19
chore(deps): update all dependencies (#1514)
renovate-bot 2c6bbe4
chore(deps): update dependency charset-normalizer to v3.1.0 (#1518)
renovate-bot ca79ecd
chore(deps): update all dependencies (#1522)
renovate-bot 51ea49e
chore(deps): update all dependencies (#1540)
renovate-bot 7be216b
chore(deps): update all dependencies (#1549)
renovate-bot d891b4f
chore(deps): update dependency google-cloud-bigquery to v3.10.0 (#1556)
renovate-bot d734f08
chore(deps): update all dependencies (#1557)
renovate-bot 3bbcefc
chore(deps): update dependency requests to v2.31.0 [security] (#1573)
renovate-bot c4edce8
chore(deps): update all dependencies (#1560)
renovate-bot 1bd95ed
chore(deps): update all dependencies (#1576)
renovate-bot 6b2a3d3
chore(deps): update all dependencies (#1577)
renovate-bot 60b584e
chore(deps): update all dependencies (#1606)
renovate-bot a8b1a52
test: enable copy table tests (#1609)
alvarowolfx 2045eef
chore(deps): update all dependencies (#1607)
renovate-bot e132ab3
chore(deps): bump certifi in /samples/geography (#1627)
dependabot[bot] ee00d1d
chore(deps): update all dependencies (#1626)
renovate-bot f083f14
chore(deps): update all dependencies (#1636)
renovate-bot 8789303
chore(docs): update region tag and move sample and test (#1648)
meredithslota 9363149
docs: Revise update_table_expiration sample (#1457)
thejaredchapman 8f5ff4d
docs: revised `create_partitioned_table` sample (#1447)
thejaredchapman 63ff0b8
docs: revised relax column mode sample (#1467)
thejaredchapman ab29105
chore: [autoapprove] Update `black` and `isort` to latest versions (#…
gcf-owl-bot[bot] fc055c3
chore: upgrade mypy (#1705)
Linchin e35d730
chore(deps): bump urllib3 from 1.26.15 to 1.26.18 in /samples/geograp…
dependabot[bot] 9b9c980
chore(deps): update dependency pyarrow to v14 [security] (#1718)
renovate-bot 3ce61e2
chore: standardize samples directory (#1727)
kiraksi 75fca5d
chore: standardize samples directory - delete unneeded dependencies (…
kiraksi bbc532f
feat: Add support for Python 3.12 (#1736)
gcf-owl-bot[bot] afda9f0
feat: add `Client.query_and_wait` which directly returns a `RowIterat…
tswast cefb6fc
chore: cleanup resources at startup (#1741)
kiraksi 959632f
docs: update multiple samples to change query to query_and_wait (#1784)
kiraksi 01e2fb1
docs: update the query with no cache sample to use query_and_wait API…
SalemJorden e2faf51
docs: remove unused query code sample (#1769)
tswast 2daf954
docs: Updates `query` to `query and wait` in samples/desktopapp/user_…
DevStephanie 9663662
docs: update `client_query_destination_table.py` sample to use `query…
SalemJorden bd4a3a4
docs: update to use `query_and_wait` in `client_query_w_positional_pa…
DevStephanie 97c42c8
Docs: update the query destination table legacy file to use query_and…
SalemJorden 1e8ba7e
docs: update sample for query_to_arrow to use query_and_wait API (#1776)
SalemJorden f671b11
docs: update query_external_sheets_permanent_table.py to use query_an…
SalemJorden 8660eb7
docs: update to use API (#1781)
SalemJorden 98abae1
docs: update to use `query_and_wait` in `samples/client_query_w_times…
DevStephanie 0443100
docs: update to_geodataframe to use query_and_wait functionality (#1800)
DevStephanie 356b3c4
docs: update `client_query_w_named_params.py` to use `query_and_wait`…
SalemJorden 0332441
docs(samples): updates to urllib3 constraint for Python 3.7 (#1834)
chalmerlowe cb68abd
chore(deps): update all dependencies (#1640)
renovate-bot 9bb13c8
chore: use mock from unittest (#1823)
parthea 477ebe4
chore(deps): update all dependencies (#1835)
renovate-bot f2e19d6
chore(deps): update all dependencies (#1849)
renovate-bot b559c10
chore(deps): update dependency pyarrow to v15.0.2 (#1861)
renovate-bot fbd58ac
fix: update error logging when converting to pyarrow column fails (#1…
chalmerlowe b38b269
chore(deps): update dependency google-auth to v2.29.0 (#1865)
renovate-bot 8670b25
chore(deps): update dependency google-api-core to v2.18.0 (#1866)
renovate-bot 3fa077a
feat: add `fields` parameter to `set_iam_policy` for consistency with…
tswast bf8ef64
chore(deps): update all dependencies (#1873)
renovate-bot 67b50e0
fix: make `pyarrow` an optional dependency post-3.20.0 yanked release…
tswast 48a2428
chore(deps): update all dependencies (#1875)
renovate-bot 5ca2938
chore(deps): update all dependencies (#1882)
renovate-bot 89ca02c
chore(deps): update all dependencies (#1891)
renovate-bot cf00806
chore(deps): update dependency idna to v3.7 [security] (#1896)
renovate-bot 26d12c9
chore(deps): update all dependencies (#1893)
renovate-bot 6e5b589
chore(deps): update all dependencies (#1904)
renovate-bot ab959e5
chore(deps): update all dependencies (#1916)
renovate-bot ccbd50a
chore(deps): update all dependencies (#1921)
renovate-bot 787313e
chore(deps): update all dependencies (#1926)
renovate-bot e2ab37c
chore(deps): update all dependencies (#1934)
renovate-bot 4925ef4
chore(deps): bump requests from 2.31.0 to 2.32.2 in /samples/geograph…
dependabot[bot] 445de37
chore(deps): update all dependencies (#1938)
renovate-bot 8dec077
testing: update BQML training option (#1943)
shollyman 2609735
chore(deps): update all dependencies (#1946)
renovate-bot cac945d
chore(deps): update all dependencies (#1954)
renovate-bot 21c8826
chore(deps): update dependency urllib3 to v2.2.2 [security] (#1959)
renovate-bot 72b5ae4
chore(deps): update all dependencies (#1955)
renovate-bot 29d377c
chore(deps): update dependency certifi to v2024.7.4 [security] (#1968)
renovate-bot 77b1dfc
feat: use `bigquery-magics` package for the `%%bigquery` magic (#1965)
tswast d418820
docs: add short mode query sample & test (#1978)
shollyman 6cc205a
chore(deps): update all dependencies (#1982)
renovate-bot cb94d3c
chore(deps): update all dependencies (#1983)
renovate-bot 751083f
chore(deps): update all dependencies (#1993)
renovate-bot c73a17b
chore(deps): update all dependencies (#2002)
renovate-bot f8d4fe6
chore(deps): update all dependencies (#2004)
renovate-bot 666e84d
testing: remove testing identity override (#2011)
shollyman ea1fda2
chore(deps): update all dependencies (#2005)
renovate-bot ae28765
chore(deps): update all dependencies (#2017)
renovate-bot ac5636c
chore(deps): update all dependencies (#2018)
renovate-bot cead7ea
chore(deps): update all dependencies (#2025)
renovate-bot d0cc2d2
chore(deps): update all dependencies (#2029)
renovate-bot dc66205
chore(deps): bump fiona from 1.9.6 to 1.10.0 in /samples/geography (#…
dependabot[bot] c89feea
chore(deps): update all dependencies (#2031)
renovate-bot bbcd3ff
chore(deps): update all dependencies (#2033)
renovate-bot fe3fb8d
build: use multiScm for Kokoro release builds (#2049)
gcf-owl-bot[bot] 6b115ae
chore(deps): update all dependencies (#2038)
renovate-bot 80a4a51
chore(deps): update all dependencies (#2064)
renovate-bot 022f554
chore(deps): update all dependencies (#2068)
renovate-bot 76853ac
chore(deps): update all dependencies (#2070)
renovate-bot 20510aa
chore(deps): update all dependencies (#2078)
renovate-bot e50f8f0
chore(deps): update all dependencies (#2096)
renovate-bot 28ecb45
chore(deps): update dependency grpcio to v1.69.0 (#2102)
renovate-bot 23da4c5
test: add unit test covering the case where worker streams are stoppe…
tswast d6ae6ba
deps: Remove Python 3.7 and 3.8 as supported runtimes (#2133)
chalmerlowe cb121be
chore(deps): update all dependencies (#2143)
renovate-bot 4d62f5e
chore(deps): update dependency pyasn1-modules to v0.4.2 (#2150)
renovate-bot 5c6f5d9
chore(deps): update dependency shapely to v2.1.0 (#2155)
renovate-bot 6476f2c
chore(deps): update dependency typing-extensions to v4.13.1 (#2156)
renovate-bot ce0002f
test: adds pytest-xdist to speed up processing of CI/CD checks (#2153)
chalmerlowe a145a4b
chore(deps): update all dependencies (#2158)
renovate-bot 9364272
chore(deps): update dependency db-dtypes to v1.4.3 (#2178)
renovate-bot 0cc489d
chore(deps): update all dependencies to v3.32.0 (#2179)
renovate-bot ba10f79
fix(deps): update all dependencies (#2184)
renovate-bot 15acd5e
chore(deps): update dependency google-auth to v2.40.2 (#2196)
renovate-bot 5b000ed
docs: use query_and_wait in the array parameters sample (#2202)
tswast df6f64c
feat: job creation mode GA (#2190)
shollyman 31e9e45
chore(deps): update dependency pytest-xdist to v3.7.0 (#2203)
renovate-bot f133aec
chore(deps): update all dependencies (#2205)
renovate-bot 3c55818
chore(deps): update all dependencies (#2209)
renovate-bot 73565b0
chore(deps): update all dependencies (#2211)
renovate-bot 9567692
chore(deps): update dependency requests to v2.32.4 (#2213)
renovate-bot a3f0bfe
chore(deps): update dependency google-api-core to v2.25.1 (#2215)
renovate-bot 73b1d67
chore(deps): bump urllib3 from 2.4.0 to 2.5.0 in /samples/geography (…
dependabot[bot] 37d277c
chore: add label job sample (#2219)
leahecole 14f16a6
chore(deps): update all dependencies (#2216)
renovate-bot 8757d85
chore(deps): update all dependencies (#2224)
renovate-bot 1b48ff1
chore(deps): update all dependencies (#2226)
renovate-bot d4aafa1
chore(deps): update dependency certifi to v2025.7.9 (#2232)
renovate-bot c4d9092
chore(deps): update dependency certifi to v2025.7.14 (#2237)
renovate-bot 71d04c3
chore(deps): update all dependencies to v3.35.0 (#2242)
renovate-bot 3f2c662
chore(deps): update all dependencies (#2243)
renovate-bot 77bd6b5
chore(deps): update dependency matplotlib to v3.10.5 (#2251)
renovate-bot a46d6c8
chore(deps): update all dependencies (#2253)
renovate-bot 4de31a5
chore(deps): update all dependencies (#2259)
renovate-bot 187f588
chore(deps): update all dependencies (#2275)
renovate-bot 0500c9e
chore(deps): update all dependencies (#2300)
renovate-bot 535a7c1
chore(deps): update dependency google-auth to v2.41.1 (#2312)
renovate-bot f2b1eba
chore(deps): update all dependencies (#2314)
renovate-bot bb4a68f
chore(python): Add Python 3.14 to python post processor image (#2317)
gcf-owl-bot[bot] 07a9f24
chore(deps): update dependency urllib3 to v2.6.0 [security] (#2342)
renovate-bot 7bf31d6
chore(deps): update dependency urllib3 to v2.6.3 [security] (#2357)
renovate-bot c22e051
chore(deps): update dependency geopandas to v1.1.2 [security] (#2411)
renovate-bot 4391569
chore(deps): update dependency pyasn1 to v0.6.2 [security] (#2407)
renovate-bot 86fe133
Merge remote-tracking branch 'migration/main' into python-bigquery-mi…
parthea afb8ce6
enable tests
parthea 10c8385
update requirements
parthea 1be5bd7
restore docs
parthea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md |
Empty file.
40 changes: 40 additions & 0 deletions
40
packages/google-cloud-bigquery/samples/add_empty_column.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def add_empty_column(table_id: str) -> None: | ||
| # [START bigquery_add_empty_column] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the table | ||
| # to add an empty column. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| table = client.get_table(table_id) # Make an API request. | ||
|
|
||
| original_schema = table.schema | ||
| new_schema = original_schema[:] # Creates a copy of the schema. | ||
| new_schema.append(bigquery.SchemaField("phone", "STRING")) | ||
|
|
||
| table.schema = new_schema | ||
| table = client.update_table(table, ["schema"]) # Make an API request. | ||
|
|
||
| if len(table.schema) == len(original_schema) + 1 == len(new_schema): | ||
| print("A new column has been added.") | ||
| else: | ||
| print("The column has not been added.") | ||
| # [END bigquery_add_empty_column] |
56 changes: 56 additions & 0 deletions
56
packages/google-cloud-bigquery/samples/browse_table_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def browse_table_data(table_id: str) -> None: | ||
| # [START bigquery_browse_table] | ||
|
|
||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the table to browse data rows. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| # Download all rows from a table. | ||
| rows_iter = client.list_rows(table_id) # Make an API request. | ||
|
|
||
| # Iterate over rows to make the API requests to fetch row data. | ||
| rows = list(rows_iter) | ||
| print("Downloaded {} rows from table {}".format(len(rows), table_id)) | ||
|
|
||
| # Download at most 10 rows. | ||
| rows_iter = client.list_rows(table_id, max_results=10) | ||
| rows = list(rows_iter) | ||
| print("Downloaded {} rows from table {}".format(len(rows), table_id)) | ||
|
|
||
| # Specify selected fields to limit the results to certain columns. | ||
| table = client.get_table(table_id) # Make an API request. | ||
| fields = table.schema[:2] # First two columns. | ||
| rows_iter = client.list_rows(table_id, selected_fields=fields, max_results=10) | ||
| print("Selected {} columns from table {}.".format(len(rows_iter.schema), table_id)) | ||
|
|
||
| rows = list(rows_iter) | ||
| print("Downloaded {} rows from table {}".format(len(rows), table_id)) | ||
|
|
||
| # Print row data in tabular format. | ||
| rows_iter = client.list_rows(table_id, max_results=10) | ||
| format_string = "{!s:<16} " * len(rows_iter.schema) | ||
| field_names = [field.name for field in rows_iter.schema] | ||
| print(format_string.format(*field_names)) # Prints column headers. | ||
|
|
||
| for row in rows_iter: | ||
| print(format_string.format(*row)) # Prints row data. | ||
| # [END bigquery_browse_table] |
49 changes: 49 additions & 0 deletions
49
packages/google-cloud-bigquery/samples/client_list_jobs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def client_list_jobs() -> None: | ||
| # [START bigquery_list_jobs] | ||
|
|
||
| from google.cloud import bigquery | ||
|
|
||
| import datetime | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # List the 10 most recent jobs in reverse chronological order. | ||
| # Omit the max_results parameter to list jobs from the past 6 months. | ||
| print("Last 10 jobs:") | ||
| for job in client.list_jobs(max_results=10): # API request(s) | ||
| print("{}".format(job.job_id)) | ||
|
|
||
| # The following are examples of additional optional parameters: | ||
|
|
||
| # Use min_creation_time and/or max_creation_time to specify a time window. | ||
| print("Jobs from the last ten minutes:") | ||
| ten_mins_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=10) | ||
| for job in client.list_jobs(min_creation_time=ten_mins_ago): | ||
| print("{}".format(job.job_id)) | ||
|
|
||
| # Use all_users to include jobs run by all users in the project. | ||
| print("Last 10 jobs run by all users:") | ||
| for job in client.list_jobs(max_results=10, all_users=True): | ||
| print("{} run by user: {}".format(job.job_id, job.user_email)) | ||
|
|
||
| # Use state_filter to filter by job state. | ||
| print("Last 10 jobs done:") | ||
| for job in client.list_jobs(max_results=10, state_filter="DONE"): | ||
| print("{}".format(job.job_id)) | ||
| # [END bigquery_list_jobs] |
49 changes: 49 additions & 0 deletions
49
packages/google-cloud-bigquery/samples/client_load_partitioned_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def client_load_partitioned_table(table_id: str) -> None: | ||
| # [START bigquery_load_table_partitioned] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the table to create. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| job_config = bigquery.LoadJobConfig( | ||
| schema=[ | ||
| bigquery.SchemaField("name", "STRING"), | ||
| bigquery.SchemaField("post_abbr", "STRING"), | ||
| bigquery.SchemaField("date", "DATE"), | ||
| ], | ||
| skip_leading_rows=1, | ||
| time_partitioning=bigquery.TimePartitioning( | ||
| type_=bigquery.TimePartitioningType.DAY, | ||
| field="date", # Name of the column to use for partitioning. | ||
| expiration_ms=7776000000, # 90 days. | ||
| ), | ||
| ) | ||
| uri = "gs://cloud-samples-data/bigquery/us-states/us-states-by-date.csv" | ||
|
|
||
| load_job = client.load_table_from_uri( | ||
| uri, table_id, job_config=job_config | ||
| ) # Make an API request. | ||
|
|
||
| load_job.result() # Wait for the job to complete. | ||
|
|
||
| table = client.get_table(table_id) | ||
| print("Loaded {} rows to table {}".format(table.num_rows, table_id)) | ||
| # [END bigquery_load_table_partitioned] | ||
50 changes: 50 additions & 0 deletions
50
packages/google-cloud-bigquery/samples/client_query_add_column.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def client_query_add_column(table_id: str) -> None: | ||
| # [START bigquery_add_column_query_append] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the destination table. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| # Retrieves the destination table and checks the length of the schema. | ||
| table = client.get_table(table_id) # Make an API request. | ||
| print("Table {} contains {} columns".format(table_id, len(table.schema))) | ||
|
|
||
| # Configures the query to append the results to a destination table, | ||
| # allowing field addition. | ||
| job_config = bigquery.QueryJobConfig( | ||
| destination=table_id, | ||
| schema_update_options=[bigquery.SchemaUpdateOption.ALLOW_FIELD_ADDITION], | ||
| write_disposition=bigquery.WriteDisposition.WRITE_APPEND, | ||
| ) | ||
|
|
||
| # Start the query, passing in the extra configuration. | ||
| client.query_and_wait( | ||
| # In this example, the existing table contains only the 'full_name' and | ||
| # 'age' columns, while the results of this query will contain an | ||
| # additional 'favorite_color' column. | ||
| 'SELECT "Timmy" as full_name, 85 as age, "Blue" as favorite_color;', | ||
| job_config=job_config, | ||
| ) # Make an API request and wait for job to complete. | ||
|
|
||
| # Checks the updated length of the schema. | ||
| table = client.get_table(table_id) # Make an API request. | ||
| print("Table {} now contains {} columns".format(table_id, len(table.schema))) | ||
| # [END bigquery_add_column_query_append] |
53 changes: 53 additions & 0 deletions
53
packages/google-cloud-bigquery/samples/client_query_batch.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| import typing | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from google.cloud import bigquery | ||
|
|
||
|
|
||
| def client_query_batch() -> "bigquery.QueryJob": | ||
| # [START bigquery_query_batch] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| job_config = bigquery.QueryJobConfig( | ||
| # Run at batch priority, which won't count toward concurrent rate limit. | ||
| priority=bigquery.QueryPriority.BATCH | ||
| ) | ||
|
|
||
| sql = """ | ||
| SELECT corpus | ||
| FROM `bigquery-public-data.samples.shakespeare` | ||
| GROUP BY corpus; | ||
| """ | ||
|
|
||
| # Start the query, passing in the extra configuration. | ||
| query_job = client.query(sql, job_config=job_config) # Make an API request. | ||
|
|
||
| # Check on the progress by getting the job's updated state. Once the state | ||
| # is `DONE`, the results are ready. | ||
| query_job = typing.cast( | ||
| "bigquery.QueryJob", | ||
| client.get_job( | ||
| query_job.job_id, location=query_job.location | ||
| ), # Make an API request. | ||
| ) | ||
|
|
||
| print("Job {} is currently in state {}".format(query_job.job_id, query_job.state)) | ||
| # [END bigquery_query_batch] | ||
| return query_job |
40 changes: 40 additions & 0 deletions
40
packages/google-cloud-bigquery/samples/client_query_destination_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def client_query_destination_table(table_id: str) -> None: | ||
| # [START bigquery_query_destination_table] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the destination table. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| job_config = bigquery.QueryJobConfig(destination=table_id) | ||
|
|
||
| sql = """ | ||
| SELECT corpus | ||
| FROM `bigquery-public-data.samples.shakespeare` | ||
| GROUP BY corpus; | ||
| """ | ||
|
|
||
| # Start the query, passing in the extra configuration. | ||
| client.query_and_wait( | ||
| sql, job_config=job_config | ||
| ) # Make an API request and wait for the query to finish. | ||
|
|
||
| print("Query results loaded to the table {}".format(table_id)) | ||
| # [END bigquery_query_destination_table] |
43 changes: 43 additions & 0 deletions
43
packages/google-cloud-bigquery/samples/client_query_destination_table_clustered.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Copyright 2020 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
|
|
||
| def client_query_destination_table_clustered(table_id: str) -> None: | ||
| # [START bigquery_query_clustered_table] | ||
| from google.cloud import bigquery | ||
|
|
||
| # Construct a BigQuery client object. | ||
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set table_id to the ID of the destination table. | ||
| # table_id = "your-project.your_dataset.your_table_name" | ||
|
|
||
| sql = "SELECT * FROM `bigquery-public-data.samples.shakespeare`" | ||
| cluster_fields = ["corpus"] | ||
|
|
||
| job_config = bigquery.QueryJobConfig( | ||
| clustering_fields=cluster_fields, destination=table_id | ||
| ) | ||
|
|
||
| # Start the query, passing in the extra configuration. | ||
| client.query_and_wait( | ||
| sql, job_config=job_config | ||
| ) # Make an API request and wait for job to complete. | ||
|
|
||
| table = client.get_table(table_id) # Make an API request. | ||
| if table.clustering_fields == cluster_fields: | ||
| print( | ||
| "The destination table is written using the cluster_fields configuration." | ||
| ) | ||
| # [END bigquery_query_clustered_table] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved readability and to avoid 'magic numbers', it's better to use the
datetimemodule to calculate time durations. This makes the code clearer about the intent (e.g., setting an expiration of 90 days).