-
Notifications
You must be signed in to change notification settings - Fork 6.7k
migrate code from googleapis/python-bigquery #14589
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
Closed
Closed
Changes from all commits
Commits
Show all changes
513 commits
Select commit
Hold shift + click to select a range
f231c67
chore(deps): update all dependencies (#1091)
renovate-bot 1e52497
chore(deps): update all dependencies (#1098)
renovate-bot 67d376c
chore(samples): Add check for tests in directory (#1103)
gcf-owl-bot[bot] 3cc9429
chore(deps): update all dependencies (#1101)
renovate-bot 9c2ad1e
chore(python): Noxfile recognizes that tests can live in a folder (#1…
gcf-owl-bot[bot] d0fc45d
docs: show common job properties in `get_job` and `cancel_job` sample…
tswast d81b554
chore(deps): update dependency ipython to v8.0.1 [security] (#1126)
renovate-bot 0d8d8fb
chore(deps): update dependency ipython [security] (#1154)
renovate-bot 5f243e3
samples: remove browser option from user credentials sample (#1147)
busunkim96 172f6ee
deps: allow pyarrow 7.0 (#1112)
renovate-bot 72e2c2b
chore: Adding support for pytest-xdist and pytest-parallel (#1160)
gcf-owl-bot[bot] 5fb2ee7
chore(deps): update all dependencies (#1156)
renovate-bot dddcf2e
chore(deps): update all dependencies (#1162)
renovate-bot 39d89a5
chore(deps): update all dependencies (#1163)
renovate-bot d6e8918
fix: upgrade black (#1177)
steffnay 767a71d
fix!: remove out-of-date BigQuery ML protocol buffers (#1178)
tswast b3dd6d9
chore(deps): update all dependencies (#1164)
renovate-bot d1bb74f
chore(deps): update all dependencies (#1183)
renovate-bot 878e47a
chore: use === in requirements.txt for environment specific pins (#1184)
renovate-bot 6a07af9
chore(deps): update all dependencies (#1185)
renovate-bot c56fa1e
chore(deps): update all dependencies (#1192)
renovate-bot 4f46e74
chore(deps): update dependency click to v8.1.2 (#1197)
renovate-bot a658af5
chore(deps): update all dependencies (#1200)
renovate-bot fe09ea1
chore(deps): update dependency google-cloud-bigquery-storage to v2.13…
renovate-bot 118d0bb
chore(deps): update dependency google-auth to v2.6.3 (#1206)
renovate-bot 6e0266d
chore(deps): update dependency pyparsing to v3.0.8 (#1210)
renovate-bot 3d72600
chore(deps): update dependency google-cloud-core to v2.3.0 (#1211)
renovate-bot 81aae7e
chore(deps): update dependency google-auth to v2.6.4 (#1214)
renovate-bot 7982abb
chore(deps): update dependency google-api-core to v2.7.2 (#1215)
renovate-bot b1bd6f6
fix: export bigquery.HivePartitioningOptions (#1217)
jli ec0ca20
chore(deps): update dependency google-auth to v2.6.5 (#1219)
renovate-bot 09caeb2
chore(deps): update dependency typing-extensions to v4.2.0 (#1221)
renovate-bot 062f04b
chore(python): add nox session to sort python imports (#1224)
gcf-owl-bot[bot] 5bd9f61
chore(deps): update all dependencies (#1227)
renovate-bot 730d0af
chore(deps): update dependency pytest to v7.1.2 (#1229)
renovate-bot 910a537
chore(deps): update dependency click to v8.1.3 (#1233)
renovate-bot a5699a0
chore(deps): update dependency ipython to v8.3.0 (#1234)
renovate-bot d22d600
chore(deps): update dependency google-api-core to v2.7.3 (#1236)
renovate-bot 45e1179
chore(deps): update dependency matplotlib to v3.5.2 (#1237)
renovate-bot c3d4c2d
chore(deps): update all dependencies (#1238)
renovate-bot ffef9c1
docs: updated variable typo in comment in code sample (#1239)
meredithslota 07b6993
chore: update all dependencies (#1244)
renovate-bot cc22ed6
chore(deps): update dependency pyparsing to v3.0.9 (#1246)
renovate-bot 667c446
chore(deps): update dependency libcst to v0.4.3 (#1247)
renovate-bot b6cb440
chore(deps): update dependency grpcio to v1.46.1 (#1249)
renovate-bot ed280e5
chore(deps): update dependency googleapis-common-protos to v1.56.1 (#…
renovate-bot 3ad8c7b
chore(deps): update all dependencies (#1253)
renovate-bot 086daf1
chore(deps): update all dependencies (#1255)
renovate-bot ec19a8b
feat: add support for table clones (#1235)
abecerrilsalas 8f0a68d
chore(deps): update all dependencies (#1258)
renovate-bot 106e70f
chore(deps): update all dependencies (#1264)
renovate-bot 66b581d
docs(samples): add table snapshot sample (#1274)
steffnay bc5b6b2
fix: require python 3.7+ (#1284)
gcf-owl-bot[bot] 5fa2869
docs(samples): explicitly add bq to samples reqs, upgrade grpc to fix…
leahecole d318bdf
chore(deps): update all dependencies (#1301)
renovate-bot 65a0fda
chore(deps): update all dependencies (#1305)
renovate-bot bd30685
chore(deps): update all dependencies (#1308)
renovate-bot 06693ba
chore(deps): update all dependencies (#1313)
renovate-bot 92ae5d8
chore(deps): update dependency pytz to v2022.2.1 (#1316)
renovate-bot 95ab9c1
chore(deps): update dependency google-cloud-bigquery-storage to v2.14…
renovate-bot e6a07af
chore(deps): update dependency shapely to v1.8.3 (#1320)
renovate-bot c2b761c
chore(deps): update all dependencies (#1322)
renovate-bot a8ad3bf
chore(deps): update all dependencies (#1323)
renovate-bot de5040a
chore(deps): update dependency proto-plus to v1.22.1 (#1330)
renovate-bot d4cdf74
chore(deps): update dependency pandas to v1.4.4 (#1332)
renovate-bot 2fb0a1e
chore(deps): update dependency google-crc32c to v1.5.0 (#1334)
renovate-bot 00d941c
fix: uses function (create_job) more appropriate to the described sam…
chalmerlowe 0d46444
chore(deps): update all dependencies (#1339)
renovate-bot 953dacd
chore(deps): update dependency google-cloud-bigquery-storage to v2.15…
renovate-bot ba09913
chore(deps): update dependency certifi to v2022.6.15.1 (#1346)
renovate-bot 41a62f5
chore: detect samples tests in nested directories (#1349)
gcf-owl-bot[bot] 888e546
chore(deps): update all dependencies (#1351)
renovate-bot 97677ef
chore(deps): update dependency google-api-core to v2.10.1 (#1353)
renovate-bot 38e6a9a
chore(deps): update all dependencies (#1354)
renovate-bot 04cb0d5
chore(deps): update all dependencies (#1358)
renovate-bot 8d2f934
chore(deps): update all dependencies (#1360)
renovate-bot 5e5f048
chore(deps): update dependency db-dtypes to v1.0.4 (#1361)
renovate-bot ba40821
chore(deps): update all dependencies (#1363)
renovate-bot b90aa5a
chore(deps): update all dependencies (#1380)
renovate-bot 333be9c
feat: reconfigure tqdm progress bar in %%bigquery magic (#1355)
aribray cc91583
chore(deps): update all dependencies (#1382)
renovate-bot 969b9f2
fix: corrects test for non-existent attribute (#1395)
chalmerlowe adfa9d1
chore(python): drop flake8-import-order in samples noxfile (#1424)
gcf-owl-bot[bot] 05d7f53
docs: created samples for load table and create table from schema fil…
Mattix23 0cde687
docs: create sample to write schema file from table (#1439)
thejaredchapman f53c250
docs: revise sample for nested schema (#1446)
Mattix23 41781a6
chore: install all sample dependencies when type checking samples (#1…
thejaredchapman 4241ab2
docs: revise label table code samples (#1451)
Mattix23 24d7745
docs: revise create table cmek sample (#1452)
Mattix23 cfc0d90
chore(python): add support for python 3.11 [autoapprove] (#1454)
gcf-owl-bot[bot] 0b2eec7
chore(deps): update dependency certifi to v2022.12.7 [security] (#1434)
renovate-bot ab20806
chore(deps): update all dependencies (#1390)
renovate-bot 785feb9
chore(deps): update all dependencies (#1456)
renovate-bot a8d1020
chore(deps): update all dependencies (#1460)
renovate-bot a406fc4
chore(deps): update all dependencies (#1461)
renovate-bot 386c2bc
docs: revise get table labels code sample, add TODO to clean up snipp…
Mattix23 75975c1
chore(deps): update dependency packaging to v23 (#1462)
renovate-bot f25b152
docs: revise delete label table code sample, add TODO to clean up sni…
Mattix23 a33f459
docs: adds snippet for creating table with external data config (#1420)
aribray af9ad01
chore(deps): update all dependencies (#1471)
renovate-bot 4863daf
chore(deps): update all dependencies (#1475)
renovate-bot 634305d
docs(samples): table variable fix (#1287)
adhiggs 3114f05
chore(deps): update dependency google-cloud-bigquery-storage to v2.18…
renovate-bot e5d086e
chore(deps): update dependency geojson to v3 (#1478)
renovate-bot 12ca190
chore(deps): update all dependencies (#1479)
renovate-bot 38a7e2a
chore(deps): update dependency shapely to v2.0.1 (#1480)
renovate-bot b731654
chore(deps): update dependency fiona to v1.9.0 (#1482)
renovate-bot de9d01e
chore(deps): update dependency google-cloud-bigquery to v3.5.0 (#1485)
renovate-bot 5a9bef3
chore(deps): update all dependencies to v1 (#1486)
renovate-bot 61a9346
chore(deps): update all dependencies (#1501)
renovate-bot 59d7300
chore(deps): update all dependencies (#1513)
renovate-bot 6a41d5e
chore(deps): update all dependencies (#1514)
renovate-bot bae1ee2
chore(deps): update dependency charset-normalizer to v3.1.0 (#1518)
renovate-bot 34b4540
chore(deps): update all dependencies (#1522)
renovate-bot 1eb45b9
chore(deps): update all dependencies (#1540)
renovate-bot 10adb53
chore(deps): update all dependencies (#1549)
renovate-bot e1b7a39
chore(deps): update dependency google-cloud-bigquery to v3.10.0 (#1556)
renovate-bot eeeca25
chore(deps): update all dependencies (#1557)
renovate-bot 302e920
chore(deps): update dependency requests to v2.31.0 [security] (#1573)
renovate-bot 936ea49
chore(deps): update all dependencies (#1560)
renovate-bot dd5d6d1
chore(deps): update all dependencies (#1576)
renovate-bot 6614159
chore(deps): update all dependencies (#1577)
renovate-bot 2a2167f
chore(deps): update all dependencies (#1606)
renovate-bot c17fe55
test: enable copy table tests (#1609)
alvarowolfx 77325c4
chore(deps): update all dependencies (#1607)
renovate-bot 225710a
chore(deps): bump certifi in /samples/geography (#1627)
dependabot[bot] 29df1db
chore(deps): update all dependencies (#1626)
renovate-bot 516b28a
chore(deps): update all dependencies (#1636)
renovate-bot 62a9ceb
chore(docs): update region tag and move sample and test (#1648)
meredithslota 667e8c3
docs: Revise update_table_expiration sample (#1457)
thejaredchapman 17660f5
docs: revised `create_partitioned_table` sample (#1447)
thejaredchapman 15638a8
docs: revised relax column mode sample (#1467)
thejaredchapman dae7ce0
chore: [autoapprove] Update `black` and `isort` to latest versions (#…
gcf-owl-bot[bot] a505318
chore: upgrade mypy (#1705)
Linchin 7341a83
chore(deps): bump urllib3 from 1.26.15 to 1.26.18 in /samples/geograp…
dependabot[bot] 2c16169
chore(deps): update dependency pyarrow to v14 [security] (#1718)
renovate-bot 2f5b6e1
chore: standardize samples directory (#1727)
kiraksi cd8e83a
chore: standardize samples directory - delete unneeded dependencies (…
kiraksi 3165487
feat: Add support for Python 3.12 (#1736)
gcf-owl-bot[bot] 127d8df
feat: add `Client.query_and_wait` which directly returns a `RowIterat…
tswast 8c52c28
chore: cleanup resources at startup (#1741)
kiraksi 1a38aee
docs: update multiple samples to change query to query_and_wait (#1784)
kiraksi 53a8fd8
docs: update the query with no cache sample to use query_and_wait API…
SalemJorden f5296f6
docs: remove unused query code sample (#1769)
tswast 379b518
docs: Updates `query` to `query and wait` in samples/desktopapp/user_…
DevStephanie 31834e5
docs: update `client_query_destination_table.py` sample to use `query…
SalemJorden 57d373c
docs: update to use `query_and_wait` in `client_query_w_positional_pa…
DevStephanie d7e7297
Docs: update the query destination table legacy file to use query_and…
SalemJorden 21dcbc4
docs: update sample for query_to_arrow to use query_and_wait API (#1776)
SalemJorden c965c9a
docs: update query_external_sheets_permanent_table.py to use query_an…
SalemJorden f8623e6
docs: update to use API (#1781)
SalemJorden 94f5810
docs: update to use `query_and_wait` in `samples/client_query_w_times…
DevStephanie 7df38bd
docs: update to_geodataframe to use query_and_wait functionality (#1800)
DevStephanie e55307e
docs: update `client_query_w_named_params.py` to use `query_and_wait`…
SalemJorden 174b110
docs(samples): updates to urllib3 constraint for Python 3.7 (#1834)
chalmerlowe 483de9f
chore(deps): update all dependencies (#1640)
renovate-bot b12a3bb
chore: use mock from unittest (#1823)
parthea 9ac17c0
chore(deps): update all dependencies (#1835)
renovate-bot 8e7a524
chore(deps): update all dependencies (#1849)
renovate-bot 93b2ae4
chore(deps): update dependency pyarrow to v15.0.2 (#1861)
renovate-bot 4041102
fix: update error logging when converting to pyarrow column fails (#1…
chalmerlowe 9ea3d1f
chore(deps): update dependency google-auth to v2.29.0 (#1865)
renovate-bot 5027c07
chore(deps): update dependency google-api-core to v2.18.0 (#1866)
renovate-bot 7011ba0
feat: add `fields` parameter to `set_iam_policy` for consistency with…
tswast 880dc53
chore(deps): update all dependencies (#1873)
renovate-bot 19a5a41
fix: make `pyarrow` an optional dependency post-3.20.0 yanked release…
tswast 727b00c
chore(deps): update all dependencies (#1875)
renovate-bot eeea2f3
chore(deps): update all dependencies (#1882)
renovate-bot 156b26b
chore(deps): update all dependencies (#1891)
renovate-bot 386848b
chore(deps): update dependency idna to v3.7 [security] (#1896)
renovate-bot f1a4b06
chore(deps): update all dependencies (#1893)
renovate-bot dcc9e64
chore(deps): update all dependencies (#1904)
renovate-bot e1a9be0
chore(deps): update all dependencies (#1916)
renovate-bot 8e9c517
chore(deps): update all dependencies (#1921)
renovate-bot 8d8ae1d
chore(deps): update all dependencies (#1926)
renovate-bot 56b8b3c
chore(deps): update all dependencies (#1934)
renovate-bot 5c04a0d
chore(deps): bump requests from 2.31.0 to 2.32.2 in /samples/geograph…
dependabot[bot] 8de6f1e
chore(deps): update all dependencies (#1938)
renovate-bot cc0c568
testing: update BQML training option (#1943)
shollyman 39793a0
chore(deps): update all dependencies (#1946)
renovate-bot 2fd59e6
chore(deps): update all dependencies (#1954)
renovate-bot 87c7263
chore(deps): update dependency urllib3 to v2.2.2 [security] (#1959)
renovate-bot 3fa6f6d
chore(deps): update all dependencies (#1955)
renovate-bot ce7e959
chore(deps): update dependency certifi to v2024.7.4 [security] (#1968)
renovate-bot 6168a09
feat: use `bigquery-magics` package for the `%%bigquery` magic (#1965)
tswast e82df33
docs: add short mode query sample & test (#1978)
shollyman e9b58de
chore(deps): update all dependencies (#1982)
renovate-bot febe765
chore(deps): update all dependencies (#1983)
renovate-bot 64b4c90
chore(deps): update all dependencies (#1993)
renovate-bot 3d51539
chore(deps): update all dependencies (#2002)
renovate-bot 6df4f7a
chore(deps): update all dependencies (#2004)
renovate-bot b3bcacc
testing: remove testing identity override (#2011)
shollyman aff5b9d
chore(deps): update all dependencies (#2005)
renovate-bot 2761813
chore(deps): update all dependencies (#2017)
renovate-bot eedd32e
chore(deps): update all dependencies (#2018)
renovate-bot 0a14b3d
chore(deps): update all dependencies (#2025)
renovate-bot ab7cb55
chore(deps): update all dependencies (#2029)
renovate-bot e1cf25b
chore(deps): bump fiona from 1.9.6 to 1.10.0 in /samples/geography (#…
dependabot[bot] 3e943f3
chore(deps): update all dependencies (#2031)
renovate-bot 3236688
chore(deps): update all dependencies (#2033)
renovate-bot c13faed
build: use multiScm for Kokoro release builds (#2049)
gcf-owl-bot[bot] 273c7b2
chore(deps): update all dependencies (#2038)
renovate-bot ba3835d
chore(deps): update all dependencies (#2064)
renovate-bot 7979dc7
chore(deps): update all dependencies (#2068)
renovate-bot 047cf76
chore(deps): update all dependencies (#2070)
renovate-bot c52f8e0
chore(deps): update all dependencies (#2078)
renovate-bot a15760f
chore(deps): update all dependencies (#2096)
renovate-bot c8ac235
chore(deps): update dependency grpcio to v1.69.0 (#2102)
renovate-bot fd6b146
test: add unit test covering the case where worker streams are stoppe…
tswast 0991d59
deps: Remove Python 3.7 and 3.8 as supported runtimes (#2133)
chalmerlowe 833e6ca
chore(deps): update all dependencies (#2143)
renovate-bot 1762258
chore(deps): update dependency pyasn1-modules to v0.4.2 (#2150)
renovate-bot 976622b
chore(deps): update dependency shapely to v2.1.0 (#2155)
renovate-bot 278e671
chore(deps): update dependency typing-extensions to v4.13.1 (#2156)
renovate-bot aa7e2fa
test: adds pytest-xdist to speed up processing of CI/CD checks (#2153)
chalmerlowe 40b9199
chore(deps): update all dependencies (#2158)
renovate-bot 1c15cab
chore(deps): update dependency db-dtypes to v1.4.3 (#2178)
renovate-bot f9495e9
chore(deps): update all dependencies to v3.32.0 (#2179)
renovate-bot 05d50c3
fix(deps): update all dependencies (#2184)
renovate-bot a967a3f
chore(deps): update dependency google-auth to v2.40.2 (#2196)
renovate-bot 66272d2
docs: use query_and_wait in the array parameters sample (#2202)
tswast 5c7ffdf
feat: job creation mode GA (#2190)
shollyman 23d7b6a
chore(deps): update dependency pytest-xdist to v3.7.0 (#2203)
renovate-bot 6e3c1c5
chore(deps): update all dependencies (#2205)
renovate-bot 81e9d49
chore(deps): update all dependencies (#2209)
renovate-bot 7b57832
chore(deps): update all dependencies (#2211)
renovate-bot 0ff5d2f
chore(deps): update dependency requests to v2.32.4 (#2213)
renovate-bot 65d2b22
chore(deps): update dependency google-api-core to v2.25.1 (#2215)
renovate-bot c733265
chore(deps): bump urllib3 from 2.4.0 to 2.5.0 in /samples/geography (…
dependabot[bot] eb196af
chore: add label job sample (#2219)
leahecole c383c65
chore(deps): update all dependencies (#2216)
renovate-bot a42ab2e
chore(deps): update all dependencies (#2224)
renovate-bot fa6325b
chore(deps): update all dependencies (#2226)
renovate-bot c536b75
chore(deps): update dependency certifi to v2025.7.9 (#2232)
renovate-bot c2b7906
chore(deps): update dependency certifi to v2025.7.14 (#2237)
renovate-bot b046d6a
chore(deps): update all dependencies to v3.35.0 (#2242)
renovate-bot 4be13ee
chore(deps): update all dependencies (#2243)
renovate-bot 70d1658
chore(deps): update dependency matplotlib to v3.10.5 (#2251)
renovate-bot 953521b
chore(deps): update all dependencies (#2253)
renovate-bot c48797b
chore(deps): update all dependencies (#2259)
renovate-bot e452ea3
chore(deps): update all dependencies (#2275)
renovate-bot 52c15e3
chore(deps): update all dependencies (#2300)
renovate-bot bd41b2a
chore(deps): update dependency google-auth to v2.41.1 (#2312)
renovate-bot e1a63ef
chore(deps): update all dependencies (#2314)
renovate-bot f240fb0
chore(python): Add Python 3.14 to python post processor image (#2317)
gcf-owl-bot[bot] bd147ea
chore(deps): update dependency urllib3 to v2.6.0 [security] (#2342)
renovate-bot 87f9f3e
chore(deps): update dependency urllib3 to v2.6.3 [security] (#2357)
renovate-bot 5d236f7
chore(deps): update dependency geopandas to v1.1.2 [security] (#2411)
renovate-bot 56e7ee7
chore(deps): update dependency pyasn1 to v0.6.2 [security] (#2407)
renovate-bot efaa148
Merge remote-tracking branch 'migration/main' into python-bigquery-mi…
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.
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] |
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] | ||
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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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] | ||||||
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] |
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] |
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 |
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] |
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.
Calling
list(rows_iter)on an arbitrary table loads all rows into memory at once, which can cause Out Of Memory (OOM) errors for large tables. Since the goal here is only to print the total number of rows, use thetotal_rowsproperty of theRowIteratorinstead of loading all rows into memory.