sqlalchemy-bigquery 1.4.4__tar.gz → 1.12.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.4.4 → sqlalchemy_bigquery-1.12.0}/AUTHORS +1 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/MANIFEST.in +3 -2
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/PKG-INFO +136 -11
- sqlalchemy-bigquery-1.4.4/sqlalchemy_bigquery.egg-info/PKG-INFO → sqlalchemy_bigquery-1.12.0/README.rst +106 -36
- sqlalchemy_bigquery-1.12.0/pyproject.toml +5 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/setup.py +42 -19
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/__init__.py +5 -3
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/_helpers.py +42 -10
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/_struct.py +14 -36
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/_types.py +2 -2
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/base.py +380 -83
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/parse_url.py +8 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/requirements.py +5 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/version.py +1 -1
- sqlalchemy-bigquery-1.4.4/README.rst → sqlalchemy_bigquery-1.12.0/sqlalchemy_bigquery.egg-info/PKG-INFO +161 -5
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery.egg-info/SOURCES.txt +11 -1
- sqlalchemy_bigquery-1.12.0/sqlalchemy_bigquery.egg-info/requires.txt +37 -0
- sqlalchemy_bigquery-1.12.0/sqlalchemy_bigquery.egg-info/top_level.txt +2 -0
- sqlalchemy_bigquery-1.12.0/tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py +642 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/test__struct.py +24 -21
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/test_alembic.py +18 -14
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/test_geography.py +14 -6
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/test_helpers.py +8 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/test_sqlalchemy_bigquery.py +249 -116
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/conftest.py +12 -9
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/fauxdbi.py +0 -1
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test__struct.py +2 -2
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_catalog_functions.py +1 -12
- sqlalchemy_bigquery-1.12.0/tests/unit/test_compiler.py +419 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_compliance.py +20 -30
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_geography.py +9 -7
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_helpers.py +13 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_like_reescape.py +0 -2
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_parse_url.py +13 -2
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_select.py +230 -118
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_sqlalchemy_bigquery.py +15 -8
- sqlalchemy_bigquery-1.12.0/tests/unit/test_table_options.py +492 -0
- sqlalchemy_bigquery-1.12.0/tests/unit/test_version.py +29 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/__init__.py +0 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/py.typed +0 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/AUTHORS +30 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/LICENSE +19 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/__init__.py +6 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/__init__.py +0 -0
- sqlalchemy_bigquery-1.12.0/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/base.py +19 -0
- sqlalchemy-bigquery-1.4.4/sqlalchemy_bigquery.egg-info/requires.txt +0 -25
- sqlalchemy-bigquery-1.4.4/sqlalchemy_bigquery.egg-info/top_level.txt +0 -1
- sqlalchemy-bigquery-1.4.4/tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py +0 -264
- sqlalchemy-bigquery-1.4.4/tests/unit/test_compiler.py +0 -116
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/LICENSE +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/setup.cfg +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery/geography.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery.egg-info/dependency_links.txt +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/sqlalchemy_bigquery.egg-info/entry_points.txt +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/__init__.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/conftest.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/sqlalchemy_dialect_compliance/README.rst +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/sqlalchemy_dialect_compliance/conftest.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/__init__.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/conftest.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/data/sample.json +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/data/sample_one_row.json +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/system/data/schema.json +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/__init__.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_comments.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_dialect_types.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_engine.py +0 -0
- {sqlalchemy-bigquery-1.4.4 → sqlalchemy_bigquery-1.12.0}/tests/unit/test_view.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
#
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2024 Google LLC
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
# Generated by synthtool. DO NOT EDIT!
|
|
18
18
|
include README.rst LICENSE
|
|
19
|
-
recursive-include
|
|
19
|
+
recursive-include third_party/sqlalchemy_bigquery_vendored *
|
|
20
|
+
recursive-include sqlalchemy_bigquery *.json *.proto py.typed
|
|
20
21
|
recursive-include tests *
|
|
21
22
|
global-exclude *.py[co]
|
|
22
23
|
global-exclude __pycache__
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.12.0
|
|
4
4
|
Summary: SQLAlchemy dialect for BigQuery
|
|
5
5
|
Home-page: https://github.com/googleapis/python-bigquery-sqlalchemy
|
|
6
6
|
Author: The Sqlalchemy-Bigquery Authors
|
|
@@ -12,22 +12,46 @@ 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.6
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.8
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
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.8, <3.13
|
|
24
24
|
Description-Content-Type: text/x-rst
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
License-File: AUTHORS
|
|
27
|
+
Requires-Dist: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5
|
|
28
|
+
Requires-Dist: google-auth<3.0.0dev,>=1.25.0
|
|
29
|
+
Requires-Dist: google-cloud-bigquery<4.0.0dev,>=3.3.6
|
|
30
|
+
Requires-Dist: packaging
|
|
31
|
+
Requires-Dist: sqlalchemy<3.0.0dev,>=1.4.16
|
|
25
32
|
Provides-Extra: geography
|
|
33
|
+
Requires-Dist: GeoAlchemy2; extra == "geography"
|
|
34
|
+
Requires-Dist: shapely; extra == "geography"
|
|
26
35
|
Provides-Extra: alembic
|
|
36
|
+
Requires-Dist: alembic; extra == "alembic"
|
|
27
37
|
Provides-Extra: tests
|
|
38
|
+
Requires-Dist: packaging; extra == "tests"
|
|
39
|
+
Requires-Dist: pytz; extra == "tests"
|
|
40
|
+
Provides-Extra: bqstorage
|
|
41
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0dev,>=2.0.0; extra == "bqstorage"
|
|
42
|
+
Requires-Dist: grpcio<2.0dev,>=1.47.0; extra == "bqstorage"
|
|
43
|
+
Requires-Dist: grpcio<2.0dev,>=1.49.1; python_version >= "3.11" and extra == "bqstorage"
|
|
44
|
+
Requires-Dist: pyarrow>=3.0.0; extra == "bqstorage"
|
|
28
45
|
Provides-Extra: all
|
|
29
|
-
|
|
30
|
-
|
|
46
|
+
Requires-Dist: pytz; extra == "all"
|
|
47
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0dev,>=2.0.0; extra == "all"
|
|
48
|
+
Requires-Dist: alembic; extra == "all"
|
|
49
|
+
Requires-Dist: grpcio<2.0dev,>=1.49.1; python_version >= "3.11" and extra == "all"
|
|
50
|
+
Requires-Dist: grpcio<2.0dev,>=1.47.0; extra == "all"
|
|
51
|
+
Requires-Dist: packaging; extra == "all"
|
|
52
|
+
Requires-Dist: pyarrow>=3.0.0; extra == "all"
|
|
53
|
+
Requires-Dist: GeoAlchemy2; extra == "all"
|
|
54
|
+
Requires-Dist: shapely; extra == "all"
|
|
31
55
|
|
|
32
56
|
SQLAlchemy Dialect for BigQuery
|
|
33
57
|
===============================
|
|
@@ -65,6 +89,7 @@ In order to use this library, you first need to go through the following steps:
|
|
|
65
89
|
.. _Enable the BigQuery Storage API.: https://console.cloud.google.com/apis/library/bigquery.googleapis.com
|
|
66
90
|
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
|
|
67
91
|
|
|
92
|
+
|
|
68
93
|
Installation
|
|
69
94
|
------------
|
|
70
95
|
|
|
@@ -81,11 +106,11 @@ dependencies.
|
|
|
81
106
|
|
|
82
107
|
Supported Python Versions
|
|
83
108
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
84
|
-
Python >= 3.
|
|
109
|
+
Python >= 3.8
|
|
85
110
|
|
|
86
111
|
Unsupported Python Versions
|
|
87
112
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
88
|
-
Python <= 3.
|
|
113
|
+
Python <= 3.7.
|
|
89
114
|
|
|
90
115
|
|
|
91
116
|
Mac/Linux
|
|
@@ -109,6 +134,20 @@ Windows
|
|
|
109
134
|
<your-env>\Scripts\activate
|
|
110
135
|
<your-env>\Scripts\pip.exe install sqlalchemy-bigquery
|
|
111
136
|
|
|
137
|
+
|
|
138
|
+
Installations when processing large datasets
|
|
139
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
140
|
+
|
|
141
|
+
When handling large datasets, you may see speed increases by also installing the
|
|
142
|
+
`bqstorage` dependencies. See the instructions above about creating a virtual
|
|
143
|
+
environment and then install `sqlalchemy-bigquery` using the `bqstorage` extras:
|
|
144
|
+
|
|
145
|
+
.. code-block:: console
|
|
146
|
+
|
|
147
|
+
source <your-env>/bin/activate
|
|
148
|
+
<your-env>/bin/pip install sqlalchemy-bigquery[bqstorage]
|
|
149
|
+
|
|
150
|
+
|
|
112
151
|
Usage
|
|
113
152
|
-----
|
|
114
153
|
|
|
@@ -122,7 +161,8 @@ SQLAlchemy
|
|
|
122
161
|
from sqlalchemy.schema import *
|
|
123
162
|
engine = create_engine('bigquery://project')
|
|
124
163
|
table = Table('dataset.table', MetaData(bind=engine), autoload=True)
|
|
125
|
-
print(select([func.count('*')], from_obj=table).scalar())
|
|
164
|
+
print(select([func.count('*')], from_obj=table().scalar()))
|
|
165
|
+
|
|
126
166
|
|
|
127
167
|
Project
|
|
128
168
|
^^^^^^^
|
|
@@ -132,12 +172,27 @@ Project
|
|
|
132
172
|
Authentication
|
|
133
173
|
^^^^^^^^^^^^^^
|
|
134
174
|
|
|
135
|
-
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
175
|
+
Follow the `Google Cloud library guide <https://google-cloud-python.readthedocs.io/en/latest/core/auth.html>`_ for authentication.
|
|
176
|
+
|
|
177
|
+
Alternatively, you can choose either of the following approaches:
|
|
178
|
+
|
|
179
|
+
* provide the path to a service account JSON file in ``create_engine()`` using the ``credentials_path`` parameter:
|
|
136
180
|
|
|
137
181
|
.. code-block:: python
|
|
138
182
|
|
|
183
|
+
# provide the path to a service account JSON file
|
|
139
184
|
engine = create_engine('bigquery://', credentials_path='/path/to/keyfile.json')
|
|
140
185
|
|
|
186
|
+
* pass the credentials in ``create_engine()`` as a Python dictionary using the ``credentials_info`` parameter:
|
|
187
|
+
|
|
188
|
+
.. code-block:: python
|
|
189
|
+
|
|
190
|
+
# provide credentials as a Python dictionary
|
|
191
|
+
credentials_info = {
|
|
192
|
+
"type": "service_account",
|
|
193
|
+
"project_id": "your-service-account-project-id"
|
|
194
|
+
},
|
|
195
|
+
engine = create_engine('bigquery://', credentials_info=credentials_info)
|
|
141
196
|
|
|
142
197
|
Location
|
|
143
198
|
^^^^^^^^
|
|
@@ -265,6 +320,25 @@ To create the base64 encoded string you can use the command line tool ``base64``
|
|
|
265
320
|
|
|
266
321
|
Alternatively, you can use an online generator like `www.base64encode.org <https://www.base64encode.org>_` to paste your credentials JSON file to be encoded.
|
|
267
322
|
|
|
323
|
+
|
|
324
|
+
Supplying Your Own BigQuery Client
|
|
325
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
326
|
+
|
|
327
|
+
The above connection string parameters allow you to influence how the BigQuery client used to execute your queries will be instantiated.
|
|
328
|
+
If you need additional control, you can supply a BigQuery client of your own:
|
|
329
|
+
|
|
330
|
+
.. code-block:: python
|
|
331
|
+
|
|
332
|
+
from google.cloud import bigquery
|
|
333
|
+
|
|
334
|
+
custom_bq_client = bigquery.Client(...)
|
|
335
|
+
|
|
336
|
+
engine = create_engine(
|
|
337
|
+
'bigquery://some-project/some-dataset?user_supplied_client=True',
|
|
338
|
+
connect_args={'client': custom_bq_client},
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
268
342
|
Creating tables
|
|
269
343
|
^^^^^^^^^^^^^^^
|
|
270
344
|
|
|
@@ -272,7 +346,12 @@ To add metadata to a table:
|
|
|
272
346
|
|
|
273
347
|
.. code-block:: python
|
|
274
348
|
|
|
275
|
-
table = Table('mytable', ...,
|
|
349
|
+
table = Table('mytable', ...,
|
|
350
|
+
bigquery_description='my table description',
|
|
351
|
+
bigquery_friendly_name='my table friendly name',
|
|
352
|
+
bigquery_default_rounding_mode="ROUND_HALF_EVEN",
|
|
353
|
+
bigquery_expiration_timestamp=datetime.datetime.fromisoformat("2038-01-01T00:00:00+00:00"),
|
|
354
|
+
)
|
|
276
355
|
|
|
277
356
|
To add metadata to a column:
|
|
278
357
|
|
|
@@ -280,6 +359,52 @@ To add metadata to a column:
|
|
|
280
359
|
|
|
281
360
|
Column('mycolumn', doc='my column description')
|
|
282
361
|
|
|
362
|
+
To create a clustered table:
|
|
363
|
+
|
|
364
|
+
.. code-block:: python
|
|
365
|
+
|
|
366
|
+
table = Table('mytable', ..., bigquery_clustering_fields=["a", "b", "c"])
|
|
367
|
+
|
|
368
|
+
To create a time-unit column-partitioned table:
|
|
369
|
+
|
|
370
|
+
.. code-block:: python
|
|
371
|
+
|
|
372
|
+
from google.cloud import bigquery
|
|
373
|
+
|
|
374
|
+
table = Table('mytable', ...,
|
|
375
|
+
bigquery_time_partitioning=bigquery.TimePartitioning(
|
|
376
|
+
field="mytimestamp",
|
|
377
|
+
type_="MONTH",
|
|
378
|
+
expiration_ms=1000 * 60 * 60 * 24 * 30 * 6, # 6 months
|
|
379
|
+
),
|
|
380
|
+
bigquery_require_partition_filter=True,
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
To create an ingestion-time partitioned table:
|
|
384
|
+
|
|
385
|
+
.. code-block:: python
|
|
386
|
+
|
|
387
|
+
from google.cloud import bigquery
|
|
388
|
+
|
|
389
|
+
table = Table('mytable', ...,
|
|
390
|
+
bigquery_time_partitioning=bigquery.TimePartitioning(),
|
|
391
|
+
bigquery_require_partition_filter=True,
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
To create an integer-range partitioned table
|
|
395
|
+
|
|
396
|
+
.. code-block:: python
|
|
397
|
+
|
|
398
|
+
from google.cloud import bigquery
|
|
399
|
+
|
|
400
|
+
table = Table('mytable', ...,
|
|
401
|
+
bigquery_range_partitioning=bigquery.RangePartitioning(
|
|
402
|
+
field="zipcode",
|
|
403
|
+
range_=bigquery.PartitionRange(start=0, end=100000, interval=10),
|
|
404
|
+
),
|
|
405
|
+
bigquery_require_partition_filter=True,
|
|
406
|
+
)
|
|
407
|
+
|
|
283
408
|
|
|
284
409
|
Threading and Multiprocessing
|
|
285
410
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 1.4.4
|
|
4
|
-
Summary: SQLAlchemy dialect for BigQuery
|
|
5
|
-
Home-page: https://github.com/googleapis/python-bigquery-sqlalchemy
|
|
6
|
-
Author: The Sqlalchemy-Bigquery Authors
|
|
7
|
-
Author-email: googleapis-packages@google.com
|
|
8
|
-
Keywords: bigquery,sqlalchemy
|
|
9
|
-
Platform: Posix; MacOS X; Windows
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Programming Language :: Python
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
-
Classifier: Operating System :: OS Independent
|
|
21
|
-
Classifier: Topic :: Database :: Front-Ends
|
|
22
|
-
Obsoletes: pybigquery
|
|
23
|
-
Requires-Python: >=3.6, <3.11
|
|
24
|
-
Description-Content-Type: text/x-rst
|
|
25
|
-
Provides-Extra: geography
|
|
26
|
-
Provides-Extra: alembic
|
|
27
|
-
Provides-Extra: tests
|
|
28
|
-
Provides-Extra: all
|
|
29
|
-
License-File: LICENSE
|
|
30
|
-
License-File: AUTHORS
|
|
31
|
-
|
|
32
1
|
SQLAlchemy Dialect for BigQuery
|
|
33
2
|
===============================
|
|
34
3
|
|
|
@@ -65,6 +34,7 @@ In order to use this library, you first need to go through the following steps:
|
|
|
65
34
|
.. _Enable the BigQuery Storage API.: https://console.cloud.google.com/apis/library/bigquery.googleapis.com
|
|
66
35
|
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
|
|
67
36
|
|
|
37
|
+
|
|
68
38
|
Installation
|
|
69
39
|
------------
|
|
70
40
|
|
|
@@ -81,11 +51,11 @@ dependencies.
|
|
|
81
51
|
|
|
82
52
|
Supported Python Versions
|
|
83
53
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
84
|
-
Python >= 3.
|
|
54
|
+
Python >= 3.8
|
|
85
55
|
|
|
86
56
|
Unsupported Python Versions
|
|
87
57
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
88
|
-
Python <= 3.
|
|
58
|
+
Python <= 3.7.
|
|
89
59
|
|
|
90
60
|
|
|
91
61
|
Mac/Linux
|
|
@@ -109,6 +79,20 @@ Windows
|
|
|
109
79
|
<your-env>\Scripts\activate
|
|
110
80
|
<your-env>\Scripts\pip.exe install sqlalchemy-bigquery
|
|
111
81
|
|
|
82
|
+
|
|
83
|
+
Installations when processing large datasets
|
|
84
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
85
|
+
|
|
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
|
|
88
|
+
environment and then install `sqlalchemy-bigquery` using the `bqstorage` extras:
|
|
89
|
+
|
|
90
|
+
.. code-block:: console
|
|
91
|
+
|
|
92
|
+
source <your-env>/bin/activate
|
|
93
|
+
<your-env>/bin/pip install sqlalchemy-bigquery[bqstorage]
|
|
94
|
+
|
|
95
|
+
|
|
112
96
|
Usage
|
|
113
97
|
-----
|
|
114
98
|
|
|
@@ -122,7 +106,8 @@ SQLAlchemy
|
|
|
122
106
|
from sqlalchemy.schema import *
|
|
123
107
|
engine = create_engine('bigquery://project')
|
|
124
108
|
table = Table('dataset.table', MetaData(bind=engine), autoload=True)
|
|
125
|
-
print(select([func.count('*')], from_obj=table).scalar())
|
|
109
|
+
print(select([func.count('*')], from_obj=table().scalar()))
|
|
110
|
+
|
|
126
111
|
|
|
127
112
|
Project
|
|
128
113
|
^^^^^^^
|
|
@@ -132,12 +117,27 @@ Project
|
|
|
132
117
|
Authentication
|
|
133
118
|
^^^^^^^^^^^^^^
|
|
134
119
|
|
|
135
|
-
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
|
+
|
|
122
|
+
Alternatively, you can choose either of the following approaches:
|
|
123
|
+
|
|
124
|
+
* provide the path to a service account JSON file in ``create_engine()`` using the ``credentials_path`` parameter:
|
|
136
125
|
|
|
137
126
|
.. code-block:: python
|
|
138
127
|
|
|
128
|
+
# provide the path to a service account JSON file
|
|
139
129
|
engine = create_engine('bigquery://', credentials_path='/path/to/keyfile.json')
|
|
140
130
|
|
|
131
|
+
* pass the credentials in ``create_engine()`` as a Python dictionary using the ``credentials_info`` parameter:
|
|
132
|
+
|
|
133
|
+
.. code-block:: python
|
|
134
|
+
|
|
135
|
+
# provide credentials as a Python dictionary
|
|
136
|
+
credentials_info = {
|
|
137
|
+
"type": "service_account",
|
|
138
|
+
"project_id": "your-service-account-project-id"
|
|
139
|
+
},
|
|
140
|
+
engine = create_engine('bigquery://', credentials_info=credentials_info)
|
|
141
141
|
|
|
142
142
|
Location
|
|
143
143
|
^^^^^^^^
|
|
@@ -265,6 +265,25 @@ To create the base64 encoded string you can use the command line tool ``base64``
|
|
|
265
265
|
|
|
266
266
|
Alternatively, you can use an online generator like `www.base64encode.org <https://www.base64encode.org>_` to paste your credentials JSON file to be encoded.
|
|
267
267
|
|
|
268
|
+
|
|
269
|
+
Supplying Your Own BigQuery Client
|
|
270
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
271
|
+
|
|
272
|
+
The above connection string parameters allow you to influence how the BigQuery client used to execute your queries will be instantiated.
|
|
273
|
+
If you need additional control, you can supply a BigQuery client of your own:
|
|
274
|
+
|
|
275
|
+
.. code-block:: python
|
|
276
|
+
|
|
277
|
+
from google.cloud import bigquery
|
|
278
|
+
|
|
279
|
+
custom_bq_client = bigquery.Client(...)
|
|
280
|
+
|
|
281
|
+
engine = create_engine(
|
|
282
|
+
'bigquery://some-project/some-dataset?user_supplied_client=True',
|
|
283
|
+
connect_args={'client': custom_bq_client},
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
|
|
268
287
|
Creating tables
|
|
269
288
|
^^^^^^^^^^^^^^^
|
|
270
289
|
|
|
@@ -272,7 +291,12 @@ To add metadata to a table:
|
|
|
272
291
|
|
|
273
292
|
.. code-block:: python
|
|
274
293
|
|
|
275
|
-
table = Table('mytable', ...,
|
|
294
|
+
table = Table('mytable', ...,
|
|
295
|
+
bigquery_description='my table description',
|
|
296
|
+
bigquery_friendly_name='my table friendly name',
|
|
297
|
+
bigquery_default_rounding_mode="ROUND_HALF_EVEN",
|
|
298
|
+
bigquery_expiration_timestamp=datetime.datetime.fromisoformat("2038-01-01T00:00:00+00:00"),
|
|
299
|
+
)
|
|
276
300
|
|
|
277
301
|
To add metadata to a column:
|
|
278
302
|
|
|
@@ -280,6 +304,52 @@ To add metadata to a column:
|
|
|
280
304
|
|
|
281
305
|
Column('mycolumn', doc='my column description')
|
|
282
306
|
|
|
307
|
+
To create a clustered table:
|
|
308
|
+
|
|
309
|
+
.. code-block:: python
|
|
310
|
+
|
|
311
|
+
table = Table('mytable', ..., bigquery_clustering_fields=["a", "b", "c"])
|
|
312
|
+
|
|
313
|
+
To create a time-unit column-partitioned table:
|
|
314
|
+
|
|
315
|
+
.. code-block:: python
|
|
316
|
+
|
|
317
|
+
from google.cloud import bigquery
|
|
318
|
+
|
|
319
|
+
table = Table('mytable', ...,
|
|
320
|
+
bigquery_time_partitioning=bigquery.TimePartitioning(
|
|
321
|
+
field="mytimestamp",
|
|
322
|
+
type_="MONTH",
|
|
323
|
+
expiration_ms=1000 * 60 * 60 * 24 * 30 * 6, # 6 months
|
|
324
|
+
),
|
|
325
|
+
bigquery_require_partition_filter=True,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
To create an ingestion-time partitioned table:
|
|
329
|
+
|
|
330
|
+
.. code-block:: python
|
|
331
|
+
|
|
332
|
+
from google.cloud import bigquery
|
|
333
|
+
|
|
334
|
+
table = Table('mytable', ...,
|
|
335
|
+
bigquery_time_partitioning=bigquery.TimePartitioning(),
|
|
336
|
+
bigquery_require_partition_filter=True,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
To create an integer-range partitioned table
|
|
340
|
+
|
|
341
|
+
.. code-block:: python
|
|
342
|
+
|
|
343
|
+
from google.cloud import bigquery
|
|
344
|
+
|
|
345
|
+
table = Table('mytable', ...,
|
|
346
|
+
bigquery_range_partitioning=bigquery.RangePartitioning(
|
|
347
|
+
field="zipcode",
|
|
348
|
+
range_=bigquery.PartitionRange(start=0, end=100000, interval=10),
|
|
349
|
+
),
|
|
350
|
+
bigquery_require_partition_filter=True,
|
|
351
|
+
)
|
|
352
|
+
|
|
283
353
|
|
|
284
354
|
Threading and Multiprocessing
|
|
285
355
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
@@ -22,6 +22,7 @@ import io
|
|
|
22
22
|
import itertools
|
|
23
23
|
import os
|
|
24
24
|
import re
|
|
25
|
+
import setuptools
|
|
25
26
|
from setuptools import setup
|
|
26
27
|
|
|
27
28
|
# Package metadata.
|
|
@@ -45,13 +46,38 @@ def readme():
|
|
|
45
46
|
return f.read()
|
|
46
47
|
|
|
47
48
|
|
|
48
|
-
extras =
|
|
49
|
-
geography
|
|
50
|
-
alembic
|
|
51
|
-
tests
|
|
52
|
-
|
|
49
|
+
extras = {
|
|
50
|
+
"geography": ["GeoAlchemy2", "shapely"],
|
|
51
|
+
"alembic": ["alembic"],
|
|
52
|
+
"tests": ["packaging", "pytz"],
|
|
53
|
+
# Keep the no-op bqstorage extra for backward compatibility.
|
|
54
|
+
# See: https://github.com/googleapis/python-bigquery/issues/757
|
|
55
|
+
"bqstorage": [
|
|
56
|
+
"google-cloud-bigquery-storage >= 2.0.0, <3.0.0dev",
|
|
57
|
+
# Due to an issue in pip's dependency resolver, the `grpc` extra is not
|
|
58
|
+
# installed, even though `google-cloud-bigquery-storage` specifies it
|
|
59
|
+
# as `google-api-core[grpc]`. We thus need to explicitly specify it here.
|
|
60
|
+
# See: https://github.com/googleapis/python-bigquery/issues/83 The
|
|
61
|
+
# grpc.Channel.close() method isn't added until 1.32.0.
|
|
62
|
+
# https://github.com/grpc/grpc/pull/15254
|
|
63
|
+
"grpcio >= 1.47.0, < 2.0dev",
|
|
64
|
+
"grpcio >= 1.49.1, < 2.0dev; python_version>='3.11'",
|
|
65
|
+
"pyarrow >= 3.0.0",
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
extras["all"] = set(itertools.chain.from_iterable(extras.values()))
|
|
54
70
|
|
|
71
|
+
packages = [
|
|
72
|
+
package
|
|
73
|
+
for package in setuptools.find_namespace_packages()
|
|
74
|
+
if package.startswith("sqlalchemy_bigquery")
|
|
75
|
+
] + [
|
|
76
|
+
package
|
|
77
|
+
for package in setuptools.find_namespace_packages("third_party")
|
|
78
|
+
if package.startswith("sqlalchemy_bigquery_vendored")
|
|
79
|
+
]
|
|
80
|
+
|
|
55
81
|
setup(
|
|
56
82
|
name=name,
|
|
57
83
|
version=version,
|
|
@@ -60,7 +86,11 @@ setup(
|
|
|
60
86
|
long_description_content_type="text/x-rst",
|
|
61
87
|
author="The Sqlalchemy-Bigquery Authors",
|
|
62
88
|
author_email="googleapis-packages@google.com",
|
|
63
|
-
|
|
89
|
+
package_dir={
|
|
90
|
+
"sqlalchemy-bigquery": "sqlalchemy_bigquery",
|
|
91
|
+
"sqlalchemy_bigquery_vendored": "third_party/sqlalchemy_bigquery_vendored",
|
|
92
|
+
},
|
|
93
|
+
packages=packages,
|
|
64
94
|
url="https://github.com/googleapis/python-bigquery-sqlalchemy",
|
|
65
95
|
keywords=["bigquery", "sqlalchemy"],
|
|
66
96
|
classifiers=[
|
|
@@ -69,11 +99,11 @@ setup(
|
|
|
69
99
|
"License :: OSI Approved :: MIT License",
|
|
70
100
|
"Programming Language :: Python",
|
|
71
101
|
"Programming Language :: Python :: 3",
|
|
72
|
-
"Programming Language :: Python :: 3.6",
|
|
73
|
-
"Programming Language :: Python :: 3.7",
|
|
74
102
|
"Programming Language :: Python :: 3.8",
|
|
75
103
|
"Programming Language :: Python :: 3.9",
|
|
76
104
|
"Programming Language :: Python :: 3.10",
|
|
105
|
+
"Programming Language :: Python :: 3.11",
|
|
106
|
+
"Programming Language :: Python :: 3.12",
|
|
77
107
|
"Operating System :: OS Independent",
|
|
78
108
|
"Topic :: Database :: Front-Ends",
|
|
79
109
|
],
|
|
@@ -84,19 +114,12 @@ setup(
|
|
|
84
114
|
# Until this issue is closed
|
|
85
115
|
# https://github.com/googleapis/google-cloud-python/issues/10566
|
|
86
116
|
"google-auth>=1.25.0,<3.0.0dev", # Work around pip wack.
|
|
87
|
-
"google-cloud-bigquery>=
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
# Temporarily set maximimum sqlalchemy to a known-working version while
|
|
91
|
-
# we debug failing compliance tests. See:
|
|
92
|
-
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/386
|
|
93
|
-
# and
|
|
94
|
-
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/385
|
|
95
|
-
"sqlalchemy>=1.2.0,<=1.4.27",
|
|
96
|
-
"future",
|
|
117
|
+
"google-cloud-bigquery>=3.3.6,<4.0.0dev",
|
|
118
|
+
"packaging",
|
|
119
|
+
"sqlalchemy>=1.4.16,<3.0.0dev",
|
|
97
120
|
],
|
|
98
121
|
extras_require=extras,
|
|
99
|
-
python_requires=">=3.
|
|
122
|
+
python_requires=">=3.8, <3.13",
|
|
100
123
|
tests_require=["packaging", "pytz"],
|
|
101
124
|
entry_points={
|
|
102
125
|
"sqlalchemy.dialects": ["bigquery = sqlalchemy_bigquery:BigQueryDialect"]
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
SQLAlchemy dialect for Google BigQuery
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
from .version import __version__
|
|
23
|
+
from .version import __version__
|
|
24
24
|
|
|
25
|
-
from .base import BigQueryDialect, dialect
|
|
25
|
+
from .base import BigQueryDialect, dialect
|
|
26
26
|
from ._types import (
|
|
27
27
|
ARRAY,
|
|
28
28
|
BIGNUMERIC,
|
|
@@ -44,6 +44,8 @@ from ._types import (
|
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
__all__ = [
|
|
47
|
+
"__version__",
|
|
48
|
+
"dialect",
|
|
47
49
|
"ARRAY",
|
|
48
50
|
"BIGNUMERIC",
|
|
49
51
|
"BigQueryDialect",
|
|
@@ -66,7 +68,7 @@ __all__ = [
|
|
|
66
68
|
|
|
67
69
|
try:
|
|
68
70
|
from .geography import GEOGRAPHY, WKB, WKT # noqa
|
|
69
|
-
except ImportError:
|
|
71
|
+
except ImportError: # pragma: NO COVER
|
|
70
72
|
pass
|
|
71
73
|
else:
|
|
72
74
|
__all__.extend(["GEOGRAPHY", "WKB", "WKT"])
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import functools
|
|
8
8
|
import re
|
|
9
|
+
from typing import Optional
|
|
9
10
|
|
|
10
11
|
from google.api_core import client_info
|
|
11
12
|
import google.auth
|
|
@@ -24,19 +25,48 @@ SCOPES = (
|
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def google_client_info(
|
|
28
|
-
user_agent =
|
|
28
|
+
def google_client_info(
|
|
29
|
+
user_agent: Optional[str] = None,
|
|
30
|
+
) -> google.api_core.client_info.ClientInfo:
|
|
31
|
+
"""
|
|
32
|
+
Return a client_info object, with an optional user agent
|
|
33
|
+
string. If user_agent is None, use a default value.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
if user_agent is None:
|
|
37
|
+
user_agent = USER_AGENT_TEMPLATE.format(sqlalchemy.__version__)
|
|
29
38
|
return client_info.ClientInfo(user_agent=user_agent)
|
|
30
39
|
|
|
31
40
|
|
|
32
41
|
def create_bigquery_client(
|
|
33
|
-
credentials_info=None,
|
|
34
|
-
credentials_path=None,
|
|
35
|
-
credentials_base64=None,
|
|
36
|
-
default_query_job_config=None,
|
|
37
|
-
location=None,
|
|
38
|
-
project_id=None,
|
|
39
|
-
|
|
42
|
+
credentials_info: Optional[dict] = None,
|
|
43
|
+
credentials_path: Optional[str] = None,
|
|
44
|
+
credentials_base64: Optional[str] = None,
|
|
45
|
+
default_query_job_config: Optional[google.cloud.bigquery.job.QueryJobConfig] = None,
|
|
46
|
+
location: Optional[str] = None,
|
|
47
|
+
project_id: Optional[str] = None,
|
|
48
|
+
user_agent: Optional[google.api_core.client_info.ClientInfo] = None,
|
|
49
|
+
) -> google.cloud.bigquery.Client:
|
|
50
|
+
"""Construct a BigQuery client object.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
credentials_info Optional[dict]:
|
|
54
|
+
credentials_path Optional[str]:
|
|
55
|
+
credentials_base64 Optional[str]:
|
|
56
|
+
default_query_job_config (Optional[google.cloud.bigquery.job.QueryJobConfig]):
|
|
57
|
+
Default ``QueryJobConfig``.
|
|
58
|
+
Will be merged into job configs passed into the ``query`` method.
|
|
59
|
+
location (Optional[str]):
|
|
60
|
+
Default location for jobs / datasets / tables.
|
|
61
|
+
project_id (Optional[str]):
|
|
62
|
+
Project ID for the project which the client acts on behalf of.
|
|
63
|
+
user_agent (Optional[google.api_core.client_info.ClientInfo]):
|
|
64
|
+
The client info used to send a user-agent string along with API
|
|
65
|
+
requests. If ``None``, then default info will be used. Generally,
|
|
66
|
+
you only need to set this if you're developing your own library
|
|
67
|
+
or partner tool.
|
|
68
|
+
"""
|
|
69
|
+
|
|
40
70
|
default_project = None
|
|
41
71
|
|
|
42
72
|
if credentials_base64:
|
|
@@ -60,8 +90,10 @@ def create_bigquery_client(
|
|
|
60
90
|
if project_id is None:
|
|
61
91
|
project_id = default_project
|
|
62
92
|
|
|
93
|
+
client_info = google_client_info(user_agent=user_agent)
|
|
94
|
+
|
|
63
95
|
return bigquery.Client(
|
|
64
|
-
client_info=
|
|
96
|
+
client_info=client_info,
|
|
65
97
|
project=project_id,
|
|
66
98
|
credentials=credentials,
|
|
67
99
|
location=location,
|