sqlalchemy-bigquery 1.17.3__tar.gz → 1.19.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlalchemy_bigquery-1.17.3/sqlalchemy_bigquery.egg-info → sqlalchemy_bigquery-1.19.0}/PKG-INFO +40 -20
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/README.rst +28 -8
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/pyproject.toml +6 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/setup.py +6 -6
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/__init__.py +3 -17
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/_helpers.py +45 -1
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/_struct.py +5 -6
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/base.py +329 -28
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/geography.py +27 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/version.py +1 -1
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0/sqlalchemy_bigquery.egg-info}/PKG-INFO +40 -20
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery.egg-info/SOURCES.txt +2 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery.egg-info/requires.txt +8 -8
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py +18 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test__struct.py +2 -8
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test_helpers.py +15 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test_sqlalchemy_bigquery.py +61 -31
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test__struct.py +61 -14
- sqlalchemy_bigquery-1.19.0/tests/unit/test_check_compiler_safety.py +658 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_compiler.py +446 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_engine.py +89 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_geography.py +40 -2
- sqlalchemy_bigquery-1.19.0/tests/unit/test_like_reescape.py +181 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_sqlalchemy_bigquery.py +140 -0
- sqlalchemy_bigquery-1.19.0/tests/unit/test_universe_domain.py +221 -0
- sqlalchemy_bigquery-1.17.3/tests/unit/test_like_reescape.py +0 -47
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/AUTHORS +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/LICENSE +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/MANIFEST.in +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/setup.cfg +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/_types.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/parse_url.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/provision.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery/requirements.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery.egg-info/entry_points.txt +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/sqlalchemy_bigquery.egg-info/top_level.txt +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/conftest.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/sqlalchemy_dialect_compliance/README.rst +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/sqlalchemy_dialect_compliance/conftest.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/conftest.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/data/sample.json +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/data/sample_one_row.json +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/data/schema.json +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test_alembic.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test_geography.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/system/test_sqlalchemy_bigquery_remote.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/conftest.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/fauxdbi.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test__types.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_alembic.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_catalog_functions.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_comments.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_compliance.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_dialect_types.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_helpers.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_parse_url.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_provision.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_select.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_table_options.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_version.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/tests/unit/test_view.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/py.typed +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/AUTHORS +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/LICENSE +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.3 → sqlalchemy_bigquery-1.19.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/base.py +0 -0
{sqlalchemy_bigquery-1.17.3/sqlalchemy_bigquery.egg-info → sqlalchemy_bigquery-1.19.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.19.0
|
|
4
4
|
Summary: SQLAlchemy dialect for BigQuery
|
|
5
5
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/sqlalchemy-bigquery
|
|
6
6
|
Author: The Sqlalchemy-Bigquery Authors
|
|
@@ -12,28 +12,28 @@ Classifier: Intended Audience :: Developers
|
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
13
|
Classifier: Programming Language :: Python
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
20
|
Classifier: Operating System :: OS Independent
|
|
21
21
|
Classifier: Topic :: Database :: Front-Ends
|
|
22
22
|
Obsoletes: pybigquery
|
|
23
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
24
|
Description-Content-Type: text/x-rst
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
License-File: AUTHORS
|
|
27
27
|
Requires-Dist: google-api-core<3.0.0,>=2.25.0
|
|
28
28
|
Requires-Dist: google-auth<3.0.0,>=2.14.1
|
|
29
|
-
Requires-Dist: google-cloud-bigquery<4.0.0,>=3.20.
|
|
29
|
+
Requires-Dist: google-cloud-bigquery<4.0.0,>=3.20.1
|
|
30
30
|
Requires-Dist: packaging
|
|
31
|
-
Requires-Dist: sqlalchemy<3.0.0,>=1.4.
|
|
31
|
+
Requires-Dist: sqlalchemy<3.0.0,>=1.4.41
|
|
32
32
|
Provides-Extra: geography
|
|
33
33
|
Requires-Dist: GeoAlchemy2; extra == "geography"
|
|
34
34
|
Requires-Dist: shapely; extra == "geography"
|
|
35
35
|
Provides-Extra: alembic
|
|
36
|
-
Requires-Dist: alembic; extra == "alembic"
|
|
36
|
+
Requires-Dist: alembic>=1.7.7; extra == "alembic"
|
|
37
37
|
Provides-Extra: tests
|
|
38
38
|
Requires-Dist: packaging; extra == "tests"
|
|
39
39
|
Requires-Dist: pytz; extra == "tests"
|
|
@@ -41,17 +41,17 @@ Provides-Extra: bqstorage
|
|
|
41
41
|
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "bqstorage"
|
|
42
42
|
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "bqstorage"
|
|
43
43
|
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "bqstorage"
|
|
44
|
-
Requires-Dist: pyarrow>=
|
|
44
|
+
Requires-Dist: pyarrow>=10.0.1; extra == "bqstorage"
|
|
45
45
|
Provides-Extra: all
|
|
46
|
+
Requires-Dist: pytz; extra == "all"
|
|
47
|
+
Requires-Dist: alembic>=1.7.7; extra == "all"
|
|
48
|
+
Requires-Dist: shapely; extra == "all"
|
|
46
49
|
Requires-Dist: packaging; extra == "all"
|
|
47
|
-
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "all"
|
|
48
|
-
Requires-Dist: pyarrow>=6.0.0; extra == "all"
|
|
49
50
|
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "all"
|
|
50
|
-
Requires-Dist:
|
|
51
|
-
Requires-Dist: pytz; extra == "all"
|
|
51
|
+
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "all"
|
|
52
52
|
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "all"
|
|
53
|
+
Requires-Dist: pyarrow>=10.0.1; extra == "all"
|
|
53
54
|
Requires-Dist: GeoAlchemy2; extra == "all"
|
|
54
|
-
Requires-Dist: shapely; extra == "all"
|
|
55
55
|
Dynamic: author
|
|
56
56
|
Dynamic: author-email
|
|
57
57
|
Dynamic: classifier
|
|
@@ -120,11 +120,11 @@ dependencies.
|
|
|
120
120
|
|
|
121
121
|
Supported Python Versions
|
|
122
122
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
123
|
-
Python >= 3.
|
|
123
|
+
Python >= 3.11, <= 3.15
|
|
124
124
|
|
|
125
125
|
Unsupported Python Versions
|
|
126
126
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
127
|
-
Python <= 3.
|
|
127
|
+
Python <= 3.10
|
|
128
128
|
|
|
129
129
|
|
|
130
130
|
Mac/Linux
|
|
@@ -153,7 +153,7 @@ Installations when processing large datasets
|
|
|
153
153
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
154
154
|
|
|
155
155
|
When handling large datasets, you may see speed increases by also installing the
|
|
156
|
-
`bqstorage` dependencies. See the instructions above about creating a virtual
|
|
156
|
+
`bqstorage` dependencies. See the instructions above about creating a virtual
|
|
157
157
|
environment and then install `sqlalchemy-bigquery` using the `bqstorage` extras:
|
|
158
158
|
|
|
159
159
|
.. code-block:: console
|
|
@@ -186,7 +186,7 @@ Project
|
|
|
186
186
|
Authentication
|
|
187
187
|
^^^^^^^^^^^^^^
|
|
188
188
|
|
|
189
|
-
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
189
|
+
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
190
190
|
|
|
191
191
|
Alternatively, you can choose either of the following approaches:
|
|
192
192
|
|
|
@@ -200,10 +200,10 @@ Alternatively, you can choose either of the following approaches:
|
|
|
200
200
|
* pass the credentials in ``create_engine()`` as a Python dictionary using the ``credentials_info`` parameter:
|
|
201
201
|
|
|
202
202
|
.. code-block:: python
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
# provide credentials as a Python dictionary
|
|
205
205
|
credentials_info = {
|
|
206
|
-
"type": "service_account",
|
|
206
|
+
"type": "service_account",
|
|
207
207
|
"project_id": "your-service-account-project-id"
|
|
208
208
|
}
|
|
209
209
|
engine = create_engine('bigquery://', credentials_info=credentials_info)
|
|
@@ -278,7 +278,7 @@ Note that specifying a default dataset doesn't restrict execution of queries to
|
|
|
278
278
|
Connection String Parameters
|
|
279
279
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
280
280
|
|
|
281
|
-
There are many situations where you can't call ``create_engine`` directly, such as when using tools like `Flask SQLAlchemy <
|
|
281
|
+
There are many situations where you can't call ``create_engine`` directly, such as when using tools like `Flask SQLAlchemy <https://flask-sqlalchemy.palletsprojects.com/>`_. For situations like these, or for situations where you want the ``Client`` to have a `default_query_job_config <https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client>`_, you can pass many arguments in the query of the connection string.
|
|
282
282
|
|
|
283
283
|
The ``credentials_path``, ``credentials_info``, ``credentials_base64``, ``location``, ``arraysize`` and ``list_tables_page_size`` parameters are used by this library, and the rest are used to create a `QueryJobConfig <https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.job.QueryJobConfig.html#google.cloud.bigquery.job.QueryJobConfig>`_
|
|
284
284
|
|
|
@@ -309,6 +309,10 @@ Here are examples of all the supported arguments. Any not present are either for
|
|
|
309
309
|
|
|
310
310
|
In cases where you wish to include the full credentials in the connection URI you can base64 the credentials JSON file and supply the encoded string to the ``credentials_base64`` parameter.
|
|
311
311
|
|
|
312
|
+
.. warning::
|
|
313
|
+
|
|
314
|
+
The ``credentials_base64`` parameter puts your service account's private key in the connection string. ``sqlalchemy-bigquery`` hides the key wherever SQLAlchemy hides the password of the engine's URL, such as in ``repr(engine)``. It can't hide the connection string itself, so a configuration file, an environment variable, a log message or any other URL parsed from that string still exposes the key. Where you can, use `Application Default Credentials <https://cloud.google.com/docs/authentication/application-default-credentials>`_ instead, or pass ``credentials_path`` or ``credentials_info`` to ``create_engine()`` as shown under Authentication.
|
|
315
|
+
|
|
312
316
|
.. code-block:: python
|
|
313
317
|
|
|
314
318
|
engine = create_engine(
|
|
@@ -332,7 +336,7 @@ In cases where you wish to include the full credentials in the connection URI yo
|
|
|
332
336
|
|
|
333
337
|
To create the base64 encoded string you can use the command line tool ``base64``, or ``openssl base64``, or ``python -m base64``.
|
|
334
338
|
|
|
335
|
-
|
|
339
|
+
Don't use a website to encode the file: the file contains your service account's private key.
|
|
336
340
|
|
|
337
341
|
|
|
338
342
|
Supplying Your Own BigQuery Client
|
|
@@ -420,6 +424,22 @@ To create an integer-range partitioned table
|
|
|
420
424
|
)
|
|
421
425
|
|
|
422
426
|
|
|
427
|
+
Casting with ``SAFE_CAST``
|
|
428
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
429
|
+
|
|
430
|
+
To generate a BigQuery ``SAFE_CAST`` expression (which returns ``NULL`` instead
|
|
431
|
+
of raising an error when a cast fails), use ``safe_cast`` from
|
|
432
|
+
``sqlalchemy_bigquery`` (or ``sqlalchemy.try_cast`` on SQLAlchemy 2.0+):
|
|
433
|
+
|
|
434
|
+
.. code-block:: python
|
|
435
|
+
|
|
436
|
+
from sqlalchemy import Integer, select
|
|
437
|
+
from sqlalchemy_bigquery import safe_cast
|
|
438
|
+
|
|
439
|
+
stmt = select(safe_cast(table.c.string_col, Integer))
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
423
443
|
Threading and Multiprocessing
|
|
424
444
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
425
445
|
|
|
@@ -51,11 +51,11 @@ dependencies.
|
|
|
51
51
|
|
|
52
52
|
Supported Python Versions
|
|
53
53
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
54
|
-
Python >= 3.
|
|
54
|
+
Python >= 3.11, <= 3.15
|
|
55
55
|
|
|
56
56
|
Unsupported Python Versions
|
|
57
57
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
58
|
-
Python <= 3.
|
|
58
|
+
Python <= 3.10
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
Mac/Linux
|
|
@@ -84,7 +84,7 @@ Installations when processing large datasets
|
|
|
84
84
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
85
85
|
|
|
86
86
|
When handling large datasets, you may see speed increases by also installing the
|
|
87
|
-
`bqstorage` dependencies. See the instructions above about creating a virtual
|
|
87
|
+
`bqstorage` dependencies. See the instructions above about creating a virtual
|
|
88
88
|
environment and then install `sqlalchemy-bigquery` using the `bqstorage` extras:
|
|
89
89
|
|
|
90
90
|
.. code-block:: console
|
|
@@ -117,7 +117,7 @@ Project
|
|
|
117
117
|
Authentication
|
|
118
118
|
^^^^^^^^^^^^^^
|
|
119
119
|
|
|
120
|
-
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
120
|
+
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
121
121
|
|
|
122
122
|
Alternatively, you can choose either of the following approaches:
|
|
123
123
|
|
|
@@ -131,10 +131,10 @@ Alternatively, you can choose either of the following approaches:
|
|
|
131
131
|
* pass the credentials in ``create_engine()`` as a Python dictionary using the ``credentials_info`` parameter:
|
|
132
132
|
|
|
133
133
|
.. code-block:: python
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
# provide credentials as a Python dictionary
|
|
136
136
|
credentials_info = {
|
|
137
|
-
"type": "service_account",
|
|
137
|
+
"type": "service_account",
|
|
138
138
|
"project_id": "your-service-account-project-id"
|
|
139
139
|
}
|
|
140
140
|
engine = create_engine('bigquery://', credentials_info=credentials_info)
|
|
@@ -209,7 +209,7 @@ Note that specifying a default dataset doesn't restrict execution of queries to
|
|
|
209
209
|
Connection String Parameters
|
|
210
210
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
211
211
|
|
|
212
|
-
There are many situations where you can't call ``create_engine`` directly, such as when using tools like `Flask SQLAlchemy <
|
|
212
|
+
There are many situations where you can't call ``create_engine`` directly, such as when using tools like `Flask SQLAlchemy <https://flask-sqlalchemy.palletsprojects.com/>`_. For situations like these, or for situations where you want the ``Client`` to have a `default_query_job_config <https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client>`_, you can pass many arguments in the query of the connection string.
|
|
213
213
|
|
|
214
214
|
The ``credentials_path``, ``credentials_info``, ``credentials_base64``, ``location``, ``arraysize`` and ``list_tables_page_size`` parameters are used by this library, and the rest are used to create a `QueryJobConfig <https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.job.QueryJobConfig.html#google.cloud.bigquery.job.QueryJobConfig>`_
|
|
215
215
|
|
|
@@ -240,6 +240,10 @@ Here are examples of all the supported arguments. Any not present are either for
|
|
|
240
240
|
|
|
241
241
|
In cases where you wish to include the full credentials in the connection URI you can base64 the credentials JSON file and supply the encoded string to the ``credentials_base64`` parameter.
|
|
242
242
|
|
|
243
|
+
.. warning::
|
|
244
|
+
|
|
245
|
+
The ``credentials_base64`` parameter puts your service account's private key in the connection string. ``sqlalchemy-bigquery`` hides the key wherever SQLAlchemy hides the password of the engine's URL, such as in ``repr(engine)``. It can't hide the connection string itself, so a configuration file, an environment variable, a log message or any other URL parsed from that string still exposes the key. Where you can, use `Application Default Credentials <https://cloud.google.com/docs/authentication/application-default-credentials>`_ instead, or pass ``credentials_path`` or ``credentials_info`` to ``create_engine()`` as shown under Authentication.
|
|
246
|
+
|
|
243
247
|
.. code-block:: python
|
|
244
248
|
|
|
245
249
|
engine = create_engine(
|
|
@@ -263,7 +267,7 @@ In cases where you wish to include the full credentials in the connection URI yo
|
|
|
263
267
|
|
|
264
268
|
To create the base64 encoded string you can use the command line tool ``base64``, or ``openssl base64``, or ``python -m base64``.
|
|
265
269
|
|
|
266
|
-
|
|
270
|
+
Don't use a website to encode the file: the file contains your service account's private key.
|
|
267
271
|
|
|
268
272
|
|
|
269
273
|
Supplying Your Own BigQuery Client
|
|
@@ -351,6 +355,22 @@ To create an integer-range partitioned table
|
|
|
351
355
|
)
|
|
352
356
|
|
|
353
357
|
|
|
358
|
+
Casting with ``SAFE_CAST``
|
|
359
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
360
|
+
|
|
361
|
+
To generate a BigQuery ``SAFE_CAST`` expression (which returns ``NULL`` instead
|
|
362
|
+
of raising an error when a cast fails), use ``safe_cast`` from
|
|
363
|
+
``sqlalchemy_bigquery`` (or ``sqlalchemy.try_cast`` on SQLAlchemy 2.0+):
|
|
364
|
+
|
|
365
|
+
.. code-block:: python
|
|
366
|
+
|
|
367
|
+
from sqlalchemy import Integer, select
|
|
368
|
+
from sqlalchemy_bigquery import safe_cast
|
|
369
|
+
|
|
370
|
+
stmt = select(safe_cast(table.c.string_col, Integer))
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
354
374
|
Threading and Multiprocessing
|
|
355
375
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
356
376
|
|
|
@@ -49,7 +49,7 @@ def readme():
|
|
|
49
49
|
|
|
50
50
|
extras = {
|
|
51
51
|
"geography": ["GeoAlchemy2", "shapely"],
|
|
52
|
-
"alembic": ["alembic"],
|
|
52
|
+
"alembic": ["alembic >= 1.7.7"],
|
|
53
53
|
"tests": ["packaging", "pytz"],
|
|
54
54
|
# Keep the no-op bqstorage extra for backward compatibility.
|
|
55
55
|
# See: https://github.com/googleapis/python-bigquery/issues/757
|
|
@@ -63,7 +63,7 @@ extras = {
|
|
|
63
63
|
# https://github.com/grpc/grpc/pull/15254
|
|
64
64
|
"grpcio >= 1.59.0, < 2.0.0",
|
|
65
65
|
"grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'",
|
|
66
|
-
"pyarrow >=
|
|
66
|
+
"pyarrow >= 10.0.1",
|
|
67
67
|
],
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -100,11 +100,11 @@ setup(
|
|
|
100
100
|
"License :: OSI Approved :: MIT License",
|
|
101
101
|
"Programming Language :: Python",
|
|
102
102
|
"Programming Language :: Python :: 3",
|
|
103
|
-
"Programming Language :: Python :: 3.10",
|
|
104
103
|
"Programming Language :: Python :: 3.11",
|
|
105
104
|
"Programming Language :: Python :: 3.12",
|
|
106
105
|
"Programming Language :: Python :: 3.13",
|
|
107
106
|
"Programming Language :: Python :: 3.14",
|
|
107
|
+
"Programming Language :: Python :: 3.15",
|
|
108
108
|
"Operating System :: OS Independent",
|
|
109
109
|
"Topic :: Database :: Front-Ends",
|
|
110
110
|
],
|
|
@@ -112,12 +112,12 @@ setup(
|
|
|
112
112
|
install_requires=[
|
|
113
113
|
"google-api-core >= 2.25.0, <3.0.0",
|
|
114
114
|
"google-auth>=2.14.1,<3.0.0",
|
|
115
|
-
"google-cloud-bigquery>=3.20.
|
|
115
|
+
"google-cloud-bigquery>=3.20.1,<4.0.0",
|
|
116
116
|
"packaging",
|
|
117
|
-
"sqlalchemy>=1.4.
|
|
117
|
+
"sqlalchemy>=1.4.41,<3.0.0",
|
|
118
118
|
],
|
|
119
119
|
extras_require=extras,
|
|
120
|
-
python_requires=">=3.
|
|
120
|
+
python_requires=">=3.11",
|
|
121
121
|
tests_require=["packaging", "pytz"],
|
|
122
122
|
entry_points={
|
|
123
123
|
"sqlalchemy.dialects": ["bigquery = sqlalchemy_bigquery:BigQueryDialect"]
|
|
@@ -20,9 +20,6 @@
|
|
|
20
20
|
SQLAlchemy dialect for Google BigQuery
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
import sys
|
|
24
|
-
import warnings
|
|
25
|
-
|
|
26
23
|
from ._types import (
|
|
27
24
|
ARRAY,
|
|
28
25
|
BIGNUMERIC,
|
|
@@ -42,22 +39,9 @@ from ._types import (
|
|
|
42
39
|
TIME,
|
|
43
40
|
TIMESTAMP,
|
|
44
41
|
)
|
|
45
|
-
from .base import BigQueryDialect, dialect
|
|
42
|
+
from .base import BigQueryDialect, SafeCast, dialect, safe_cast
|
|
46
43
|
from .version import __version__
|
|
47
44
|
|
|
48
|
-
# Now that support for Python 3.7, 3.8 and 3.9 has been removed, we don't expect the
|
|
49
|
-
# following check to succeed. The warning is only included for robustness.
|
|
50
|
-
if sys.version_info < (3, 10): # pragma: NO COVER
|
|
51
|
-
warnings.warn(
|
|
52
|
-
"The python-bigquery-sqlalchemy library no longer supports Python 3.7, "
|
|
53
|
-
"3.8 and 3.9. "
|
|
54
|
-
f"Your Python version is {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}. We "
|
|
55
|
-
"recommend that you update soon to ensure ongoing support. For "
|
|
56
|
-
"more details, see: [Google Cloud Client Libraries Supported Python Versions policy](https://cloud.google.com/python/docs/supported-python-versions)",
|
|
57
|
-
FutureWarning,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
45
|
__all__ = [
|
|
62
46
|
"__version__",
|
|
63
47
|
"dialect",
|
|
@@ -77,8 +61,10 @@ __all__ = [
|
|
|
77
61
|
"RECORD",
|
|
78
62
|
"STRING",
|
|
79
63
|
"STRUCT",
|
|
64
|
+
"SafeCast",
|
|
80
65
|
"TIME",
|
|
81
66
|
"TIMESTAMP",
|
|
67
|
+
"safe_cast",
|
|
82
68
|
]
|
|
83
69
|
|
|
84
70
|
try:
|
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
# https://opensource.org/licenses/MIT.
|
|
6
6
|
|
|
7
7
|
import base64
|
|
8
|
+
import copy
|
|
8
9
|
import functools
|
|
9
10
|
import json
|
|
10
11
|
import re
|
|
11
|
-
from
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
from typing import Any, Optional
|
|
12
14
|
|
|
13
15
|
import google.auth
|
|
14
16
|
import sqlalchemy
|
|
15
17
|
from google.api_core import client_info
|
|
18
|
+
from google.api_core import client_options as client_options_lib
|
|
16
19
|
from google.cloud import bigquery
|
|
17
20
|
from google.oauth2 import service_account
|
|
18
21
|
|
|
@@ -37,6 +40,40 @@ def google_client_info(
|
|
|
37
40
|
return client_info.ClientInfo(user_agent=user_agent)
|
|
38
41
|
|
|
39
42
|
|
|
43
|
+
# TODO(https://github.com/googleapis/google-cloud-python/issues/19297): Replace with
|
|
44
|
+
# google.api_core.client_options.normalize_client_options once available and
|
|
45
|
+
# minimum allowed google-api-core version exceeds that release.
|
|
46
|
+
def _normalize_client_options(
|
|
47
|
+
client_options: client_options_lib.ClientOptions | Mapping[str, Any] | None,
|
|
48
|
+
) -> client_options_lib.ClientOptions | None:
|
|
49
|
+
"""Normalize ``client_options`` to a fresh ``ClientOptions`` copy or ``None``.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
client_options: Optional ``ClientOptions`` instance, ``Mapping``, or
|
|
53
|
+
``None``.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
A fresh ``ClientOptions`` copy, or ``None`` if ``client_options`` is
|
|
57
|
+
``None``.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
TypeError: If ``client_options`` is not a ``ClientOptions`` instance,
|
|
61
|
+
``Mapping``, or ``None``.
|
|
62
|
+
ValueError: If ``client_options`` is a ``Mapping`` containing an
|
|
63
|
+
unrecognized option name.
|
|
64
|
+
"""
|
|
65
|
+
if client_options is None:
|
|
66
|
+
return None
|
|
67
|
+
if isinstance(client_options, Mapping):
|
|
68
|
+
return client_options_lib.from_dict(client_options)
|
|
69
|
+
if isinstance(client_options, client_options_lib.ClientOptions):
|
|
70
|
+
return copy.copy(client_options)
|
|
71
|
+
raise TypeError(
|
|
72
|
+
"client_options must be a ClientOptions instance, Mapping, or None; "
|
|
73
|
+
f"got {type(client_options).__name__}"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
40
77
|
def create_bigquery_client(
|
|
41
78
|
credentials_info: Optional[dict] = None,
|
|
42
79
|
credentials_path: Optional[str] = None,
|
|
@@ -45,6 +82,7 @@ def create_bigquery_client(
|
|
|
45
82
|
location: Optional[str] = None,
|
|
46
83
|
project_id: Optional[str] = None,
|
|
47
84
|
user_agent: Optional[google.api_core.client_info.ClientInfo] = None,
|
|
85
|
+
client_options: client_options_lib.ClientOptions | Mapping[str, Any] | None = None,
|
|
48
86
|
) -> google.cloud.bigquery.Client:
|
|
49
87
|
"""Construct a BigQuery client object.
|
|
50
88
|
|
|
@@ -64,6 +102,10 @@ def create_bigquery_client(
|
|
|
64
102
|
requests. If ``None``, then default info will be used. Generally,
|
|
65
103
|
you only need to set this if you're developing your own library
|
|
66
104
|
or partner tool.
|
|
105
|
+
client_options (client_options_lib.ClientOptions | Mapping[str, Any] | None):
|
|
106
|
+
Client options (such as ``universe_domain`` or ``api_endpoint``)
|
|
107
|
+
forwarded to ``google.cloud.bigquery.Client``. If ``None``, default
|
|
108
|
+
client options are used.
|
|
67
109
|
"""
|
|
68
110
|
|
|
69
111
|
default_project = None
|
|
@@ -90,6 +132,7 @@ def create_bigquery_client(
|
|
|
90
132
|
project_id = default_project
|
|
91
133
|
|
|
92
134
|
client_info = google_client_info(user_agent=user_agent)
|
|
135
|
+
client_options = _normalize_client_options(client_options)
|
|
93
136
|
|
|
94
137
|
return bigquery.Client(
|
|
95
138
|
client_info=client_info,
|
|
@@ -97,6 +140,7 @@ def create_bigquery_client(
|
|
|
97
140
|
credentials=credentials,
|
|
98
141
|
location=location,
|
|
99
142
|
default_query_job_config=default_query_job_config,
|
|
143
|
+
client_options=client_options,
|
|
100
144
|
)
|
|
101
145
|
|
|
102
146
|
|
|
@@ -91,6 +91,11 @@ class STRUCT(sqlalchemy.sql.sqltypes.Indexable, sqlalchemy.types.UserDefinedType
|
|
|
91
91
|
subtype = self.expr.type._STRUCT_byname.get(name.lower())
|
|
92
92
|
if subtype is None:
|
|
93
93
|
raise KeyError(name)
|
|
94
|
+
# Reuse `operators.json_getitem_op` to represent STRUCT subfield
|
|
95
|
+
# access. `BigQueryCompiler.visit_json_getitem_op_binary` in
|
|
96
|
+
# `base.py` checks whether the left operand is a `STRUCT` (vs. a
|
|
97
|
+
# `sqlalchemy.JSON` column) and compiles STRUCT subfields as
|
|
98
|
+
# backtick-quoted SQL identifiers (`struct_col.`field``).
|
|
94
99
|
operator = operators.json_getitem_op
|
|
95
100
|
index = _field_index(self, name, operator)
|
|
96
101
|
return operator, index, subtype
|
|
@@ -112,9 +117,3 @@ def _field_index(self, name, operator):
|
|
|
112
117
|
operator=operator,
|
|
113
118
|
bindparam_type=sqlalchemy.types.String(),
|
|
114
119
|
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# class SQLCompiler:
|
|
118
|
-
# def visit_json_getitem_op_binary(self, binary, operator_, **kw):
|
|
119
|
-
# left = self.process(binary.left, **kw)
|
|
120
|
-
# return f"{left}.{binary.right.value}"
|