sqlalchemy-bigquery 1.17.1__tar.gz → 1.17.3__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.1/sqlalchemy_bigquery.egg-info → sqlalchemy_bigquery-1.17.3}/PKG-INFO +11 -13
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/setup.py +3 -7
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/base.py +10 -10
- sqlalchemy_bigquery-1.17.3/sqlalchemy_bigquery/provision.py +95 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/version.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3/sqlalchemy_bigquery.egg-info}/PKG-INFO +11 -13
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/SOURCES.txt +2 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/requires.txt +9 -15
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/sqlalchemy_dialect_compliance/conftest.py +59 -15
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py +25 -16
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/conftest.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/fauxdbi.py +1 -2
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_comments.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_compiler.py +40 -5
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_compliance.py +2 -2
- sqlalchemy_bigquery-1.17.3/tests/unit/test_provision.py +128 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_select.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/AUTHORS +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/LICENSE +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/MANIFEST.in +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/README.rst +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/pyproject.toml +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/setup.cfg +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/__init__.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/_helpers.py +2 -2
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/_struct.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/_types.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/geography.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/parse_url.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/requirements.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/entry_points.txt +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/top_level.txt +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/conftest.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/sqlalchemy_dialect_compliance/README.rst +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/conftest.py +2 -2
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/data/sample.json +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/data/sample_one_row.json +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/data/schema.json +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test__struct.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_alembic.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_geography.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_helpers.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_sqlalchemy_bigquery.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_sqlalchemy_bigquery_remote.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test__struct.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test__types.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_alembic.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_catalog_functions.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_dialect_types.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_engine.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_geography.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_helpers.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_like_reescape.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_parse_url.py +1 -1
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_sqlalchemy_bigquery.py +2 -2
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_table_options.py +2 -2
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_version.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_view.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/py.typed +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/AUTHORS +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/LICENSE +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/__init__.py +0 -0
- {sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/base.py +0 -0
{sqlalchemy_bigquery-1.17.1/sqlalchemy_bigquery.egg-info → sqlalchemy_bigquery-1.17.3}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 1.17.
|
|
3
|
+
Version: 1.17.3
|
|
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
|
|
@@ -24,7 +24,7 @@ Requires-Python: >=3.10
|
|
|
24
24
|
Description-Content-Type: text/x-rst
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
License-File: AUTHORS
|
|
27
|
-
Requires-Dist: google-api-core
|
|
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
29
|
Requires-Dist: google-cloud-bigquery<4.0.0,>=3.20.0
|
|
30
30
|
Requires-Dist: packaging
|
|
@@ -38,22 +38,20 @@ Provides-Extra: tests
|
|
|
38
38
|
Requires-Dist: packaging; extra == "tests"
|
|
39
39
|
Requires-Dist: pytz; extra == "tests"
|
|
40
40
|
Provides-Extra: bqstorage
|
|
41
|
-
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.
|
|
42
|
-
Requires-Dist: grpcio<2.0.0,>=1.
|
|
43
|
-
Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version == "3.11" and extra == "bqstorage"
|
|
41
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "bqstorage"
|
|
42
|
+
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "bqstorage"
|
|
44
43
|
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "bqstorage"
|
|
45
44
|
Requires-Dist: pyarrow>=6.0.0; extra == "bqstorage"
|
|
46
45
|
Provides-Extra: all
|
|
47
|
-
Requires-Dist:
|
|
48
|
-
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.18.0; extra == "all"
|
|
49
|
-
Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version == "3.11" and extra == "all"
|
|
50
|
-
Requires-Dist: shapely; extra == "all"
|
|
51
|
-
Requires-Dist: pyarrow>=6.0.0; extra == "all"
|
|
46
|
+
Requires-Dist: packaging; extra == "all"
|
|
52
47
|
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "all"
|
|
53
|
-
Requires-Dist:
|
|
54
|
-
Requires-Dist:
|
|
48
|
+
Requires-Dist: pyarrow>=6.0.0; extra == "all"
|
|
49
|
+
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "all"
|
|
55
50
|
Requires-Dist: alembic; extra == "all"
|
|
56
|
-
Requires-Dist:
|
|
51
|
+
Requires-Dist: pytz; extra == "all"
|
|
52
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "all"
|
|
53
|
+
Requires-Dist: GeoAlchemy2; extra == "all"
|
|
54
|
+
Requires-Dist: shapely; extra == "all"
|
|
57
55
|
Dynamic: author
|
|
58
56
|
Dynamic: author-email
|
|
59
57
|
Dynamic: classifier
|
|
@@ -54,15 +54,14 @@ extras = {
|
|
|
54
54
|
# Keep the no-op bqstorage extra for backward compatibility.
|
|
55
55
|
# See: https://github.com/googleapis/python-bigquery/issues/757
|
|
56
56
|
"bqstorage": [
|
|
57
|
-
"google-cloud-bigquery-storage >= 2.
|
|
57
|
+
"google-cloud-bigquery-storage >= 2.29.0, <3.0.0",
|
|
58
58
|
# Due to an issue in pip's dependency resolver, the `grpc` extra is not
|
|
59
59
|
# installed, even though `google-cloud-bigquery-storage` specifies it
|
|
60
60
|
# as `google-api-core[grpc]`. We thus need to explicitly specify it here.
|
|
61
61
|
# See: https://github.com/googleapis/python-bigquery/issues/83 The
|
|
62
62
|
# grpc.Channel.close() method isn't added until 1.32.0.
|
|
63
63
|
# https://github.com/grpc/grpc/pull/15254
|
|
64
|
-
"grpcio >= 1.
|
|
65
|
-
"grpcio >= 1.49.1, < 2.0.0; python_version =='3.11'",
|
|
64
|
+
"grpcio >= 1.59.0, < 2.0.0",
|
|
66
65
|
"grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'",
|
|
67
66
|
"pyarrow >= 6.0.0",
|
|
68
67
|
],
|
|
@@ -111,10 +110,7 @@ setup(
|
|
|
111
110
|
],
|
|
112
111
|
platforms="Posix; MacOS X; Windows",
|
|
113
112
|
install_requires=[
|
|
114
|
-
"google-api-core >= 2.
|
|
115
|
-
# NOTE: Maintainers, please do not require google-auth>=2.x.x
|
|
116
|
-
# Until this issue is closed
|
|
117
|
-
# https://github.com/googleapis/google-cloud-python/issues/10566
|
|
113
|
+
"google-api-core >= 2.25.0, <3.0.0",
|
|
118
114
|
"google-auth>=2.14.1,<3.0.0",
|
|
119
115
|
"google-cloud-bigquery>=3.20.0,<4.0.0",
|
|
120
116
|
"packaging",
|
|
@@ -20,14 +20,21 @@
|
|
|
20
20
|
"""Integration between SQLAlchemy and BigQuery."""
|
|
21
21
|
|
|
22
22
|
import datetime
|
|
23
|
-
from decimal import Decimal
|
|
24
23
|
import operator
|
|
25
24
|
import random
|
|
26
25
|
import re
|
|
27
26
|
import uuid
|
|
27
|
+
from decimal import Decimal
|
|
28
28
|
|
|
29
|
-
from google import auth
|
|
30
29
|
import google.api_core.exceptions
|
|
30
|
+
import packaging.version
|
|
31
|
+
import sqlalchemy
|
|
32
|
+
import sqlalchemy.sql.expression
|
|
33
|
+
import sqlalchemy.sql.functions
|
|
34
|
+
import sqlalchemy.sql.sqltypes
|
|
35
|
+
import sqlalchemy.sql.type_api
|
|
36
|
+
import sqlalchemy_bigquery_vendored.sqlalchemy.postgresql.base as vendored_postgresql
|
|
37
|
+
from google import auth
|
|
31
38
|
from google.api_core.exceptions import NotFound
|
|
32
39
|
from google.cloud.bigquery import ConnectionProperty, QueryJobConfig, dbapi
|
|
33
40
|
from google.cloud.bigquery.table import (
|
|
@@ -35,8 +42,6 @@ from google.cloud.bigquery.table import (
|
|
|
35
42
|
TableReference,
|
|
36
43
|
TimePartitioning,
|
|
37
44
|
)
|
|
38
|
-
import packaging.version
|
|
39
|
-
import sqlalchemy
|
|
40
45
|
from sqlalchemy import util
|
|
41
46
|
from sqlalchemy.engine.base import Engine
|
|
42
47
|
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
|
|
@@ -49,14 +54,9 @@ from sqlalchemy.sql.compiler import (
|
|
|
49
54
|
IdentifierPreparer,
|
|
50
55
|
SQLCompiler,
|
|
51
56
|
)
|
|
52
|
-
import sqlalchemy.sql.expression
|
|
53
|
-
import sqlalchemy.sql.functions
|
|
54
57
|
from sqlalchemy.sql.schema import Column, Table
|
|
55
58
|
from sqlalchemy.sql.selectable import CTE
|
|
56
|
-
import sqlalchemy.sql.sqltypes
|
|
57
59
|
from sqlalchemy.sql.sqltypes import Integer, NullType, Numeric, String
|
|
58
|
-
import sqlalchemy.sql.type_api
|
|
59
|
-
import sqlalchemy_bigquery_vendored.sqlalchemy.postgresql.base as vendored_postgresql
|
|
60
60
|
|
|
61
61
|
from . import _helpers, _types
|
|
62
62
|
from .parse_url import parse_url
|
|
@@ -600,7 +600,7 @@ class BigQueryTypeCompiler(GenericTypeCompiler):
|
|
|
600
600
|
def visit_FLOAT(self, type_, **kw):
|
|
601
601
|
return "FLOAT64"
|
|
602
602
|
|
|
603
|
-
visit_REAL = visit_FLOAT
|
|
603
|
+
visit_REAL = visit_DOUBLE = visit_DOUBLE_PRECISION = visit_FLOAT
|
|
604
604
|
|
|
605
605
|
def visit_STRING(self, type_, **kw):
|
|
606
606
|
if (type_.length is not None) and isinstance(
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright 2026 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import contextlib
|
|
16
|
+
import datetime
|
|
17
|
+
import os
|
|
18
|
+
import uuid
|
|
19
|
+
|
|
20
|
+
import google.cloud.bigquery
|
|
21
|
+
from sqlalchemy.engine import make_url
|
|
22
|
+
from sqlalchemy.testing.provision import (
|
|
23
|
+
create_db,
|
|
24
|
+
drop_db,
|
|
25
|
+
follower_url_from_main,
|
|
26
|
+
generate_driver_url,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
import test_utils.prefixer # pragma: NO COVER
|
|
31
|
+
|
|
32
|
+
prefixer = test_utils.prefixer.Prefixer( # pragma: NO COVER
|
|
33
|
+
"python-bigquery-sqlalchemy", "tests/compliance"
|
|
34
|
+
)
|
|
35
|
+
except ImportError:
|
|
36
|
+
prefixer = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _dataset_id_from_ident(ident: str) -> str:
|
|
40
|
+
"""Derive a deterministic BigQuery dataset ID for an xdist follower ident."""
|
|
41
|
+
run_prefix = os.environ.get("COMPLIANCE_RUN_PREFIX")
|
|
42
|
+
if not run_prefix:
|
|
43
|
+
if prefixer:
|
|
44
|
+
run_prefix = prefixer.create_prefix()
|
|
45
|
+
else:
|
|
46
|
+
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d%H%M%S")
|
|
47
|
+
run_prefix = f"python_bigquery_sqlalchemy_tests_compliance_{now}_{uuid.uuid4().hex[:6]}"
|
|
48
|
+
os.environ["COMPLIANCE_RUN_PREFIX"] = run_prefix
|
|
49
|
+
return f"{run_prefix}_{ident}"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@generate_driver_url.for_db("bigquery")
|
|
53
|
+
def _bigquery_generate_driver_url(url, driver, query_str):
|
|
54
|
+
url = make_url(url)
|
|
55
|
+
if driver and driver != "bigquery":
|
|
56
|
+
new_url = url.set(drivername=f"bigquery+{driver}")
|
|
57
|
+
else:
|
|
58
|
+
new_url = url.set(drivername="bigquery")
|
|
59
|
+
if query_str:
|
|
60
|
+
new_url = new_url.update_query_string(query_str)
|
|
61
|
+
return new_url
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@follower_url_from_main.for_db("bigquery")
|
|
65
|
+
def _bigquery_follower_url_from_main(url, ident):
|
|
66
|
+
url = make_url(url)
|
|
67
|
+
dataset_id = _dataset_id_from_ident(ident)
|
|
68
|
+
return url.set(database=dataset_id)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def ensure_dataset(dataset_id: str) -> None:
|
|
72
|
+
"""Ensure a BigQuery dataset exists with a 1-hour expiration safety net."""
|
|
73
|
+
with contextlib.closing(google.cloud.bigquery.Client()) as client:
|
|
74
|
+
dataset_ref = google.cloud.bigquery.DatasetReference(client.project, dataset_id)
|
|
75
|
+
dataset = google.cloud.bigquery.Dataset(dataset_ref)
|
|
76
|
+
dataset.default_table_expiration_ms = 3600 * 1000
|
|
77
|
+
client.create_dataset(dataset, exists_ok=True)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def drop_dataset(dataset_id: str) -> None:
|
|
81
|
+
"""Drop a BigQuery dataset and its contents if it exists."""
|
|
82
|
+
with contextlib.closing(google.cloud.bigquery.Client()) as client:
|
|
83
|
+
client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=True)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@create_db.for_db("bigquery")
|
|
87
|
+
def _bigquery_create_db(cfg, eng, ident):
|
|
88
|
+
dataset_id = _dataset_id_from_ident(ident)
|
|
89
|
+
ensure_dataset(dataset_id)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@drop_db.for_db("bigquery")
|
|
93
|
+
def _bigquery_drop_db(cfg, eng, ident):
|
|
94
|
+
dataset_id = _dataset_id_from_ident(ident)
|
|
95
|
+
drop_dataset(dataset_id)
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3/sqlalchemy_bigquery.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 1.17.
|
|
3
|
+
Version: 1.17.3
|
|
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
|
|
@@ -24,7 +24,7 @@ Requires-Python: >=3.10
|
|
|
24
24
|
Description-Content-Type: text/x-rst
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
License-File: AUTHORS
|
|
27
|
-
Requires-Dist: google-api-core
|
|
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
29
|
Requires-Dist: google-cloud-bigquery<4.0.0,>=3.20.0
|
|
30
30
|
Requires-Dist: packaging
|
|
@@ -38,22 +38,20 @@ Provides-Extra: tests
|
|
|
38
38
|
Requires-Dist: packaging; extra == "tests"
|
|
39
39
|
Requires-Dist: pytz; extra == "tests"
|
|
40
40
|
Provides-Extra: bqstorage
|
|
41
|
-
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.
|
|
42
|
-
Requires-Dist: grpcio<2.0.0,>=1.
|
|
43
|
-
Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version == "3.11" and extra == "bqstorage"
|
|
41
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "bqstorage"
|
|
42
|
+
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "bqstorage"
|
|
44
43
|
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "bqstorage"
|
|
45
44
|
Requires-Dist: pyarrow>=6.0.0; extra == "bqstorage"
|
|
46
45
|
Provides-Extra: all
|
|
47
|
-
Requires-Dist:
|
|
48
|
-
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.18.0; extra == "all"
|
|
49
|
-
Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version == "3.11" and extra == "all"
|
|
50
|
-
Requires-Dist: shapely; extra == "all"
|
|
51
|
-
Requires-Dist: pyarrow>=6.0.0; extra == "all"
|
|
46
|
+
Requires-Dist: packaging; extra == "all"
|
|
52
47
|
Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14" and extra == "all"
|
|
53
|
-
Requires-Dist:
|
|
54
|
-
Requires-Dist:
|
|
48
|
+
Requires-Dist: pyarrow>=6.0.0; extra == "all"
|
|
49
|
+
Requires-Dist: grpcio<2.0.0,>=1.59.0; extra == "all"
|
|
55
50
|
Requires-Dist: alembic; extra == "all"
|
|
56
|
-
Requires-Dist:
|
|
51
|
+
Requires-Dist: pytz; extra == "all"
|
|
52
|
+
Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.29.0; extra == "all"
|
|
53
|
+
Requires-Dist: GeoAlchemy2; extra == "all"
|
|
54
|
+
Requires-Dist: shapely; extra == "all"
|
|
57
55
|
Dynamic: author
|
|
58
56
|
Dynamic: author-email
|
|
59
57
|
Dynamic: classifier
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/SOURCES.txt
RENAMED
|
@@ -12,6 +12,7 @@ sqlalchemy_bigquery/_types.py
|
|
|
12
12
|
sqlalchemy_bigquery/base.py
|
|
13
13
|
sqlalchemy_bigquery/geography.py
|
|
14
14
|
sqlalchemy_bigquery/parse_url.py
|
|
15
|
+
sqlalchemy_bigquery/provision.py
|
|
15
16
|
sqlalchemy_bigquery/requirements.py
|
|
16
17
|
sqlalchemy_bigquery/version.py
|
|
17
18
|
sqlalchemy_bigquery.egg-info/PKG-INFO
|
|
@@ -52,6 +53,7 @@ tests/unit/test_geography.py
|
|
|
52
53
|
tests/unit/test_helpers.py
|
|
53
54
|
tests/unit/test_like_reescape.py
|
|
54
55
|
tests/unit/test_parse_url.py
|
|
56
|
+
tests/unit/test_provision.py
|
|
55
57
|
tests/unit/test_select.py
|
|
56
58
|
tests/unit/test_sqlalchemy_bigquery.py
|
|
57
59
|
tests/unit/test_table_options.py
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/requires.txt
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
google-api-core
|
|
1
|
+
google-api-core<3.0.0,>=2.25.0
|
|
2
2
|
google-auth<3.0.0,>=2.14.1
|
|
3
3
|
google-cloud-bigquery<4.0.0,>=3.20.0
|
|
4
4
|
packaging
|
|
@@ -8,29 +8,23 @@ sqlalchemy<3.0.0,>=1.4.16
|
|
|
8
8
|
alembic
|
|
9
9
|
|
|
10
10
|
[all]
|
|
11
|
-
|
|
12
|
-
google-cloud-bigquery-storage<3.0.0,>=2.18.0
|
|
13
|
-
shapely
|
|
11
|
+
packaging
|
|
14
12
|
pyarrow>=6.0.0
|
|
15
|
-
grpcio<2.0.0,>=1.
|
|
16
|
-
pytz
|
|
13
|
+
grpcio<2.0.0,>=1.59.0
|
|
17
14
|
alembic
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
pytz
|
|
16
|
+
google-cloud-bigquery-storage<3.0.0,>=2.29.0
|
|
17
|
+
GeoAlchemy2
|
|
18
|
+
shapely
|
|
22
19
|
|
|
23
20
|
[all:python_version >= "3.14"]
|
|
24
21
|
grpcio<2.0.0,>=1.75.1
|
|
25
22
|
|
|
26
23
|
[bqstorage]
|
|
27
|
-
google-cloud-bigquery-storage<3.0.0,>=2.
|
|
28
|
-
grpcio<2.0.0,>=1.
|
|
24
|
+
google-cloud-bigquery-storage<3.0.0,>=2.29.0
|
|
25
|
+
grpcio<2.0.0,>=1.59.0
|
|
29
26
|
pyarrow>=6.0.0
|
|
30
27
|
|
|
31
|
-
[bqstorage:python_version == "3.11"]
|
|
32
|
-
grpcio<2.0.0,>=1.49.1
|
|
33
|
-
|
|
34
28
|
[bqstorage:python_version >= "3.14"]
|
|
35
29
|
grpcio<2.0.0,>=1.75.1
|
|
36
30
|
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
19
|
|
|
20
20
|
import contextlib
|
|
21
|
+
import os
|
|
21
22
|
import re
|
|
22
23
|
import traceback
|
|
23
24
|
|
|
24
25
|
import google.cloud.bigquery.dbapi.connection
|
|
25
|
-
from sqlalchemy.testing import config
|
|
26
|
-
from sqlalchemy.testing.plugin.pytestplugin import * # noqa
|
|
27
|
-
from sqlalchemy.testing.plugin.pytestplugin import (
|
|
28
|
-
pytest_sessionfinish as _pytest_sessionfinish,
|
|
29
|
-
)
|
|
30
|
-
from sqlalchemy.testing.plugin.pytestplugin import (
|
|
31
|
-
pytest_sessionstart as _pytest_sessionstart,
|
|
32
|
-
)
|
|
33
26
|
import test_utils.prefixer
|
|
27
|
+
from sqlalchemy.testing import config
|
|
28
|
+
from sqlalchemy.testing.plugin import pytestplugin
|
|
29
|
+
|
|
30
|
+
# flake8: F401, F403 are ignored because SQLAlchemy requires importing its testing
|
|
31
|
+
# plugin fixtures and hooks directly into the pytest conftest namespace.
|
|
32
|
+
from sqlalchemy.testing.plugin.pytestplugin import * # noqa: F401, F403
|
|
34
33
|
|
|
35
34
|
import sqlalchemy_bigquery.base
|
|
35
|
+
import sqlalchemy_bigquery.provision
|
|
36
36
|
|
|
37
37
|
sqlalchemy_bigquery.BigQueryDialect.preexecute_autoincrement_sequences = True
|
|
38
38
|
|
|
@@ -54,6 +54,7 @@ _where = re.compile(r"\s+WHERE\s+", re.IGNORECASE).search
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
def visit_delete(self, delete_stmt, *args, **kw):
|
|
57
|
+
"""Compile DELETE statements, appending WHERE true during test teardown."""
|
|
57
58
|
text = super(sqlalchemy_bigquery.base.BigQueryCompiler, self).visit_delete(
|
|
58
59
|
delete_stmt, *args, **kw
|
|
59
60
|
)
|
|
@@ -69,19 +70,62 @@ def visit_delete(self, delete_stmt, *args, **kw):
|
|
|
69
70
|
sqlalchemy_bigquery.base.BigQueryCompiler.visit_delete = visit_delete
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
def _resolve_dataset_id(cfg) -> str:
|
|
74
|
+
"""Resolve the dataset ID for the current runner process (worker or master)."""
|
|
75
|
+
run_prefix = os.environ["COMPLIANCE_RUN_PREFIX"]
|
|
76
|
+
if hasattr(cfg, "workerinput"):
|
|
77
|
+
ident = cfg.workerinput.get("follower_ident")
|
|
78
|
+
if ident:
|
|
79
|
+
return sqlalchemy_bigquery.provision._dataset_id_from_ident(ident)
|
|
80
|
+
return f"{run_prefix}_worker"
|
|
81
|
+
return f"{run_prefix}_master"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def pytest_configure(config):
|
|
85
|
+
"""Configure pytest session, establishing compliance run prefix and target dburi."""
|
|
86
|
+
if hasattr(config, "workerinput"):
|
|
87
|
+
prefix = config.workerinput.get("compliance_run_prefix")
|
|
88
|
+
if prefix:
|
|
89
|
+
os.environ["COMPLIANCE_RUN_PREFIX"] = prefix
|
|
90
|
+
else:
|
|
91
|
+
if "COMPLIANCE_RUN_PREFIX" not in os.environ:
|
|
92
|
+
os.environ["COMPLIANCE_RUN_PREFIX"] = prefixer.create_prefix()
|
|
93
|
+
|
|
94
|
+
dataset_id = _resolve_dataset_id(config)
|
|
95
|
+
config.option.dburi = [f"bigquery:///{dataset_id}"]
|
|
96
|
+
pytestplugin.pytest_configure(config)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def pytest_configure_node(node):
|
|
100
|
+
"""Propagate the compliance run prefix from the controller to worker nodes."""
|
|
101
|
+
node.workerinput["compliance_run_prefix"] = os.environ.get("COMPLIANCE_RUN_PREFIX")
|
|
102
|
+
|
|
103
|
+
|
|
72
104
|
def pytest_sessionstart(session):
|
|
73
|
-
|
|
105
|
+
"""Ensure the target dataset exists before running compliance tests in the session."""
|
|
106
|
+
dataset_id = _resolve_dataset_id(session.config)
|
|
74
107
|
session.config.option.dburi = [f"bigquery:///{dataset_id}"]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_pytest_sessionstart(session)
|
|
108
|
+
sqlalchemy_bigquery.provision.ensure_dataset(dataset_id)
|
|
109
|
+
pytestplugin.pytest_sessionstart(session)
|
|
78
110
|
|
|
79
111
|
|
|
80
112
|
def pytest_sessionfinish(session):
|
|
81
|
-
|
|
82
|
-
|
|
113
|
+
"""Tear down datasets and clean up leaked test datasets after session completion."""
|
|
114
|
+
if hasattr(session.config, "workerinput"):
|
|
115
|
+
# Worker dataset teardown is handled by provision.drop_follower_db
|
|
116
|
+
# on the controller node.
|
|
117
|
+
pytestplugin.pytest_sessionfinish(session)
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
pytestplugin.pytest_sessionfinish(session)
|
|
121
|
+
run_prefix = os.environ.get("COMPLIANCE_RUN_PREFIX")
|
|
122
|
+
db = getattr(session.config, "db", None) or getattr(config, "db", None)
|
|
123
|
+
if db is not None and hasattr(db.dialect, "dataset_id"):
|
|
124
|
+
sqlalchemy_bigquery.provision.drop_dataset(db.dialect.dataset_id)
|
|
125
|
+
elif run_prefix:
|
|
126
|
+
sqlalchemy_bigquery.provision.drop_dataset(f"{run_prefix}_master")
|
|
127
|
+
|
|
83
128
|
with contextlib.closing(google.cloud.bigquery.Client()) as client:
|
|
84
|
-
client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=True)
|
|
85
129
|
for dataset in client.list_datasets():
|
|
86
130
|
if prefixer.should_cleanup(dataset.dataset_id):
|
|
87
131
|
client.delete_dataset(dataset, delete_contents=True, not_found_ok=True)
|
|
@@ -25,33 +25,34 @@ import packaging.version
|
|
|
25
25
|
import pytest
|
|
26
26
|
import pytz
|
|
27
27
|
import sqlalchemy
|
|
28
|
-
from sqlalchemy import and_
|
|
29
28
|
import sqlalchemy.sql.sqltypes
|
|
29
|
+
import sqlalchemy.testing.suite.test_types
|
|
30
|
+
from sqlalchemy import and_
|
|
30
31
|
from sqlalchemy.testing import config, util
|
|
31
32
|
from sqlalchemy.testing.assertions import eq_
|
|
33
|
+
from sqlalchemy.testing.suite import * # noqa
|
|
32
34
|
from sqlalchemy.testing.suite import (
|
|
35
|
+
Column,
|
|
36
|
+
DistinctOnTest,
|
|
37
|
+
HasIndexTest,
|
|
38
|
+
IdentityAutoincrementTest,
|
|
33
39
|
Integer,
|
|
34
40
|
LongNameBlowoutTest,
|
|
35
41
|
PostCompileParamsTest,
|
|
36
42
|
QuotedNameArgumentTest,
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
String,
|
|
44
|
+
Table,
|
|
39
45
|
WindowFunctionTest,
|
|
40
46
|
bindparam,
|
|
41
47
|
exists,
|
|
42
48
|
select,
|
|
43
49
|
testing,
|
|
44
50
|
)
|
|
45
|
-
from sqlalchemy.testing.suite import * # noqa
|
|
46
51
|
from sqlalchemy.testing.suite import CTETest as _CTETest
|
|
47
|
-
from sqlalchemy.testing.suite import Column
|
|
48
|
-
from sqlalchemy.testing.suite import DistinctOnTest
|
|
49
|
-
from sqlalchemy.testing.suite import ExistsTest as _ExistsTest
|
|
50
|
-
from sqlalchemy.testing.suite import HasIndexTest, IdentityAutoincrementTest
|
|
51
|
-
from sqlalchemy.testing.suite import InsertBehaviorTest as _InsertBehaviorTest
|
|
52
|
-
from sqlalchemy.testing.suite import String, Table
|
|
53
52
|
from sqlalchemy.testing.suite import DifficultParametersTest as _DifficultParametersTest
|
|
53
|
+
from sqlalchemy.testing.suite import ExistsTest as _ExistsTest
|
|
54
54
|
from sqlalchemy.testing.suite import FetchLimitOffsetTest as _FetchLimitOffsetTest
|
|
55
|
+
from sqlalchemy.testing.suite import InsertBehaviorTest as _InsertBehaviorTest
|
|
55
56
|
from sqlalchemy.testing.suite import SimpleUpdateDeleteTest as _SimpleUpdateDeleteTest
|
|
56
57
|
from sqlalchemy.testing.suite import (
|
|
57
58
|
TimestampMicrosecondsTest as _TimestampMicrosecondsTest,
|
|
@@ -62,7 +63,6 @@ from sqlalchemy.testing.suite.test_reflection import (
|
|
|
62
63
|
ComponentReflectionTestExtra,
|
|
63
64
|
HasTableTest,
|
|
64
65
|
)
|
|
65
|
-
import sqlalchemy.testing.suite.test_types
|
|
66
66
|
from sqlalchemy.testing.suite.test_types import ArrayTest
|
|
67
67
|
|
|
68
68
|
if packaging.version.parse(sqlalchemy.__version__) >= packaging.version.parse("2.0"):
|
|
@@ -637,9 +637,18 @@ del HasTableTest.test_has_table_cache # TODO confirm whether BQ has table cachi
|
|
|
637
637
|
del DistinctOnTest # expects unquoted table names.
|
|
638
638
|
del HasIndexTest # BQ doesn't do the indexes that SQLA is loooking for.
|
|
639
639
|
del IdentityAutoincrementTest # BQ doesn't do autoincrement
|
|
640
|
-
del LongNameBlowoutTest # Requires features (indexes, primary keys, etc., that BigQuery doesn't have.
|
|
641
|
-
del PostCompileParamsTest # BQ adds backticks to bind parameters, causing failure of tests TODO: fix this?
|
|
642
|
-
del QuotedNameArgumentTest # Quotes aren't allowed in BigQuery table names.
|
|
643
640
|
del (
|
|
644
|
-
|
|
645
|
-
) #
|
|
641
|
+
LongNameBlowoutTest
|
|
642
|
+
) # Requires features (indexes, primary keys, etc., that BigQuery doesn't have.
|
|
643
|
+
del (
|
|
644
|
+
PostCompileParamsTest
|
|
645
|
+
) # BQ adds backticks to bind parameters, causing failure of tests TODO: fix this?
|
|
646
|
+
del QuotedNameArgumentTest # Quotes aren't allowed in BigQuery table names.
|
|
647
|
+
# Test expects BQ to return sorted results, which it does not do. (renamed to _w_caching in SQLAlchemy 2.1+)
|
|
648
|
+
for _test_name in ("test_window_rows_between", "test_window_rows_between_w_caching"):
|
|
649
|
+
if hasattr(WindowFunctionTest, _test_name):
|
|
650
|
+
delattr(WindowFunctionTest, _test_name)
|
|
651
|
+
|
|
652
|
+
# BigQuery requires dataset qualification for views, which TableViaSelectTest does not provide.
|
|
653
|
+
if "TableViaSelectTest" in globals():
|
|
654
|
+
del TableViaSelectTest
|
|
@@ -68,7 +68,7 @@ def faux_conn():
|
|
|
68
68
|
|
|
69
69
|
conn.ex = ex
|
|
70
70
|
|
|
71
|
-
ex("create table comments
|
|
71
|
+
ex("create table comments (key string primary key, comment string)")
|
|
72
72
|
|
|
73
73
|
# Modernize faux_conn for SQLAlchemy 2.0+ by allowing it to execute
|
|
74
74
|
# Compiled objects (common in this test suite)
|
|
@@ -432,8 +432,7 @@ class FauxClient:
|
|
|
432
432
|
|
|
433
433
|
def __get_comments(self, cursor, table_name):
|
|
434
434
|
cursor.execute(
|
|
435
|
-
f"select key, comment"
|
|
436
|
-
f" from comments where key like {repr(table_name + '%')}"
|
|
435
|
+
f"select key, comment from comments where key like {repr(table_name + '%')}"
|
|
437
436
|
)
|
|
438
437
|
|
|
439
438
|
return {key.split(",")[1]: comment for key, comment in cursor}
|
|
@@ -79,7 +79,7 @@ def test_table_friendly_name_dialect_option(faux_conn):
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
assert " ".join(faux_conn.test_data["execute"][-1][0].strip().split()) == (
|
|
82
|
-
"CREATE TABLE `some_table` ( `id` INT64 )
|
|
82
|
+
"CREATE TABLE `some_table` ( `id` INT64 ) OPTIONS(friendly_name='bob')"
|
|
83
83
|
)
|
|
84
84
|
|
|
85
85
|
|
|
@@ -58,7 +58,7 @@ def test_constraints_are_ignored(faux_conn, metadata):
|
|
|
58
58
|
)
|
|
59
59
|
metadata.create_all(faux_conn.engine)
|
|
60
60
|
assert " ".join(faux_conn.test_data["execute"][-1][0].strip().split()) == (
|
|
61
|
-
"CREATE TABLE `some_table`
|
|
61
|
+
"CREATE TABLE `some_table` ( `id` INT64 NOT NULL, `ref_id` INT64 )"
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
|
|
@@ -111,8 +111,7 @@ def test_no_alias_for_known_tables_cte(faux_conn, metadata):
|
|
|
111
111
|
q = sqlalchemy.select(table.c.foo, F.unnest(table.c.bars).column_valued("bar"))
|
|
112
112
|
|
|
113
113
|
expected_initial_sql = (
|
|
114
|
-
"SELECT `table1`.`foo`, `bar` \
|
|
115
|
-
"FROM `table1`, unnest(`table1`.`bars`) AS `bar`"
|
|
114
|
+
"SELECT `table1`.`foo`, `bar` \nFROM `table1`, unnest(`table1`.`bars`) AS `bar`"
|
|
116
115
|
)
|
|
117
116
|
found_initial_sql = q.compile(faux_conn).string
|
|
118
117
|
assert found_initial_sql == expected_initial_sql
|
|
@@ -338,8 +337,7 @@ def test_grouping_ops_vs_single_column(faux_conn, table, grouping_op, grouping_o
|
|
|
338
337
|
found_sql = q.compile(faux_conn).string
|
|
339
338
|
|
|
340
339
|
expected_sql = (
|
|
341
|
-
f"SELECT `table1`.`foo` \
|
|
342
|
-
f"FROM `table1` GROUP BY {grouping_op}(`table1`.`foo`)"
|
|
340
|
+
f"SELECT `table1`.`foo` \nFROM `table1` GROUP BY {grouping_op}(`table1`.`foo`)"
|
|
343
341
|
)
|
|
344
342
|
|
|
345
343
|
assert found_sql == expected_sql
|
|
@@ -452,3 +450,40 @@ def test_label_compiler(faux_conn, metadata):
|
|
|
452
450
|
|
|
453
451
|
found_sql = q.compile(faux_conn).string
|
|
454
452
|
assert found_sql == expected_sql
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def test_type_compiler_double_methods():
|
|
456
|
+
from sqlalchemy_bigquery.base import BigQueryTypeCompiler
|
|
457
|
+
|
|
458
|
+
assert BigQueryTypeCompiler.visit_DOUBLE == BigQueryTypeCompiler.visit_FLOAT
|
|
459
|
+
assert (
|
|
460
|
+
BigQueryTypeCompiler.visit_DOUBLE_PRECISION == BigQueryTypeCompiler.visit_FLOAT
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
_double_types = [
|
|
465
|
+
getattr(sqlalchemy, name)
|
|
466
|
+
for name in ("DOUBLE", "DOUBLE_PRECISION", "Double")
|
|
467
|
+
if hasattr(sqlalchemy, name)
|
|
468
|
+
]
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
@pytest.mark.skipif(
|
|
472
|
+
not _double_types,
|
|
473
|
+
reason="DOUBLE types not present in this SQLAlchemy version",
|
|
474
|
+
)
|
|
475
|
+
@pytest.mark.parametrize("type_cls", _double_types or [None])
|
|
476
|
+
def test_double_types_compile_to_float64(type_cls):
|
|
477
|
+
import sqlalchemy_bigquery
|
|
478
|
+
|
|
479
|
+
dialect = sqlalchemy_bigquery.BigQueryDialect()
|
|
480
|
+
assert dialect.type_compiler.process(type_cls()) == "FLOAT64"
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def test_float_literal_pyformat_bindparam():
|
|
484
|
+
import sqlalchemy_bigquery
|
|
485
|
+
|
|
486
|
+
dialect = sqlalchemy_bigquery.BigQueryDialect(paramstyle="pyformat")
|
|
487
|
+
stmt = sqlalchemy.select(sqlalchemy.literal(15.7563))
|
|
488
|
+
compiled = stmt.compile(dialect=dialect)
|
|
489
|
+
assert "%(param_1:FLOAT64)s" in str(compiled)
|
|
@@ -166,12 +166,12 @@ def test_likish(faux_conn, meth, arg, expected):
|
|
|
166
166
|
],
|
|
167
167
|
)
|
|
168
168
|
expr = getattr(table.c.data, meth)(arg)
|
|
169
|
-
rows = {value for value, in faux_conn.execute(select(table.c.id).where(expr))}
|
|
169
|
+
rows = {value for (value,) in faux_conn.execute(select(table.c.id).where(expr))}
|
|
170
170
|
eq_(rows, expected)
|
|
171
171
|
|
|
172
172
|
all = {i for i in range(1, 11)}
|
|
173
173
|
expr = sqlalchemy.not_(expr)
|
|
174
|
-
rows = {value for value, in faux_conn.execute(select(table.c.id).where(expr))}
|
|
174
|
+
rows = {value for (value,) in faux_conn.execute(select(table.c.id).where(expr))}
|
|
175
175
|
eq_(rows, all - expected)
|
|
176
176
|
|
|
177
177
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Copyright 2026 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
from unittest import mock
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
from sqlalchemy.engine import make_url
|
|
20
|
+
|
|
21
|
+
from sqlalchemy_bigquery import provision
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_dataset_id_from_ident_with_existing_env(monkeypatch):
|
|
25
|
+
monkeypatch.setenv("COMPLIANCE_RUN_PREFIX", "custom_prefix")
|
|
26
|
+
dataset_id = provision._dataset_id_from_ident("gw0")
|
|
27
|
+
assert dataset_id == "custom_prefix_gw0"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_dataset_id_from_ident_without_env(monkeypatch):
|
|
31
|
+
monkeypatch.delenv("COMPLIANCE_RUN_PREFIX", raising=False)
|
|
32
|
+
monkeypatch.setattr(provision, "prefixer", None)
|
|
33
|
+
dataset_id = provision._dataset_id_from_ident("gw1")
|
|
34
|
+
cached_prefix = os.environ.get("COMPLIANCE_RUN_PREFIX")
|
|
35
|
+
assert cached_prefix is not None
|
|
36
|
+
assert dataset_id == f"{cached_prefix}_gw1"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_dataset_id_from_ident_with_prefixer(monkeypatch):
|
|
40
|
+
monkeypatch.delenv("COMPLIANCE_RUN_PREFIX", raising=False)
|
|
41
|
+
mock_prefixer = mock.Mock()
|
|
42
|
+
mock_prefixer.create_prefix.return_value = "mock_pfx"
|
|
43
|
+
monkeypatch.setattr(provision, "prefixer", mock_prefixer)
|
|
44
|
+
dataset_id = provision._dataset_id_from_ident("gw5")
|
|
45
|
+
assert dataset_id == "mock_pfx_gw5"
|
|
46
|
+
assert os.environ.get("COMPLIANCE_RUN_PREFIX") == "mock_pfx"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.mark.parametrize(
|
|
50
|
+
"driver, query_str, expected_drivername, expected_query",
|
|
51
|
+
[
|
|
52
|
+
(None, None, "bigquery", {}),
|
|
53
|
+
("bigquery", None, "bigquery", {}),
|
|
54
|
+
("bigquery", "param=1", "bigquery", {"param": "1"}),
|
|
55
|
+
("custom", None, "bigquery+custom", {}),
|
|
56
|
+
("custom", "param=2", "bigquery+custom", {"param": "2"}),
|
|
57
|
+
],
|
|
58
|
+
)
|
|
59
|
+
def test_generate_driver_url(driver, query_str, expected_drivername, expected_query):
|
|
60
|
+
base_url = "bigquery:///test_master"
|
|
61
|
+
result = provision._bigquery_generate_driver_url(base_url, driver, query_str)
|
|
62
|
+
assert result.drivername == expected_drivername
|
|
63
|
+
if expected_query:
|
|
64
|
+
for k, v in expected_query.items():
|
|
65
|
+
assert result.query.get(k) == v
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_follower_url_from_main(monkeypatch):
|
|
69
|
+
monkeypatch.setenv("COMPLIANCE_RUN_PREFIX", "run_123")
|
|
70
|
+
base_url = make_url("bigquery:///master_dataset")
|
|
71
|
+
follower_url = provision._bigquery_follower_url_from_main(base_url, "gw2")
|
|
72
|
+
assert follower_url.database == "run_123_gw2"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_create_db(monkeypatch):
|
|
76
|
+
monkeypatch.setenv("COMPLIANCE_RUN_PREFIX", "run_456")
|
|
77
|
+
mock_client = mock.MagicMock()
|
|
78
|
+
mock_client.project = "test-project"
|
|
79
|
+
mock_cfg = mock.Mock()
|
|
80
|
+
mock_cfg.db.url = make_url("bigquery:///test_dataset")
|
|
81
|
+
|
|
82
|
+
with mock.patch("google.cloud.bigquery.Client", return_value=mock_client):
|
|
83
|
+
provision._bigquery_create_db(mock_cfg, mock.Mock(), "gw3")
|
|
84
|
+
|
|
85
|
+
mock_client.create_dataset.assert_called_once()
|
|
86
|
+
created_dataset = mock_client.create_dataset.call_args[0][0]
|
|
87
|
+
assert created_dataset.dataset_id == "run_456_gw3"
|
|
88
|
+
assert created_dataset.default_table_expiration_ms == 3600 * 1000
|
|
89
|
+
assert mock_client.create_dataset.call_args[1].get("exists_ok") is True
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_drop_db(monkeypatch):
|
|
93
|
+
monkeypatch.setenv("COMPLIANCE_RUN_PREFIX", "run_789")
|
|
94
|
+
mock_client = mock.MagicMock()
|
|
95
|
+
mock_cfg = mock.Mock()
|
|
96
|
+
mock_cfg.db.url = make_url("bigquery:///test_dataset")
|
|
97
|
+
|
|
98
|
+
with mock.patch("google.cloud.bigquery.Client", return_value=mock_client):
|
|
99
|
+
provision._bigquery_drop_db(mock_cfg, mock.Mock(), "gw4")
|
|
100
|
+
|
|
101
|
+
mock_client.delete_dataset.assert_called_once_with(
|
|
102
|
+
"run_789_gw4", delete_contents=True, not_found_ok=True
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_ensure_dataset():
|
|
107
|
+
mock_client = mock.MagicMock()
|
|
108
|
+
mock_client.project = "test-project"
|
|
109
|
+
|
|
110
|
+
with mock.patch("google.cloud.bigquery.Client", return_value=mock_client):
|
|
111
|
+
provision.ensure_dataset("custom_dataset_123")
|
|
112
|
+
|
|
113
|
+
mock_client.create_dataset.assert_called_once()
|
|
114
|
+
created = mock_client.create_dataset.call_args[0][0]
|
|
115
|
+
assert created.dataset_id == "custom_dataset_123"
|
|
116
|
+
assert created.default_table_expiration_ms == 3600 * 1000
|
|
117
|
+
assert mock_client.create_dataset.call_args[1].get("exists_ok") is True
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_drop_dataset():
|
|
121
|
+
mock_client = mock.MagicMock()
|
|
122
|
+
|
|
123
|
+
with mock.patch("google.cloud.bigquery.Client", return_value=mock_client):
|
|
124
|
+
provision.drop_dataset("custom_dataset_456")
|
|
125
|
+
|
|
126
|
+
mock_client.delete_dataset.assert_called_once_with(
|
|
127
|
+
"custom_dataset_456", delete_contents=True, not_found_ok=True
|
|
128
|
+
)
|
|
@@ -118,7 +118,7 @@ def test_typed_parameters(faux_conn, type_, val, btype, vrep):
|
|
|
118
118
|
table = setup_table(faux_conn, "t", sqlalchemy.Column(col_name, type_))
|
|
119
119
|
|
|
120
120
|
assert faux_conn.test_data["execute"].pop()[0].strip() == (
|
|
121
|
-
f"CREATE TABLE `t` (\n
|
|
121
|
+
f"CREATE TABLE `t` (\n\t`{col_name}` {btype}\n)"
|
|
122
122
|
)
|
|
123
123
|
|
|
124
124
|
faux_conn.execute(table.insert().values(**{col_name: val}))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
SQLAlchemy dialect for Google BigQuery
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
+
import sys
|
|
23
24
|
import warnings
|
|
24
25
|
|
|
25
26
|
from ._types import (
|
|
@@ -43,7 +44,6 @@ from ._types import (
|
|
|
43
44
|
)
|
|
44
45
|
from .base import BigQueryDialect, dialect
|
|
45
46
|
from .version import __version__
|
|
46
|
-
import sys
|
|
47
47
|
|
|
48
48
|
# Now that support for Python 3.7, 3.8 and 3.9 has been removed, we don't expect the
|
|
49
49
|
# following check to succeed. The warning is only included for robustness.
|
|
@@ -10,11 +10,11 @@ import json
|
|
|
10
10
|
import re
|
|
11
11
|
from typing import Optional
|
|
12
12
|
|
|
13
|
-
from google.api_core import client_info
|
|
14
13
|
import google.auth
|
|
14
|
+
import sqlalchemy
|
|
15
|
+
from google.api_core import client_info
|
|
15
16
|
from google.cloud import bigquery
|
|
16
17
|
from google.oauth2 import service_account
|
|
17
|
-
import sqlalchemy
|
|
18
18
|
|
|
19
19
|
USER_AGENT_TEMPLATE = "sqlalchemy/{}"
|
|
20
20
|
SCOPES = (
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
18
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
19
|
|
|
20
|
-
from sqlalchemy.sql import operators
|
|
21
20
|
import sqlalchemy.sql.coercions
|
|
22
21
|
import sqlalchemy.sql.default_comparator
|
|
23
22
|
import sqlalchemy.sql.roles
|
|
24
23
|
import sqlalchemy.sql.sqltypes
|
|
25
24
|
import sqlalchemy.types
|
|
25
|
+
from sqlalchemy.sql import operators
|
|
26
26
|
|
|
27
27
|
# from . import base # Moved to _get_subtype_col_spec to break circular import
|
|
28
28
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
18
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
19
|
|
|
20
|
-
from google.cloud.bigquery.schema import SchemaField
|
|
21
20
|
import sqlalchemy.types
|
|
22
21
|
import sqlalchemy.util
|
|
22
|
+
from google.cloud.bigquery.schema import SchemaField
|
|
23
23
|
|
|
24
24
|
try:
|
|
25
25
|
from .geography import GEOGRAPHY
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
import geoalchemy2
|
|
21
21
|
import geoalchemy2.functions
|
|
22
|
+
import sqlalchemy.ext.compiler
|
|
22
23
|
from geoalchemy2.shape import to_shape
|
|
23
24
|
from shapely import wkb, wkt
|
|
24
|
-
import sqlalchemy.ext.compiler
|
|
25
25
|
from sqlalchemy.sql.elements import BindParameter
|
|
26
26
|
|
|
27
27
|
SRID = 4326 # WGS84, https://spatialreference.org/ref/epsg/wgs-84/
|
|
File without changes
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery/requirements.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/sqlalchemy_bigquery.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
import pathlib
|
|
21
21
|
from typing import List
|
|
22
22
|
|
|
23
|
-
from google.api_core import exceptions
|
|
24
|
-
from google.cloud import bigquery
|
|
25
23
|
import pytest
|
|
26
24
|
import sqlalchemy
|
|
27
25
|
import test_utils.prefixer
|
|
28
26
|
import test_utils.retry
|
|
27
|
+
from google.api_core import exceptions
|
|
28
|
+
from google.cloud import bigquery
|
|
29
29
|
|
|
30
30
|
from sqlalchemy_bigquery import BigQueryDialect
|
|
31
31
|
|
|
File without changes
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/data/sample_one_row.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
import contextlib
|
|
21
21
|
|
|
22
22
|
import google.api_core.exceptions
|
|
23
|
-
from google.cloud.bigquery import SchemaField, TimePartitioning
|
|
24
23
|
import pytest
|
|
24
|
+
from google.cloud.bigquery import SchemaField, TimePartitioning
|
|
25
25
|
from sqlalchemy import Column, DateTime, Integer, Numeric, String
|
|
26
26
|
|
|
27
27
|
alembic = pytest.importorskip("alembic")
|
|
File without changes
|
|
File without changes
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/system/test_sqlalchemy_bigquery.py
RENAMED
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
import datetime
|
|
22
22
|
import decimal
|
|
23
23
|
|
|
24
|
-
from google.cloud.bigquery import TimePartitioning
|
|
25
24
|
import packaging.version
|
|
26
25
|
import pytest
|
|
27
26
|
import sqlalchemy
|
|
27
|
+
from google.cloud.bigquery import TimePartitioning
|
|
28
28
|
from sqlalchemy import (
|
|
29
29
|
Column,
|
|
30
30
|
MetaData,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from google.cloud.bigquery.schema import SchemaField
|
|
16
15
|
import pytest
|
|
16
|
+
from google.cloud.bigquery.schema import SchemaField
|
|
17
17
|
|
|
18
18
|
from sqlalchemy_bigquery._types import _get_transitive_schema_fields
|
|
19
19
|
|
|
File without changes
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_catalog_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
18
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
19
|
|
|
20
|
+
import pytest
|
|
20
21
|
from google.cloud.bigquery import QueryJobConfig
|
|
21
22
|
from google.cloud.bigquery.dataset import DatasetReference
|
|
22
23
|
from google.cloud.bigquery.table import EncryptionConfiguration, TableReference
|
|
23
|
-
import pytest
|
|
24
24
|
from sqlalchemy.engine.url import make_url
|
|
25
25
|
|
|
26
26
|
from sqlalchemy_bigquery.parse_url import parse_url
|
{sqlalchemy_bigquery-1.17.1 → sqlalchemy_bigquery-1.17.3}/tests/unit/test_sqlalchemy_bigquery.py
RENAMED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
from unittest import mock
|
|
8
8
|
|
|
9
9
|
import google.api_core.exceptions
|
|
10
|
+
import pytest
|
|
11
|
+
import sqlalchemy
|
|
10
12
|
from google.cloud import bigquery
|
|
11
13
|
from google.cloud.bigquery.dataset import DatasetListItem
|
|
12
14
|
from google.cloud.bigquery.table import TableListItem
|
|
13
|
-
import pytest
|
|
14
|
-
import sqlalchemy
|
|
15
15
|
|
|
16
16
|
from .conftest import setup_table
|
|
17
17
|
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
import datetime
|
|
21
21
|
import sqlite3
|
|
22
22
|
|
|
23
|
+
import pytest
|
|
24
|
+
import sqlalchemy
|
|
23
25
|
from google.cloud.bigquery import (
|
|
24
26
|
PartitionRange,
|
|
25
27
|
RangePartitioning,
|
|
26
28
|
TimePartitioning,
|
|
27
29
|
TimePartitioningType,
|
|
28
30
|
)
|
|
29
|
-
import pytest
|
|
30
|
-
import sqlalchemy
|
|
31
31
|
|
|
32
32
|
from .conftest import setup_table
|
|
33
33
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|