sqlalchemy-bigquery 1.12.1__tar.gz → 1.14.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.
Files changed (68) hide show
  1. {sqlalchemy_bigquery-1.12.1/sqlalchemy_bigquery.egg-info → sqlalchemy_bigquery-1.14.0}/PKG-INFO +14 -14
  2. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/setup.cfg +0 -3
  3. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/setup.py +7 -7
  4. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/base.py +36 -16
  5. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/version.py +1 -1
  6. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0/sqlalchemy_bigquery.egg-info}/PKG-INFO +14 -14
  7. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery.egg-info/SOURCES.txt +1 -0
  8. sqlalchemy_bigquery-1.14.0/sqlalchemy_bigquery.egg-info/requires.txt +37 -0
  9. sqlalchemy_bigquery-1.14.0/tests/system/test_sqlalchemy_bigquery_remote.py +107 -0
  10. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/fauxdbi.py +13 -8
  11. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_engine.py +6 -0
  12. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_sqlalchemy_bigquery.py +21 -0
  13. sqlalchemy_bigquery-1.12.1/sqlalchemy_bigquery.egg-info/requires.txt +0 -37
  14. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/AUTHORS +0 -0
  15. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/LICENSE +0 -0
  16. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/MANIFEST.in +0 -0
  17. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/README.rst +0 -0
  18. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/pyproject.toml +0 -0
  19. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/__init__.py +0 -0
  20. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/_helpers.py +0 -0
  21. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/_struct.py +0 -0
  22. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/_types.py +0 -0
  23. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/_versions_helpers.py +0 -0
  24. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/geography.py +0 -0
  25. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/parse_url.py +0 -0
  26. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery/requirements.py +0 -0
  27. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery.egg-info/dependency_links.txt +0 -0
  28. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery.egg-info/entry_points.txt +0 -0
  29. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/sqlalchemy_bigquery.egg-info/top_level.txt +0 -0
  30. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/__init__.py +0 -0
  31. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/conftest.py +0 -0
  32. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/sqlalchemy_dialect_compliance/README.rst +0 -0
  33. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/sqlalchemy_dialect_compliance/conftest.py +0 -0
  34. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py +0 -0
  35. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/__init__.py +0 -0
  36. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/conftest.py +0 -0
  37. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/data/sample.json +0 -0
  38. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/data/sample_one_row.json +0 -0
  39. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/data/schema.json +0 -0
  40. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/test__struct.py +0 -0
  41. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/test_alembic.py +0 -0
  42. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/test_geography.py +0 -0
  43. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/test_helpers.py +0 -0
  44. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/system/test_sqlalchemy_bigquery.py +0 -0
  45. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/__init__.py +0 -0
  46. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/conftest.py +0 -0
  47. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test__struct.py +0 -0
  48. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_alembic.py +0 -0
  49. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_catalog_functions.py +0 -0
  50. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_comments.py +0 -0
  51. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_compiler.py +0 -0
  52. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_compliance.py +0 -0
  53. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_dialect_types.py +0 -0
  54. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_geography.py +0 -0
  55. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_helpers.py +0 -0
  56. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_like_reescape.py +0 -0
  57. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_parse_url.py +0 -0
  58. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_select.py +0 -0
  59. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_table_options.py +0 -0
  60. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_version.py +0 -0
  61. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/tests/unit/test_view.py +0 -0
  62. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/__init__.py +0 -0
  63. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/py.typed +0 -0
  64. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/AUTHORS +0 -0
  65. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/LICENSE +0 -0
  66. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/__init__.py +0 -0
  67. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/__init__.py +0 -0
  68. {sqlalchemy_bigquery-1.12.1 → sqlalchemy_bigquery-1.14.0}/third_party/sqlalchemy_bigquery_vendored/sqlalchemy/postgresql/base.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy-bigquery
3
- Version: 1.12.1
3
+ Version: 1.14.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
@@ -24,11 +24,11 @@ Requires-Python: >=3.8, <3.13
24
24
  Description-Content-Type: text/x-rst
25
25
  License-File: LICENSE
26
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
27
+ Requires-Dist: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5
28
+ Requires-Dist: google-auth<3.0.0,>=1.25.0
29
+ Requires-Dist: google-cloud-bigquery<4.0.0,>=3.3.6
30
30
  Requires-Dist: packaging
31
- Requires-Dist: sqlalchemy<3.0.0dev,>=1.4.16
31
+ Requires-Dist: sqlalchemy<3.0.0,>=1.4.16
32
32
  Provides-Extra: geography
33
33
  Requires-Dist: GeoAlchemy2; extra == "geography"
34
34
  Requires-Dist: shapely; extra == "geography"
@@ -38,20 +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.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"
41
+ Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.0.0; extra == "bqstorage"
42
+ Requires-Dist: grpcio<2.0.0,>=1.47.0; extra == "bqstorage"
43
+ Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version >= "3.11" and extra == "bqstorage"
44
44
  Requires-Dist: pyarrow>=3.0.0; extra == "bqstorage"
45
45
  Provides-Extra: all
46
46
  Requires-Dist: GeoAlchemy2; extra == "all"
47
- Requires-Dist: shapely; extra == "all"
48
- Requires-Dist: grpcio<2.0dev,>=1.47.0; extra == "all"
49
- Requires-Dist: pytz; extra == "all"
50
- Requires-Dist: packaging; extra == "all"
51
47
  Requires-Dist: pyarrow>=3.0.0; extra == "all"
52
- Requires-Dist: google-cloud-bigquery-storage<3.0.0dev,>=2.0.0; extra == "all"
48
+ Requires-Dist: grpcio<2.0.0,>=1.47.0; extra == "all"
49
+ Requires-Dist: shapely; extra == "all"
53
50
  Requires-Dist: alembic; extra == "all"
54
- Requires-Dist: grpcio<2.0dev,>=1.49.1; python_version >= "3.11" and extra == "all"
51
+ Requires-Dist: packaging; extra == "all"
52
+ Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.0.0; extra == "all"
53
+ Requires-Dist: pytz; extra == "all"
54
+ Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version >= "3.11" and extra == "all"
55
55
 
56
56
  SQLAlchemy Dialect for BigQuery
57
57
  ===============================
@@ -1,6 +1,3 @@
1
- [bdist_wheel]
2
- universal = 1
3
-
4
1
  [sqla_testing]
5
2
  requirement_cls = sqlalchemy_bigquery.requirements:Requirements
6
3
  profile_file = .sqlalchemy_dialect_compliance-profiles.txt
@@ -53,15 +53,15 @@ extras = {
53
53
  # Keep the no-op bqstorage extra for backward compatibility.
54
54
  # See: https://github.com/googleapis/python-bigquery/issues/757
55
55
  "bqstorage": [
56
- "google-cloud-bigquery-storage >= 2.0.0, <3.0.0dev",
56
+ "google-cloud-bigquery-storage >= 2.0.0, <3.0.0",
57
57
  # Due to an issue in pip's dependency resolver, the `grpc` extra is not
58
58
  # installed, even though `google-cloud-bigquery-storage` specifies it
59
59
  # as `google-api-core[grpc]`. We thus need to explicitly specify it here.
60
60
  # See: https://github.com/googleapis/python-bigquery/issues/83 The
61
61
  # grpc.Channel.close() method isn't added until 1.32.0.
62
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'",
63
+ "grpcio >= 1.47.0, < 2.0.0",
64
+ "grpcio >= 1.49.1, < 2.0.0; python_version>='3.11'",
65
65
  "pyarrow >= 3.0.0",
66
66
  ],
67
67
  }
@@ -109,14 +109,14 @@ setup(
109
109
  ],
110
110
  platforms="Posix; MacOS X; Windows",
111
111
  install_requires=[
112
- "google-api-core >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
112
+ "google-api-core >= 1.31.5, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
113
113
  # NOTE: Maintainers, please do not require google-auth>=2.x.x
114
114
  # Until this issue is closed
115
115
  # https://github.com/googleapis/google-cloud-python/issues/10566
116
- "google-auth>=1.25.0,<3.0.0dev", # Work around pip wack.
117
- "google-cloud-bigquery>=3.3.6,<4.0.0dev",
116
+ "google-auth>=1.25.0,<3.0.0", # Work around pip wack.
117
+ "google-cloud-bigquery>=3.3.6,<4.0.0",
118
118
  "packaging",
119
- "sqlalchemy>=1.4.16,<3.0.0dev",
119
+ "sqlalchemy>=1.4.16,<3.0.0",
120
120
  ],
121
121
  extras_require=extras,
122
122
  python_requires=">=3.8, <3.13",
@@ -27,7 +27,7 @@ import uuid
27
27
 
28
28
  from google import auth
29
29
  import google.api_core.exceptions
30
- from google.cloud.bigquery import dbapi
30
+ from google.cloud.bigquery import dbapi, ConnectionProperty
31
31
  from google.cloud.bigquery.table import (
32
32
  RangePartitioning,
33
33
  TableReference,
@@ -61,6 +61,7 @@ import re
61
61
  from .parse_url import parse_url
62
62
  from . import _helpers, _struct, _types
63
63
  import sqlalchemy_bigquery_vendored.sqlalchemy.postgresql.base as vendored_postgresql
64
+ from google.cloud.bigquery import QueryJobConfig
64
65
 
65
66
  # Illegal characters is intended to be all characters that are not explicitly
66
67
  # allowed as part of the flexible column names.
@@ -1080,6 +1081,7 @@ class BigQueryDialect(DefaultDialect):
1080
1081
  self,
1081
1082
  arraysize=5000,
1082
1083
  credentials_path=None,
1084
+ billing_project_id=None,
1083
1085
  location=None,
1084
1086
  credentials_info=None,
1085
1087
  credentials_base64=None,
@@ -1092,6 +1094,8 @@ class BigQueryDialect(DefaultDialect):
1092
1094
  self.credentials_path = credentials_path
1093
1095
  self.credentials_info = credentials_info
1094
1096
  self.credentials_base64 = credentials_base64
1097
+ self.project_id = None
1098
+ self.billing_project_id = billing_project_id
1095
1099
  self.location = location
1096
1100
  self.identifier_preparer = self.preparer(self)
1097
1101
  self.dataset_id = None
@@ -1114,25 +1118,36 @@ class BigQueryDialect(DefaultDialect):
1114
1118
  """Build '<dataset_id>.<table_id>' string using given table."""
1115
1119
  return "{}.{}".format(table.reference.dataset_id, table.table_id)
1116
1120
 
1117
- @staticmethod
1118
- def _add_default_dataset_to_job_config(job_config, project_id, dataset_id):
1119
- # If dataset_id is set, then we know the job_config isn't None
1120
- if dataset_id:
1121
- # If project_id is missing, use default project_id for the current environment
1121
+ def create_job_config(self, provided_config: QueryJobConfig):
1122
+ project_id = self.project_id
1123
+ if self.dataset_id is None and project_id == self.billing_project_id:
1124
+ return provided_config
1125
+ job_config = provided_config or QueryJobConfig()
1126
+ if project_id != self.billing_project_id:
1127
+ job_config.connection_properties = [
1128
+ ConnectionProperty(key="dataset_project_id", value=project_id)
1129
+ ]
1130
+ if self.dataset_id:
1122
1131
  if not project_id:
1123
1132
  _, project_id = auth.default()
1133
+ job_config.default_dataset = "{}.{}".format(project_id, self.dataset_id)
1134
+ return job_config
1124
1135
 
1125
- job_config.default_dataset = "{}.{}".format(project_id, dataset_id)
1136
+ def do_execute(self, cursor, statement, parameters, context=None):
1137
+ kwargs = {}
1138
+ if context is not None and context.execution_options.get("job_config"):
1139
+ kwargs["job_config"] = context.execution_options.get("job_config")
1140
+ cursor.execute(statement, parameters, **kwargs)
1126
1141
 
1127
1142
  def create_connect_args(self, url):
1128
1143
  (
1129
- project_id,
1144
+ self.project_id,
1130
1145
  location,
1131
1146
  dataset_id,
1132
1147
  arraysize,
1133
1148
  credentials_path,
1134
1149
  credentials_base64,
1135
- default_query_job_config,
1150
+ provided_job_config,
1136
1151
  list_tables_page_size,
1137
1152
  user_supplied_client,
1138
1153
  ) = parse_url(url)
@@ -1143,9 +1158,9 @@ class BigQueryDialect(DefaultDialect):
1143
1158
  self.credentials_path = credentials_path or self.credentials_path
1144
1159
  self.credentials_base64 = credentials_base64 or self.credentials_base64
1145
1160
  self.dataset_id = dataset_id
1146
- self._add_default_dataset_to_job_config(
1147
- default_query_job_config, project_id, dataset_id
1148
- )
1161
+ self.billing_project_id = self.billing_project_id or self.project_id
1162
+
1163
+ default_query_job_config = self.create_job_config(provided_job_config)
1149
1164
 
1150
1165
  if user_supplied_client:
1151
1166
  # The user is expected to supply a client with
@@ -1156,10 +1171,14 @@ class BigQueryDialect(DefaultDialect):
1156
1171
  credentials_path=self.credentials_path,
1157
1172
  credentials_info=self.credentials_info,
1158
1173
  credentials_base64=self.credentials_base64,
1159
- project_id=project_id,
1174
+ project_id=self.billing_project_id,
1160
1175
  location=self.location,
1161
1176
  default_query_job_config=default_query_job_config,
1162
1177
  )
1178
+ # If the user specified `bigquery://` we need to set the project_id
1179
+ # from the client
1180
+ self.project_id = self.project_id or client.project
1181
+ self.billing_project_id = self.billing_project_id or client.project
1163
1182
  return ([], {"client": client})
1164
1183
 
1165
1184
  def _get_table_or_view_names(self, connection, item_types, schema=None):
@@ -1171,7 +1190,7 @@ class BigQueryDialect(DefaultDialect):
1171
1190
  )
1172
1191
 
1173
1192
  client = connection.connection._client
1174
- datasets = client.list_datasets()
1193
+ datasets = client.list_datasets(self.project_id)
1175
1194
 
1176
1195
  result = []
1177
1196
  for dataset in datasets:
@@ -1272,7 +1291,8 @@ class BigQueryDialect(DefaultDialect):
1272
1291
 
1273
1292
  client = connection.connection._client
1274
1293
 
1275
- table_ref = self._table_reference(schema, table_name, client.project)
1294
+ # table_ref = self._table_reference(schema, table_name, client.project)
1295
+ table_ref = self._table_reference(schema, table_name, self.project_id)
1276
1296
  try:
1277
1297
  table = client.get_table(table_ref)
1278
1298
  except NotFound:
@@ -1326,7 +1346,7 @@ class BigQueryDialect(DefaultDialect):
1326
1346
  if isinstance(connection, Engine):
1327
1347
  connection = connection.connect()
1328
1348
 
1329
- datasets = connection.connection._client.list_datasets()
1349
+ datasets = connection.connection._client.list_datasets(self.project_id)
1330
1350
  return [d.dataset_id for d in datasets]
1331
1351
 
1332
1352
  def get_table_names(self, connection, schema=None, **kw):
@@ -17,4 +17,4 @@
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
- __version__ = "1.12.1"
20
+ __version__ = "1.14.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy-bigquery
3
- Version: 1.12.1
3
+ Version: 1.14.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
@@ -24,11 +24,11 @@ Requires-Python: >=3.8, <3.13
24
24
  Description-Content-Type: text/x-rst
25
25
  License-File: LICENSE
26
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
27
+ Requires-Dist: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5
28
+ Requires-Dist: google-auth<3.0.0,>=1.25.0
29
+ Requires-Dist: google-cloud-bigquery<4.0.0,>=3.3.6
30
30
  Requires-Dist: packaging
31
- Requires-Dist: sqlalchemy<3.0.0dev,>=1.4.16
31
+ Requires-Dist: sqlalchemy<3.0.0,>=1.4.16
32
32
  Provides-Extra: geography
33
33
  Requires-Dist: GeoAlchemy2; extra == "geography"
34
34
  Requires-Dist: shapely; extra == "geography"
@@ -38,20 +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.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"
41
+ Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.0.0; extra == "bqstorage"
42
+ Requires-Dist: grpcio<2.0.0,>=1.47.0; extra == "bqstorage"
43
+ Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version >= "3.11" and extra == "bqstorage"
44
44
  Requires-Dist: pyarrow>=3.0.0; extra == "bqstorage"
45
45
  Provides-Extra: all
46
46
  Requires-Dist: GeoAlchemy2; extra == "all"
47
- Requires-Dist: shapely; extra == "all"
48
- Requires-Dist: grpcio<2.0dev,>=1.47.0; extra == "all"
49
- Requires-Dist: pytz; extra == "all"
50
- Requires-Dist: packaging; extra == "all"
51
47
  Requires-Dist: pyarrow>=3.0.0; extra == "all"
52
- Requires-Dist: google-cloud-bigquery-storage<3.0.0dev,>=2.0.0; extra == "all"
48
+ Requires-Dist: grpcio<2.0.0,>=1.47.0; extra == "all"
49
+ Requires-Dist: shapely; extra == "all"
53
50
  Requires-Dist: alembic; extra == "all"
54
- Requires-Dist: grpcio<2.0dev,>=1.49.1; python_version >= "3.11" and extra == "all"
51
+ Requires-Dist: packaging; extra == "all"
52
+ Requires-Dist: google-cloud-bigquery-storage<3.0.0,>=2.0.0; extra == "all"
53
+ Requires-Dist: pytz; extra == "all"
54
+ Requires-Dist: grpcio<2.0.0,>=1.49.1; python_version >= "3.11" and extra == "all"
55
55
 
56
56
  SQLAlchemy Dialect for BigQuery
57
57
  ===============================
@@ -33,6 +33,7 @@ tests/system/test_alembic.py
33
33
  tests/system/test_geography.py
34
34
  tests/system/test_helpers.py
35
35
  tests/system/test_sqlalchemy_bigquery.py
36
+ tests/system/test_sqlalchemy_bigquery_remote.py
36
37
  tests/system/data/sample.json
37
38
  tests/system/data/sample_one_row.json
38
39
  tests/system/data/schema.json
@@ -0,0 +1,37 @@
1
+ google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5
2
+ google-auth<3.0.0,>=1.25.0
3
+ google-cloud-bigquery<4.0.0,>=3.3.6
4
+ packaging
5
+ sqlalchemy<3.0.0,>=1.4.16
6
+
7
+ [alembic]
8
+ alembic
9
+
10
+ [all]
11
+ GeoAlchemy2
12
+ pyarrow>=3.0.0
13
+ grpcio<2.0.0,>=1.47.0
14
+ shapely
15
+ alembic
16
+ packaging
17
+ google-cloud-bigquery-storage<3.0.0,>=2.0.0
18
+ pytz
19
+
20
+ [all:python_version >= "3.11"]
21
+ grpcio<2.0.0,>=1.49.1
22
+
23
+ [bqstorage]
24
+ google-cloud-bigquery-storage<3.0.0,>=2.0.0
25
+ grpcio<2.0.0,>=1.47.0
26
+ pyarrow>=3.0.0
27
+
28
+ [bqstorage:python_version >= "3.11"]
29
+ grpcio<2.0.0,>=1.49.1
30
+
31
+ [geography]
32
+ GeoAlchemy2
33
+ shapely
34
+
35
+ [tests]
36
+ packaging
37
+ pytz
@@ -0,0 +1,107 @@
1
+ # Copyright (c) 2017 The sqlalchemy-bigquery Authors
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ # -*- coding: utf-8 -*-
21
+
22
+ from sqlalchemy.engine import create_engine
23
+ from sqlalchemy.exc import DatabaseError
24
+ from sqlalchemy.schema import Table, MetaData
25
+ import pytest
26
+ import sqlalchemy
27
+ import google.api_core.exceptions as core_exceptions
28
+
29
+
30
+ EXPECTED_STATES = ["AL", "CA", "FL", "KY"]
31
+
32
+ REMOTE_TESTS = [
33
+ ("bigquery-public-data", "bigquery-public-data.usa_names.usa_1910_2013"),
34
+ ("bigquery-public-data", "usa_names.usa_1910_2013"),
35
+ ("bigquery-public-data/usa_names", "bigquery-public-data.usa_names.usa_1910_2013"),
36
+ ("bigquery-public-data/usa_names", "usa_1910_2013"),
37
+ ("bigquery-public-data/usa_names", "usa_names.usa_1910_2013"),
38
+ ]
39
+
40
+
41
+ @pytest.fixture(scope="session")
42
+ def engine_using_remote_dataset(bigquery_client):
43
+ engine = create_engine(
44
+ "bigquery://bigquery-public-data/usa_names",
45
+ billing_project_id=bigquery_client.project,
46
+ echo=True,
47
+ )
48
+ return engine
49
+
50
+
51
+ def test_remote_tables_list(engine_using_remote_dataset):
52
+ tables = sqlalchemy.inspect(engine_using_remote_dataset).get_table_names()
53
+ assert "usa_1910_2013" in tables
54
+
55
+
56
+ @pytest.mark.parametrize(
57
+ ["urlpath", "table_name"],
58
+ REMOTE_TESTS,
59
+ ids=[f"test_engine_remote_sql_{x}" for x in range(len(REMOTE_TESTS))],
60
+ )
61
+ def test_engine_remote_sql(bigquery_client, urlpath, table_name):
62
+ engine = create_engine(
63
+ f"bigquery://{urlpath}", billing_project_id=bigquery_client.project, echo=True
64
+ )
65
+ with engine.connect() as conn:
66
+ rows = conn.execute(
67
+ sqlalchemy.text(f"SELECT DISTINCT(state) FROM `{table_name}`")
68
+ ).fetchall()
69
+ states = set(map(lambda row: row[0], rows))
70
+ assert set(EXPECTED_STATES).issubset(states)
71
+
72
+
73
+ @pytest.mark.parametrize(
74
+ ["urlpath", "table_name"],
75
+ REMOTE_TESTS,
76
+ ids=[f"test_engine_remote_table_{x}" for x in range(len(REMOTE_TESTS))],
77
+ )
78
+ def test_engine_remote_table(bigquery_client, urlpath, table_name):
79
+ engine = create_engine(
80
+ f"bigquery://{urlpath}", billing_project_id=bigquery_client.project, echo=True
81
+ )
82
+ with engine.connect() as conn:
83
+ table = Table(table_name, MetaData(), autoload_with=engine)
84
+ prepared = sqlalchemy.select(
85
+ sqlalchemy.distinct(table.c.state)
86
+ ).set_label_style(sqlalchemy.LABEL_STYLE_TABLENAME_PLUS_COL)
87
+ rows = conn.execute(prepared).fetchall()
88
+ states = set(map(lambda row: row[0], rows))
89
+ assert set(EXPECTED_STATES).issubset(states)
90
+
91
+
92
+ @pytest.mark.parametrize(
93
+ ["urlpath", "table_name"],
94
+ REMOTE_TESTS,
95
+ ids=[f"test_engine_remote_table_fail_{x}" for x in range(len(REMOTE_TESTS))],
96
+ )
97
+ def test_engine_remote_table_fail(urlpath, table_name):
98
+ engine = create_engine(f"bigquery://{urlpath}", echo=True)
99
+ with pytest.raises(
100
+ (DatabaseError, core_exceptions.Forbidden), match="Access Denied"
101
+ ):
102
+ with engine.connect() as conn:
103
+ table = Table(table_name, MetaData(), autoload_with=engine)
104
+ prepared = sqlalchemy.select(
105
+ sqlalchemy.distinct(table.c.state)
106
+ ).set_label_style(sqlalchemy.LABEL_STYLE_TABLENAME_PLUS_COL)
107
+ conn.execute(prepared).fetchall()
@@ -327,10 +327,12 @@ class Cursor:
327
327
  pickle.loads(v.encode("latin1"))
328
328
  # \x80\x04 is latin-1 encoded prefix for Pickle protocol 4.
329
329
  if isinstance(v, str) and v[:2] == "\x80\x04" and v[-1] == "."
330
- else pickle.loads(base64.b16decode(v))
331
- # 8004 is base64 encoded prefix for Pickle protocol 4.
332
- if isinstance(v, str) and v[:4] == "8004" and v[-2:] == "2E"
333
- else v
330
+ else (
331
+ pickle.loads(base64.b16decode(v))
332
+ # 8004 is base64 encoded prefix for Pickle protocol 4.
333
+ if isinstance(v, str) and v[:4] == "8004" and v[-2:] == "2E"
334
+ else v
335
+ )
334
336
  )
335
337
  for d, v in zip(self.description, row)
336
338
  ]
@@ -355,7 +357,10 @@ class attrdict(dict):
355
357
  class FauxClient:
356
358
  def __init__(self, project_id=None, default_query_job_config=None, *args, **kw):
357
359
  if project_id is None:
358
- if default_query_job_config is not None:
360
+ if (
361
+ default_query_job_config is not None
362
+ and default_query_job_config.default_dataset
363
+ ):
359
364
  project_id = default_query_job_config.default_dataset.project
360
365
  else:
361
366
  project_id = "authproj" # we would still have gotten it from auth.
@@ -469,10 +474,10 @@ class FauxClient:
469
474
  else:
470
475
  raise google.api_core.exceptions.NotFound(table_ref)
471
476
 
472
- def list_datasets(self):
477
+ def list_datasets(self, project="myproject"):
473
478
  return [
474
- google.cloud.bigquery.Dataset("myproject.mydataset"),
475
- google.cloud.bigquery.Dataset("myproject.yourdataset"),
479
+ google.cloud.bigquery.Dataset(f"{project}.mydataset"),
480
+ google.cloud.bigquery.Dataset(f"{project}.yourdataset"),
476
481
  ]
477
482
 
478
483
  def list_tables(self, dataset, page_size):
@@ -27,6 +27,12 @@ def test_engine_dataset_but_no_project(faux_conn):
27
27
  assert conn.connection._client.project == "authproj"
28
28
 
29
29
 
30
+ def test_engine_dataset_with_billing_project(faux_conn):
31
+ engine = sqlalchemy.create_engine("bigquery://foo", billing_project_id="bar")
32
+ conn = engine.connect()
33
+ assert conn.connection._client.project == "bar"
34
+
35
+
30
36
  def test_engine_no_dataset_no_project(faux_conn):
31
37
  engine = sqlalchemy.create_engine("bigquery://")
32
38
  conn = engine.connect()
@@ -240,3 +240,24 @@ def test_setting_user_supplied_client_skips_creating_client(
240
240
  )
241
241
  assert result == ([], {})
242
242
  assert not mock_create_bigquery_client.called
243
+
244
+
245
+ def test_do_execute():
246
+ # Ensures the do_execute() method overrides that of the parent class.
247
+ import sqlalchemy_bigquery # noqa
248
+ from sqlalchemy_bigquery.base import BigQueryExecutionContext
249
+
250
+ job_config_kwargs = {}
251
+ job_config_kwargs["use_query_cache"] = False
252
+ job_config = bigquery.QueryJobConfig(**job_config_kwargs)
253
+ execution_options = {"job_config": job_config}
254
+ context = mock.MagicMock(spec=BigQueryExecutionContext)
255
+ type(context).execution_options = mock.PropertyMock(return_value=execution_options)
256
+
257
+ cursor = mock.MagicMock()
258
+
259
+ sqlalchemy_bigquery.BigQueryDialect().do_execute(
260
+ cursor, sqlalchemy.text("SELECT 'a' AS `1`"), mock.MagicMock(), context=context
261
+ )
262
+
263
+ assert cursor.execute.call_args.kwargs["job_config"] is job_config
@@ -1,37 +0,0 @@
1
- google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5
2
- google-auth<3.0.0dev,>=1.25.0
3
- google-cloud-bigquery<4.0.0dev,>=3.3.6
4
- packaging
5
- sqlalchemy<3.0.0dev,>=1.4.16
6
-
7
- [alembic]
8
- alembic
9
-
10
- [all]
11
- GeoAlchemy2
12
- shapely
13
- grpcio<2.0dev,>=1.47.0
14
- pytz
15
- packaging
16
- pyarrow>=3.0.0
17
- google-cloud-bigquery-storage<3.0.0dev,>=2.0.0
18
- alembic
19
-
20
- [all:python_version >= "3.11"]
21
- grpcio<2.0dev,>=1.49.1
22
-
23
- [bqstorage]
24
- google-cloud-bigquery-storage<3.0.0dev,>=2.0.0
25
- grpcio<2.0dev,>=1.47.0
26
- pyarrow>=3.0.0
27
-
28
- [bqstorage:python_version >= "3.11"]
29
- grpcio<2.0dev,>=1.49.1
30
-
31
- [geography]
32
- GeoAlchemy2
33
- shapely
34
-
35
- [tests]
36
- packaging
37
- pytz