diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml
index fccaa8e84..889f77dfa 100644
--- a/.github/.OwlBot.lock.yaml
+++ b/.github/.OwlBot.lock.yaml
@@ -1,4 +1,4 @@
-# Copyright 2022 Google LLC
+# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,4 +13,4 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
- digest: sha256:3bf87e47c2173d7eed42714589dc4da2c07c3268610f1e47f8e1a30decbfc7f1
+ digest: sha256:c43f1d918bcf817d337aa29ff833439494a158a0831508fda4ec75dc4c0d0320
diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml
index e54051157..8b142686c 100644
--- a/.github/.OwlBot.yaml
+++ b/.github/.OwlBot.yaml
@@ -18,9 +18,5 @@ docker:
deep-remove-regex:
- /owl-bot-staging
-deep-copy-regex:
- - source: /google/cloud/bigquery/(v.*)/.*-py/(.*)
- dest: /owl-bot-staging/$1/$2
-
begin-after-commit-hash: f2de93abafa306b2ebadf1d10d947db8bcf2bf15
diff --git a/.kokoro/continuous/prerelease-deps-3.10.cfg b/.kokoro/continuous/prerelease-deps-3.11.cfg
similarity index 77%
rename from .kokoro/continuous/prerelease-deps-3.10.cfg
rename to .kokoro/continuous/prerelease-deps-3.11.cfg
index 339980bdd..1e19f1239 100644
--- a/.kokoro/continuous/prerelease-deps-3.10.cfg
+++ b/.kokoro/continuous/prerelease-deps-3.11.cfg
@@ -3,5 +3,5 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
- value: "prerelease_deps-3.10"
+ value: "prerelease_deps-3.11"
}
diff --git a/.kokoro/presubmit/prerelease-deps-3.10.cfg b/.kokoro/presubmit/prerelease-deps-3.11.cfg
similarity index 77%
rename from .kokoro/presubmit/prerelease-deps-3.10.cfg
rename to .kokoro/presubmit/prerelease-deps-3.11.cfg
index 339980bdd..1e19f1239 100644
--- a/.kokoro/presubmit/prerelease-deps-3.10.cfg
+++ b/.kokoro/presubmit/prerelease-deps-3.11.cfg
@@ -3,5 +3,5 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
- value: "prerelease_deps-3.10"
+ value: "prerelease_deps-3.11"
}
diff --git a/.kokoro/presubmit/snippets-3.10.cfg b/.kokoro/presubmit/snippets-3.11.cfg
similarity index 81%
rename from .kokoro/presubmit/snippets-3.10.cfg
rename to .kokoro/presubmit/snippets-3.11.cfg
index dde182fb9..74af6dd07 100644
--- a/.kokoro/presubmit/snippets-3.10.cfg
+++ b/.kokoro/presubmit/snippets-3.11.cfg
@@ -3,5 +3,5 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
- value: "snippets-3.10"
+ value: "snippets-3.11"
}
diff --git a/.kokoro/presubmit/system-3.10.cfg b/.kokoro/presubmit/system-3.11.cfg
similarity index 82%
rename from .kokoro/presubmit/system-3.10.cfg
rename to .kokoro/presubmit/system-3.11.cfg
index 30956a3ab..5ff31a603 100644
--- a/.kokoro/presubmit/system-3.10.cfg
+++ b/.kokoro/presubmit/system-3.11.cfg
@@ -3,5 +3,5 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
- value: "system-3.10"
+ value: "system-3.11"
}
diff --git a/.kokoro/samples/python3.11/common.cfg b/.kokoro/samples/python3.11/common.cfg
new file mode 100644
index 000000000..f5adc8703
--- /dev/null
+++ b/.kokoro/samples/python3.11/common.cfg
@@ -0,0 +1,40 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Build logs will be here
+action {
+ define_artifacts {
+ regex: "**/*sponge_log.xml"
+ }
+}
+
+# Specify which tests to run
+env_vars: {
+ key: "RUN_TESTS_SESSION"
+ value: "py-3.11"
+}
+
+# Declare build specific Cloud project.
+env_vars: {
+ key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
+ value: "python-docs-samples-tests-311"
+}
+
+env_vars: {
+ key: "TRAMPOLINE_BUILD_FILE"
+ value: "github/python-bigquery/.kokoro/test-samples.sh"
+}
+
+# Configure the docker image for kokoro-trampoline.
+env_vars: {
+ key: "TRAMPOLINE_IMAGE"
+ value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
+}
+
+# Download secrets for samples
+gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
+
+# Download trampoline resources.
+gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
+
+# Use the trampoline script to run in docker.
+build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
\ No newline at end of file
diff --git a/.kokoro/samples/python3.11/continuous.cfg b/.kokoro/samples/python3.11/continuous.cfg
new file mode 100644
index 000000000..a1c8d9759
--- /dev/null
+++ b/.kokoro/samples/python3.11/continuous.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
\ No newline at end of file
diff --git a/.kokoro/samples/python3.11/periodic-head.cfg b/.kokoro/samples/python3.11/periodic-head.cfg
new file mode 100644
index 000000000..5aa01bab5
--- /dev/null
+++ b/.kokoro/samples/python3.11/periodic-head.cfg
@@ -0,0 +1,11 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
+
+env_vars: {
+ key: "TRAMPOLINE_BUILD_FILE"
+ value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
+}
diff --git a/.kokoro/samples/python3.11/periodic.cfg b/.kokoro/samples/python3.11/periodic.cfg
new file mode 100644
index 000000000..71cd1e597
--- /dev/null
+++ b/.kokoro/samples/python3.11/periodic.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "False"
+}
diff --git a/.kokoro/samples/python3.11/presubmit.cfg b/.kokoro/samples/python3.11/presubmit.cfg
new file mode 100644
index 000000000..a1c8d9759
--- /dev/null
+++ b/.kokoro/samples/python3.11/presubmit.cfg
@@ -0,0 +1,6 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+env_vars: {
+ key: "INSTALL_LIBRARY_FROM_SOURCE"
+ value: "True"
+}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6f0abc85..0a5b4d179 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,29 @@
[1]: https://pypi.org/project/google-cloud-bigquery/#history
+## [3.4.2](https://github.com/googleapis/python-bigquery/compare/v3.4.1...v3.4.2) (2023-01-13)
+
+
+### Bug Fixes
+
+* Add support for python 3.11 ([#1463](https://github.com/googleapis/python-bigquery/issues/1463)) ([730a1de](https://github.com/googleapis/python-bigquery/commit/730a1dec8be49df26a3d805ebd4ad185ba72170d))
+* Require grpcio >= 1.49.1 for python 3.11 ([72b25c5](https://github.com/googleapis/python-bigquery/commit/72b25c52bc4b9a92c4cb187b6230b280d4af905c))
+
+
+### Dependencies
+
+* Remove upper bound on packaging dependency ([#1440](https://github.com/googleapis/python-bigquery/issues/1440)) ([6088129](https://github.com/googleapis/python-bigquery/commit/60881296a35067e7aa025d92b2425572f10fd4ec))
+
+
+### Documentation
+
+* Create sample to write schema file from table ([#1439](https://github.com/googleapis/python-bigquery/issues/1439)) ([093cc68](https://github.com/googleapis/python-bigquery/commit/093cc6852ada29898c4a4d047fd216544ef15bba))
+* Created samples for load table and create table from schema file ([#1436](https://github.com/googleapis/python-bigquery/issues/1436)) ([8ad2e5b](https://github.com/googleapis/python-bigquery/commit/8ad2e5bc1c04bf16fffe4c8773e722b68117c916))
+* Revise create table cmek sample ([#1452](https://github.com/googleapis/python-bigquery/issues/1452)) ([57740e4](https://github.com/googleapis/python-bigquery/commit/57740e49af7418449aec73a6fdd307fcb588c655))
+* Revise get table labels code sample, add TODO to clean up snipp… ([#1464](https://github.com/googleapis/python-bigquery/issues/1464)) ([b5ccbfe](https://github.com/googleapis/python-bigquery/commit/b5ccbfe4eee91d7f481d9708084cd29d0c85e666))
+* Revise label table code samples ([#1451](https://github.com/googleapis/python-bigquery/issues/1451)) ([14ae1f2](https://github.com/googleapis/python-bigquery/commit/14ae1f20538ea00829a1325f91f5e8524234bd0c))
+* Revise sample for nested schema ([#1446](https://github.com/googleapis/python-bigquery/issues/1446)) ([a097631](https://github.com/googleapis/python-bigquery/commit/a0976318fc5ad1620a68250c3e059e2a51d4946d))
+
## [3.4.1](https://github.com/googleapis/python-bigquery/compare/v3.4.0...v3.4.1) (2022-12-09)
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index d06598b31..5dc30a1f8 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -22,7 +22,7 @@ In order to add a feature:
documentation.
- The feature must work fully on the following CPython versions:
- 3.7, 3.8, 3.9 and 3.10 on both UNIX and Windows.
+ 3.7, 3.8, 3.9, 3.10 and 3.11 on both UNIX and Windows.
- The feature must not add unnecessary dependencies (where
"unnecessary" is of course subjective, but new dependencies should
@@ -72,7 +72,7 @@ We use `nox `__ to instrument our tests.
- To run a single unit test::
- $ nox -s unit-3.10 -- -k
+ $ nox -s unit-3.11 -- -k
.. note::
@@ -225,11 +225,13 @@ We support:
- `Python 3.8`_
- `Python 3.9`_
- `Python 3.10`_
+- `Python 3.11`_
.. _Python 3.7: https://docs.python.org/3.7/
.. _Python 3.8: https://docs.python.org/3.8/
.. _Python 3.9: https://docs.python.org/3.9/
.. _Python 3.10: https://docs.python.org/3.10/
+.. _Python 3.11: https://docs.python.org/3.11/
Supported versions can be found in our ``noxfile.py`` `config`_.
diff --git a/docs/snippets.py b/docs/snippets.py
index 05e4fa378..85856eb3e 100644
--- a/docs/snippets.py
+++ b/docs/snippets.py
@@ -118,78 +118,6 @@ def test_create_client_default_credentials():
assert client is not None
-def test_create_table_nested_repeated_schema(client, to_delete):
- dataset_id = "create_table_nested_repeated_{}".format(_millis())
- project = client.project
- dataset_ref = bigquery.DatasetReference(project, dataset_id)
- dataset = bigquery.Dataset(dataset_ref)
- client.create_dataset(dataset)
- to_delete.append(dataset)
-
- # [START bigquery_nested_repeated_schema]
- # from google.cloud import bigquery
- # client = bigquery.Client()
- # project = client.project
- # dataset_ref = bigquery.DatasetReference(project, 'my_dataset')
-
- schema = [
- bigquery.SchemaField("id", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("first_name", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("last_name", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("dob", "DATE", mode="NULLABLE"),
- bigquery.SchemaField(
- "addresses",
- "RECORD",
- mode="REPEATED",
- fields=[
- bigquery.SchemaField("status", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("address", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("city", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("state", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("zip", "STRING", mode="NULLABLE"),
- bigquery.SchemaField("numberOfYears", "STRING", mode="NULLABLE"),
- ],
- ),
- ]
- table_ref = dataset_ref.table("my_table")
- table = bigquery.Table(table_ref, schema=schema)
- table = client.create_table(table) # API request
-
- print("Created table {}".format(table.full_table_id))
- # [END bigquery_nested_repeated_schema]
-
-
-def test_create_table_cmek(client, to_delete):
- dataset_id = "create_table_cmek_{}".format(_millis())
- project = client.project
- dataset_ref = bigquery.DatasetReference(project, dataset_id)
- dataset = bigquery.Dataset(dataset_ref)
- client.create_dataset(dataset)
- to_delete.append(dataset)
-
- # [START bigquery_create_table_cmek]
- # from google.cloud import bigquery
- # client = bigquery.Client()
- # dataset_id = 'my_dataset'
-
- table_ref = dataset.table("my_table")
- table = bigquery.Table(table_ref)
-
- # Set the encryption key to use for the table.
- # TODO: Replace this key with a key you have created in Cloud KMS.
- kms_key_name = "projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}".format(
- "cloud-samples-tests", "us", "test", "test"
- )
- table.encryption_configuration = bigquery.EncryptionConfiguration(
- kms_key_name=kms_key_name
- )
-
- table = client.create_table(table) # API request
-
- assert table.encryption_configuration.kms_key_name == kms_key_name
- # [END bigquery_create_table_cmek]
-
-
def test_create_partitioned_table(client, to_delete):
dataset_id = "create_table_partitioned_{}".format(_millis())
project = client.project
@@ -246,24 +174,12 @@ def test_manage_table_labels(client, to_delete):
to_delete.append(dataset)
table = bigquery.Table(dataset.table(table_id), schema=SCHEMA)
- table = client.create_table(table)
- # [START bigquery_label_table]
- # from google.cloud import bigquery
- # client = bigquery.Client()
- # project = client.project
- # dataset_ref = bigquery.DatasetReference(project, dataset_id)
- # table_ref = dataset_ref.table('my_table')
- # table = client.get_table(table_ref) # API request
-
- assert table.labels == {}
labels = {"color": "green"}
table.labels = labels
+ table = client.create_table(table)
- table = client.update_table(table, ["labels"]) # API request
-
- assert table.labels == labels
- # [END bigquery_label_table]
+ # TODO(Mattix23): After code sample is updated from cloud.google.com delete this
# [START bigquery_get_table_labels]
# from google.cloud import bigquery
diff --git a/docs/usage/encryption.rst b/docs/usage/encryption.rst
index 6652f0565..3e6d5aacc 100644
--- a/docs/usage/encryption.rst
+++ b/docs/usage/encryption.rst
@@ -10,7 +10,7 @@ in the BigQuery documentation for more details.
Create a new table, using a customer-managed encryption key from
Cloud KMS to encrypt it.
-.. literalinclude:: ../snippets.py
+.. literalinclude:: ../samples/snippets/create_table_cmek.py
:language: python
:dedent: 4
:start-after: [START bigquery_create_table_cmek]
diff --git a/google/__init__.py b/google/__init__.py
index 8fcc60e2b..8e60d8439 100644
--- a/google/__init__.py
+++ b/google/__init__.py
@@ -21,4 +21,4 @@
except ImportError:
import pkgutil
- __path__ = pkgutil.extend_path(__path__, __name__)
+ __path__ = pkgutil.extend_path(__path__, __name__) # type: ignore
diff --git a/google/cloud/bigquery/opentelemetry_tracing.py b/google/cloud/bigquery/opentelemetry_tracing.py
index 2345fd1bb..3d0a66ba8 100644
--- a/google/cloud/bigquery/opentelemetry_tracing.py
+++ b/google/cloud/bigquery/opentelemetry_tracing.py
@@ -18,9 +18,9 @@
logger = logging.getLogger(__name__)
try:
- from opentelemetry import trace
- from opentelemetry.instrumentation.utils import http_status_to_status_code
- from opentelemetry.trace.status import Status
+ from opentelemetry import trace # type: ignore
+ from opentelemetry.instrumentation.utils import http_status_to_status_code # type: ignore
+ from opentelemetry.trace.status import Status # type: ignore
HAS_OPENTELEMETRY = True
_warned_telemetry = True
diff --git a/google/cloud/bigquery/version.py b/google/cloud/bigquery/version.py
index 71133df01..d38bb4619 100644
--- a/google/cloud/bigquery/version.py
+++ b/google/cloud/bigquery/version.py
@@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-__version__ = "3.4.1"
+__version__ = "3.4.2"
diff --git a/noxfile.py b/noxfile.py
index a91e60a5f..f6283abf9 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -36,8 +36,8 @@
)
DEFAULT_PYTHON_VERSION = "3.8"
-SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.10"]
-UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
+SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.11"]
+UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
@@ -80,7 +80,7 @@ def default(session, install_extras=True):
constraints_path,
)
- if install_extras and session.python == "3.10":
+ if install_extras and session.python == "3.11":
install_target = ".[bqstorage,ipywidgets,pandas,tqdm,opentelemetry]"
elif install_extras:
install_target = ".[all]"
@@ -185,7 +185,7 @@ def system(session):
# Data Catalog needed for the column ACL test with a real Policy Tag.
session.install("google-cloud-datacatalog", "-c", constraints_path)
- if session.python == "3.10":
+ if session.python == "3.11":
extras = "[bqstorage,ipywidgets,pandas,tqdm,opentelemetry]"
else:
extras = "[all]"
@@ -200,12 +200,22 @@ def mypy_samples(session):
"""Run type checks with mypy."""
session.install("-e", ".[all]")
- session.install("ipython", "pytest")
+ session.install("pytest")
+ for requirements_path in CURRENT_DIRECTORY.glob("samples/*/requirements.txt"):
+ session.install("-r", requirements_path)
session.install(MYPY_VERSION)
# Just install the dependencies' type info directly, since "mypy --install-types"
# might require an additional pass.
- session.install("types-mock", "types-pytz")
+ session.install(
+ "types-mock",
+ "types-pytz",
+ "types-protobuf",
+ "types-python-dateutil",
+ "types-requests",
+ "types-setuptools",
+ )
+
session.install("typing-extensions") # for TypedDict in pre-3.8 Python versions
session.run(
@@ -234,7 +244,7 @@ def snippets(session):
session.install("google-cloud-storage", "-c", constraints_path)
session.install("grpcio", "-c", constraints_path)
- if session.python == "3.10":
+ if session.python == "3.11":
extras = "[bqstorage,ipywidgets,pandas,tqdm,opentelemetry]"
else:
extras = "[all]"
@@ -290,6 +300,11 @@ def prerelease_deps(session):
"--upgrade",
"pandas",
)
+ session.install(
+ "--pre",
+ "--upgrade",
+ "git+https://github.com/pypa/packaging.git",
+ )
session.install(
"--pre",
diff --git a/samples/geography/noxfile.py b/samples/geography/noxfile.py
index e8283c38d..1224cbe21 100644
--- a/samples/geography/noxfile.py
+++ b/samples/geography/noxfile.py
@@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
# DO NOT EDIT - automatically generated.
# All versions used to test samples.
-ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
+ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]
# Any default versions that should be ignored.
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
diff --git a/samples/geography/requirements-test.txt b/samples/geography/requirements-test.txt
index 6f722c66e..1e6b7c5ea 100644
--- a/samples/geography/requirements-test.txt
+++ b/samples/geography/requirements-test.txt
@@ -1,2 +1,2 @@
-pytest==7.1.3
-mock==4.0.3
+pytest==7.2.0
+mock==5.0.1
diff --git a/samples/geography/requirements.txt b/samples/geography/requirements.txt
index 798de6bb5..0f475e0fd 100644
--- a/samples/geography/requirements.txt
+++ b/samples/geography/requirements.txt
@@ -1,45 +1,45 @@
-attrs==22.1.0
-certifi==2022.9.24
+attrs==22.2.0
+certifi==2022.12.7
cffi==1.15.1
-charset-normalizer==2.1.1
+charset-normalizer==3.0.1
click==8.1.3
click-plugins==1.1.1
cligj==0.7.2
dataclasses==0.8; python_version < '3.7'
-db-dtypes==1.0.4
+db-dtypes==1.0.5
Fiona==1.8.22
geojson==2.5.0
geopandas===0.10.2; python_version == '3.7'
-geopandas==0.12.1; python_version >= '3.8'
-google-api-core==2.10.2
-google-auth==2.13.0
-google-cloud-bigquery==3.3.5
-google-cloud-bigquery-storage==2.16.2
+geopandas==0.12.2; python_version >= '3.8'
+google-api-core==2.11.0
+google-auth==2.16.0
+google-cloud-bigquery==3.4.1
+google-cloud-bigquery-storage==2.18.0
google-cloud-core==2.3.2
google-crc32c==1.5.0
google-resumable-media==2.4.0
-googleapis-common-protos==1.56.4
-grpcio==1.50.0
+googleapis-common-protos==1.58.0
+grpcio==1.51.1
idna==3.4
-libcst==0.4.7
+libcst==0.4.9
munch==2.5.0
mypy-extensions==0.4.3
packaging==21.3
pandas===1.3.5; python_version == '3.7'
-pandas==1.5.1; python_version >= '3.8'
-proto-plus==1.22.1
-pyarrow==9.0.0
+pandas==1.5.2; python_version >= '3.8'
+proto-plus==1.22.2
+pyarrow==10.0.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pyparsing==3.0.9
python-dateutil==2.8.2
-pytz==2022.5
+pytz==2022.7
PyYAML==6.0
-requests==2.28.1
+requests==2.28.2
rsa==4.9
-Shapely==1.8.5.post1
+Shapely==2.0.0
six==1.16.0
typing-extensions==4.4.0
typing-inspect==0.8.0
-urllib3==1.26.12
+urllib3==1.26.14
diff --git a/samples/magics/noxfile.py b/samples/magics/noxfile.py
index e8283c38d..1224cbe21 100644
--- a/samples/magics/noxfile.py
+++ b/samples/magics/noxfile.py
@@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
# DO NOT EDIT - automatically generated.
# All versions used to test samples.
-ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
+ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]
# Any default versions that should be ignored.
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
diff --git a/samples/magics/requirements-test.txt b/samples/magics/requirements-test.txt
index 7902c72ef..56aa0f432 100644
--- a/samples/magics/requirements-test.txt
+++ b/samples/magics/requirements-test.txt
@@ -1,3 +1,3 @@
google-cloud-testutils==1.3.3
-pytest==7.1.3
-mock==4.0.3
+pytest==7.2.0
+mock==5.0.1
diff --git a/samples/magics/requirements.txt b/samples/magics/requirements.txt
index bdd026ce5..463829c8f 100644
--- a/samples/magics/requirements.txt
+++ b/samples/magics/requirements.txt
@@ -1,15 +1,15 @@
-db-dtypes==1.0.4
-google-cloud-bigquery-storage==2.16.2
-google-auth-oauthlib==0.5.3
-grpcio==1.50.0
-ipywidgets==8.0.2
+db-dtypes==1.0.5
+google-cloud-bigquery-storage==2.18.0
+google-auth-oauthlib==0.8.0
+grpcio==1.51.1
+ipywidgets==8.0.4
ipython===7.31.1; python_version == '3.7'
ipython===8.0.1; python_version == '3.8'
-ipython==8.5.0; python_version >= '3.9'
+ipython==8.8.0; python_version >= '3.9'
matplotlib===3.5.3; python_version == '3.7'
-matplotlib==3.6.1; python_version >= '3.8'
+matplotlib==3.6.3; python_version >= '3.8'
pandas===1.3.5; python_version == '3.7'
-pandas==1.5.1; python_version >= '3.8'
-pyarrow==9.0.0
-pytz==2022.5
+pandas==1.5.2; python_version >= '3.8'
+pyarrow==10.0.1
+pytz==2022.7
typing-extensions==4.4.0
diff --git a/samples/mypy.ini b/samples/mypy.ini
index 29757e47d..3f7eb6647 100644
--- a/samples/mypy.ini
+++ b/samples/mypy.ini
@@ -2,7 +2,6 @@
# Should match DEFAULT_PYTHON_VERSION from root noxfile.py
python_version = 3.8
exclude = noxfile\.py
-strict = True
warn_unused_configs = True
[mypy-google.auth,google.oauth2,geojson,google_auth_oauthlib,IPython.*]
diff --git a/samples/snippets/create_table_cmek.py b/samples/snippets/create_table_cmek.py
new file mode 100644
index 000000000..011c56d4e
--- /dev/null
+++ b/samples/snippets/create_table_cmek.py
@@ -0,0 +1,46 @@
+# Copyright 2022 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 create_table_cmek(table_id: str, kms_key_name: str) -> None:
+ orig_table_id = table_id
+ orig_key_name = kms_key_name
+ # [START bigquery_create_table_cmek]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table_name"
+
+ # Set the encryption key to use for the table.
+ # TODO: Replace this key with a key you have created in Cloud KMS.
+ kms_key_name = "projects/your-project/locations/us/keyRings/test/cryptoKeys/test"
+
+ # [END bigquery_create_table_cmek]
+
+ table_id = orig_table_id
+ kms_key_name = orig_key_name
+
+ # [START bigquery_create_table_cmek]
+ table = bigquery.Table(table_id)
+ table.encryption_configuration = bigquery.EncryptionConfiguration(
+ kms_key_name=kms_key_name
+ )
+ table = client.create_table(table) # API request
+
+ print(f"Created {table_id}.")
+ print(f"Key: {table.encryption_configuration.kms_key_name}.")
+
+ # [END bigquery_create_table_cmek]
diff --git a/samples/snippets/create_table_cmek_test.py b/samples/snippets/create_table_cmek_test.py
new file mode 100644
index 000000000..429baf3fd
--- /dev/null
+++ b/samples/snippets/create_table_cmek_test.py
@@ -0,0 +1,37 @@
+# Copyright 2022 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
+
+import create_table_cmek
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_create_table(
+ capsys: "pytest.CaptureFixture[str]",
+ random_table_id: str,
+) -> None:
+
+ kms_key_name = (
+ "projects/cloud-samples-tests/locations/us/keyRings/test/cryptoKeys/test"
+ )
+
+ create_table_cmek.create_table_cmek(random_table_id, kms_key_name)
+
+ out, _ = capsys.readouterr()
+ assert "Created" in out
+ assert random_table_id in out
+ assert kms_key_name in out
diff --git a/samples/snippets/create_table_schema_from_json.py b/samples/snippets/create_table_schema_from_json.py
new file mode 100644
index 000000000..b866e2ebe
--- /dev/null
+++ b/samples/snippets/create_table_schema_from_json.py
@@ -0,0 +1,42 @@
+# Copyright 2022 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 pathlib
+
+
+def create_table(table_id: str) -> None:
+ orig_table_id = table_id
+ current_directory = pathlib.Path(__file__).parent
+ orig_schema_path = str(current_directory / "schema.json")
+ # [START bigquery_schema_file_create]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table_name"
+ # TODO(dev): Change schema_path variable to the path of your schema file.
+ schema_path = "path/to/schema.json"
+ # [END bigquery_schema_file_create]
+ table_id = orig_table_id
+ schema_path = orig_schema_path
+
+ # [START bigquery_schema_file_create]
+ # To load a schema file use the schema_from_json method.
+ schema = client.schema_from_json(schema_path)
+
+ table = bigquery.Table(table_id, schema=schema)
+ table = client.create_table(table) # API request
+ print(f"Created table {table_id}.")
+ # [END bigquery_schema_file_create]
diff --git a/samples/snippets/create_table_schema_from_json_test.py b/samples/snippets/create_table_schema_from_json_test.py
new file mode 100644
index 000000000..e99b92672
--- /dev/null
+++ b/samples/snippets/create_table_schema_from_json_test.py
@@ -0,0 +1,32 @@
+# Copyright 2022 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
+
+import create_table_schema_from_json
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_create_table(
+ capsys: "pytest.CaptureFixture[str]",
+ random_table_id: str,
+) -> None:
+
+ create_table_schema_from_json.create_table(random_table_id)
+
+ out, _ = capsys.readouterr()
+ assert "Created" in out
+ assert random_table_id in out
diff --git a/samples/snippets/dataset_access_test.py b/samples/snippets/dataset_access_test.py
index 4d1a70eb1..cc6a9af61 100644
--- a/samples/snippets/dataset_access_test.py
+++ b/samples/snippets/dataset_access_test.py
@@ -18,8 +18,8 @@
import update_dataset_access
if typing.TYPE_CHECKING:
- import pytest
from google.cloud import bigquery
+ import pytest
def test_dataset_access_permissions(
diff --git a/samples/snippets/delete_job.py b/samples/snippets/delete_job.py
index 7c8640baf..2aeb53849 100644
--- a/samples/snippets/delete_job.py
+++ b/samples/snippets/delete_job.py
@@ -17,8 +17,8 @@ def delete_job_metadata(job_id: str, location: str) -> None:
orig_job_id = job_id
orig_location = location
# [START bigquery_delete_job]
- from google.cloud import bigquery
from google.api_core import exceptions
+ from google.cloud import bigquery
# TODO(developer): Set the job ID to the ID of the job whose metadata you
# wish to delete.
diff --git a/samples/snippets/get_table_labels.py b/samples/snippets/get_table_labels.py
new file mode 100644
index 000000000..8cfbd4ee2
--- /dev/null
+++ b/samples/snippets/get_table_labels.py
@@ -0,0 +1,39 @@
+# Copyright 2022 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 get_table_labels(table_id: str) -> None:
+ orig_table_id = table_id
+ # [START bigquery_get_table_labels]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table_name"
+
+ # [END bigquery_get_table_labels]
+ table_id = orig_table_id
+
+ # [START bigquery_get_table_labels]
+ table = client.get_table(table_id) # API Request
+
+ # View table labels
+ print(f"Table ID: {table_id}.")
+ if table.labels:
+ for label, value in table.labels.items():
+ print(f"\t{label}: {value}")
+ else:
+ print("\tTable has no labels defined.")
+ # [END bigquery_get_table_labels]
diff --git a/samples/snippets/get_table_labels_test.py b/samples/snippets/get_table_labels_test.py
new file mode 100644
index 000000000..f922e728c
--- /dev/null
+++ b/samples/snippets/get_table_labels_test.py
@@ -0,0 +1,50 @@
+# Copyright 2022 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
+
+from google.cloud import bigquery
+
+import get_table_labels
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_get_table_labels(
+ capsys: "pytest.CaptureFixture[str]",
+ table_id: str,
+ bigquery_client: bigquery.Client,
+) -> None:
+ table = bigquery_client.get_table(table_id)
+ table.labels = {"color": "green"}
+ bigquery_client.update_table(table, ["labels"])
+
+ get_table_labels.get_table_labels(table_id)
+
+ out, _ = capsys.readouterr()
+ assert table_id in out
+ assert "color" in out
+
+
+def test_get_table_labels_no_label(
+ capsys: "pytest.CaptureFixture[str]",
+ table_id: str,
+) -> None:
+
+ get_table_labels.get_table_labels(table_id)
+
+ out, _ = capsys.readouterr()
+ assert "no labels defined" in out
+ assert table_id in out
diff --git a/samples/snippets/get_table_make_schema.py b/samples/snippets/get_table_make_schema.py
new file mode 100644
index 000000000..f870b42de
--- /dev/null
+++ b/samples/snippets/get_table_make_schema.py
@@ -0,0 +1,47 @@
+# Copyright 2022 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 get_table_make_schema(table_id: str, schema_path: str) -> None:
+ orig_table_id = table_id
+ orig_schema_path = schema_path
+ # [START bigquery_schema_file_get]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change the table_id variable to the full name of the
+ # table you want to get schema from.
+ table_id = "your-project.your_dataset.your_table_name"
+
+ # TODO(dev): Change schema_path variable to the path
+ # of your schema file.
+ schema_path = "path/to/schema.json"
+ # [END bigquery_schema_file_get]
+ table_id = orig_table_id
+ schema_path = orig_schema_path
+ # [START bigquery_schema_file_get]
+ table = client.get_table(table_id) # Make an API request.
+
+ # Write a schema file to schema_path with the schema_to_json method.
+ client.schema_to_json(table.schema, schema_path)
+
+ with open(schema_path, "r", encoding="utf-8") as schema_file:
+ schema_contents = schema_file.read()
+
+ # View table properties
+ print(f"Got table '{table.project}.{table.dataset_id}.{table.table_id}'.")
+ print(f"Table schema: {schema_contents}")
+
+ # [END bigquery_schema_file_get]
diff --git a/samples/snippets/get_table_make_schema_test.py b/samples/snippets/get_table_make_schema_test.py
new file mode 100644
index 000000000..424f16e39
--- /dev/null
+++ b/samples/snippets/get_table_make_schema_test.py
@@ -0,0 +1,36 @@
+# Copyright 2022 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
+
+import get_table_make_schema
+
+if typing.TYPE_CHECKING:
+ import pathlib
+
+ import pytest
+
+
+def test_get_table_make_schema(
+ capsys: "pytest.CaptureFixture[str]",
+ table_id: str,
+ tmp_path: "pathlib.Path",
+) -> None:
+ schema_path = str(tmp_path / "test_schema.json")
+
+ get_table_make_schema.get_table_make_schema(table_id, schema_path)
+
+ out, _ = capsys.readouterr()
+ assert "Got table" in out
+ assert table_id in out
diff --git a/samples/snippets/label_table.py b/samples/snippets/label_table.py
new file mode 100644
index 000000000..5fce08d62
--- /dev/null
+++ b/samples/snippets/label_table.py
@@ -0,0 +1,37 @@
+# Copyright 2022 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 label_table(table_id: str) -> None:
+ orig_table_id = table_id
+ # [START bigquery_label_table]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table_name"
+
+ # [END bigquery_label_table]
+ table_id = orig_table_id
+ # [START bigquery_label_table]
+ table = client.get_table(table_id) # API request
+
+ labels = {"color": "green"}
+ table.labels = labels
+
+ table = client.update_table(table, ["labels"]) # API request
+
+ print(f"Added {table.labels} to {table_id}.")
+ # [END bigquery_label_table]
diff --git a/samples/snippets/label_table_test.py b/samples/snippets/label_table_test.py
new file mode 100644
index 000000000..a77fb4b75
--- /dev/null
+++ b/samples/snippets/label_table_test.py
@@ -0,0 +1,32 @@
+# Copyright 2022 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
+
+import label_table
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_label_table(
+ capsys: "pytest.CaptureFixture[str]",
+ table_id: str,
+) -> None:
+
+ label_table.label_table(table_id)
+
+ out, _ = capsys.readouterr()
+ assert "color" in out
+ assert table_id in out
diff --git a/samples/snippets/load_table_schema_from_json.py b/samples/snippets/load_table_schema_from_json.py
new file mode 100644
index 000000000..3f1f85430
--- /dev/null
+++ b/samples/snippets/load_table_schema_from_json.py
@@ -0,0 +1,60 @@
+# Copyright 2022 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 pathlib
+
+
+def load_table(table_id: str) -> None:
+ orig_uri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv"
+ orig_table_id = table_id
+ current_directory = pathlib.Path(__file__).parent
+ orig_schema_path = str(current_directory / "schema_us_states.json")
+ # [START bigquery_schema_file_load]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change uri variable to the path of your data file.
+ uri = "gs://your-bucket/path/to/your-file.csv"
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table"
+ # TODO(dev): Change schema_path variable to the path of your schema file.
+ schema_path = "path/to/schema.json"
+ # [END bigquery_schema_file_load]
+ uri = orig_uri
+ table_id = orig_table_id
+ schema_path = orig_schema_path
+ # [START bigquery_schema_file_load]
+ # To load a schema file use the schema_from_json method.
+ schema = client.schema_from_json(schema_path)
+
+ job_config = bigquery.LoadJobConfig(
+ # To use the schema you loaded pass it into the
+ # LoadJobConfig constructor.
+ schema=schema,
+ skip_leading_rows=1,
+ )
+
+ # Pass the job_config object to the load_table_from_file,
+ # load_table_from_json, or load_table_from_uri method
+ # to use the schema on a new table.
+ load_job = client.load_table_from_uri(
+ uri, table_id, job_config=job_config
+ ) # Make an API request.
+
+ load_job.result() # Waits for the job to complete.
+
+ destination_table = client.get_table(table_id) # Make an API request.
+ print(f"Loaded {destination_table.num_rows} rows to {table_id}.")
+ # [END bigquery_schema_file_load]
diff --git a/samples/snippets/load_table_schema_from_json_test.py b/samples/snippets/load_table_schema_from_json_test.py
new file mode 100644
index 000000000..267a6786c
--- /dev/null
+++ b/samples/snippets/load_table_schema_from_json_test.py
@@ -0,0 +1,32 @@
+# Copyright 2022 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
+
+import load_table_schema_from_json
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_load_table(
+ capsys: "pytest.CaptureFixture[str]",
+ random_table_id: str,
+) -> None:
+
+ load_table_schema_from_json.load_table(random_table_id)
+
+ out, _ = capsys.readouterr()
+ assert "Loaded" in out
+ assert random_table_id in out
diff --git a/samples/snippets/materialized_view.py b/samples/snippets/materialized_view.py
index adb3688a4..a47ee5b81 100644
--- a/samples/snippets/materialized_view.py
+++ b/samples/snippets/materialized_view.py
@@ -60,6 +60,7 @@ def update_materialized_view(
# [START bigquery_update_materialized_view]
import datetime
+
from google.cloud import bigquery
bigquery_client = bigquery.Client()
diff --git a/samples/snippets/nested_repeated_schema.py b/samples/snippets/nested_repeated_schema.py
new file mode 100644
index 000000000..5d55860cc
--- /dev/null
+++ b/samples/snippets/nested_repeated_schema.py
@@ -0,0 +1,54 @@
+# Copyright 2022 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 nested_schema(table_id: str) -> None:
+ orig_table_id = table_id
+ # [START bigquery_nested_repeated_schema]
+ from google.cloud import bigquery
+
+ client = bigquery.Client()
+
+ # TODO(dev): Change table_id to the full name of the table you want to create.
+ table_id = "your-project.your_dataset.your_table_name"
+
+ schema = [
+ bigquery.SchemaField("id", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("first_name", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("last_name", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("dob", "DATE", mode="NULLABLE"),
+ bigquery.SchemaField(
+ "addresses",
+ "RECORD",
+ mode="REPEATED",
+ fields=[
+ bigquery.SchemaField("status", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("address", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("city", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("state", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("zip", "STRING", mode="NULLABLE"),
+ bigquery.SchemaField("numberOfYears", "STRING", mode="NULLABLE"),
+ ],
+ ),
+ ]
+ # [END bigquery_nested_repeated_schema]
+
+ table_id = orig_table_id
+
+ # [START bigquery_nested_repeated_schema]
+ table = bigquery.Table(table_id, schema=schema)
+ table = client.create_table(table) # API request
+
+ print(f"Created table {table.project}.{table.dataset_id}.{table.table_id}.")
+ # [END bigquery_nested_repeated_schema]
diff --git a/samples/snippets/nested_repeated_schema_test.py b/samples/snippets/nested_repeated_schema_test.py
new file mode 100644
index 000000000..0386fc8fb
--- /dev/null
+++ b/samples/snippets/nested_repeated_schema_test.py
@@ -0,0 +1,32 @@
+# Copyright 2022 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
+
+import nested_repeated_schema
+
+if typing.TYPE_CHECKING:
+ import pytest
+
+
+def test_create_table(
+ capsys: "pytest.CaptureFixture[str]",
+ random_table_id: str,
+) -> None:
+
+ nested_repeated_schema.nested_schema(random_table_id)
+
+ out, _ = capsys.readouterr()
+ assert "Created" in out
+ assert random_table_id in out
diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py
index e8283c38d..1224cbe21 100644
--- a/samples/snippets/noxfile.py
+++ b/samples/snippets/noxfile.py
@@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
# DO NOT EDIT - automatically generated.
# All versions used to test samples.
-ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
+ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]
# Any default versions that should be ignored.
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
diff --git a/samples/snippets/quickstart_test.py b/samples/snippets/quickstart_test.py
index b0bad5ee5..610c63c3b 100644
--- a/samples/snippets/quickstart_test.py
+++ b/samples/snippets/quickstart_test.py
@@ -20,7 +20,6 @@
import quickstart
-
# Must match the dataset listed in quickstart.py (there's no easy way to
# extract this).
DATASET_ID = "my_new_dataset"
diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt
index 7902c72ef..56aa0f432 100644
--- a/samples/snippets/requirements-test.txt
+++ b/samples/snippets/requirements-test.txt
@@ -1,3 +1,3 @@
google-cloud-testutils==1.3.3
-pytest==7.1.3
-mock==4.0.3
+pytest==7.2.0
+mock==5.0.1
diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt
index ebf892279..1ecf3fc45 100644
--- a/samples/snippets/requirements.txt
+++ b/samples/snippets/requirements.txt
@@ -1,16 +1,16 @@
-db-dtypes==1.0.4
-google-cloud-bigquery==3.3.5
-google-cloud-bigquery-storage==2.16.2
-google-auth-oauthlib==0.5.3
-grpcio==1.50.0
-ipywidgets==8.0.2
+db-dtypes==1.0.5
+google-cloud-bigquery==3.4.1
+google-cloud-bigquery-storage==2.18.0
+google-auth-oauthlib==0.8.0
+grpcio==1.51.1
+ipywidgets==8.0.4
ipython===7.31.1; python_version == '3.7'
ipython===8.0.1; python_version == '3.8'
-ipython==8.5.0; python_version >= '3.9'
+ipython==8.8.0; python_version >= '3.9'
matplotlib===3.5.3; python_version == '3.7'
-matplotlib==3.6.1; python_version >= '3.8'
+matplotlib==3.6.3; python_version >= '3.8'
pandas===1.3.5; python_version == '3.7'
-pandas==1.5.1; python_version >= '3.8'
-pyarrow==9.0.0
-pytz==2022.5
+pandas==1.5.2; python_version >= '3.8'
+pyarrow==10.0.1
+pytz==2022.7
typing-extensions==4.4.0
diff --git a/samples/snippets/schema.json b/samples/snippets/schema.json
new file mode 100644
index 000000000..bd2164dad
--- /dev/null
+++ b/samples/snippets/schema.json
@@ -0,0 +1,20 @@
+[
+ {
+ "name": "qtr",
+ "type": "STRING",
+ "mode": "REQUIRED",
+ "description": "quarter"
+ },
+ {
+ "name": "rep",
+ "type": "STRING",
+ "mode": "NULLABLE",
+ "description": "sales representative"
+ },
+ {
+ "name": "sales",
+ "type": "FLOAT",
+ "mode": "NULLABLE",
+ "defaultValueExpression": "2.55"
+ }
+]
diff --git a/samples/snippets/schema_us_states.json b/samples/snippets/schema_us_states.json
new file mode 100644
index 000000000..7f2ccc277
--- /dev/null
+++ b/samples/snippets/schema_us_states.json
@@ -0,0 +1,12 @@
+[
+ {
+ "name": "name",
+ "type": "STRING",
+ "mode": "NULLABLE"
+ },
+ {
+ "name": "post_abbr",
+ "type": "STRING",
+ "mode": "NULLABLE"
+ }
+]
diff --git a/samples/snippets/user_credentials_test.py b/samples/snippets/user_credentials_test.py
index e2794e83b..df8a6354d 100644
--- a/samples/snippets/user_credentials_test.py
+++ b/samples/snippets/user_credentials_test.py
@@ -21,7 +21,6 @@
from user_credentials import main
-
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
MockType = Union[mock.mock.MagicMock, mock.mock.AsyncMock]
diff --git a/setup.py b/setup.py
index 9e1bfbbce..81cb2e5db 100644
--- a/setup.py
+++ b/setup.py
@@ -30,6 +30,7 @@
release_status = "Development Status :: 5 - Production/Stable"
dependencies = [
"grpcio >= 1.47.0, < 2.0dev", # https://github.com/googleapis/python-bigquery/issues/1262
+ "grpcio >= 1.49.1, < 2.0dev; python_version>='3.11'",
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
# Until this issue is closed
# https://github.com/googleapis/google-cloud-python/issues/10566
@@ -40,7 +41,7 @@
# https://github.com/googleapis/google-cloud-python/issues/10566
"google-cloud-core >= 1.4.1, <3.0.0dev",
"google-resumable-media >= 0.6.0, < 3.0dev",
- "packaging >= 14.3, <22.0.0dev",
+ "packaging >= 20.0.0",
"protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", # For the legacy proto-based types.
"python-dateutil >= 2.7.2, <3.0dev",
"requests >= 2.21.0, < 3.0.0dev",
@@ -58,6 +59,7 @@
# grpc.Channel.close() method isn't added until 1.32.0.
# https://github.com/grpc/grpc/pull/15254
"grpcio >= 1.47.0, < 2.0dev",
+ "grpcio >= 1.49.1, < 2.0dev; python_version>='3.11'",
pyarrow_dependency,
],
"pandas": [
@@ -129,6 +131,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
"Operating System :: OS Independent",
"Topic :: Internet",
],
diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt
index 149d6c496..3701c7343 100644
--- a/testing/constraints-3.7.txt
+++ b/testing/constraints-3.7.txt
@@ -17,6 +17,7 @@ ipython==7.0.1
opentelemetry-api==1.1.0
opentelemetry-instrumentation==0.20b0
opentelemetry-sdk==1.1.0
+packaging==20.0.0
pandas==1.1.0
proto-plus==1.22.0
protobuf==3.19.5
diff --git a/tests/unit/line_arg_parser/test_parser.py b/tests/unit/line_arg_parser/test_parser.py
index 3f9e9ff41..b170d536a 100644
--- a/tests/unit/line_arg_parser/test_parser.py
+++ b/tests/unit/line_arg_parser/test_parser.py
@@ -44,7 +44,7 @@ def test_consume_unexpected_eol(parser_class):
fake_lexer = [Token(TokenType.EOL, lexeme="", pos=0)]
parser = parser_class(fake_lexer)
- with pytest.raises(ParseError, match=r"Unexpected end of input.*expected COLON.*"):
+ with pytest.raises(ParseError, match=r"Unexpected end of input.*expected.*COLON.*"):
parser.consume(TokenType.COLON)