sqlspec 0.16.1__cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

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.

Potentially problematic release.


This version of sqlspec might be problematic. Click here for more details.

Files changed (148) hide show
  1. 51ff5a9eadfdefd49f98__mypyc.cpython-311-aarch64-linux-gnu.so +0 -0
  2. sqlspec/__init__.py +92 -0
  3. sqlspec/__main__.py +12 -0
  4. sqlspec/__metadata__.py +14 -0
  5. sqlspec/_serialization.py +77 -0
  6. sqlspec/_sql.py +1780 -0
  7. sqlspec/_typing.py +680 -0
  8. sqlspec/adapters/__init__.py +0 -0
  9. sqlspec/adapters/adbc/__init__.py +5 -0
  10. sqlspec/adapters/adbc/_types.py +12 -0
  11. sqlspec/adapters/adbc/config.py +361 -0
  12. sqlspec/adapters/adbc/driver.py +512 -0
  13. sqlspec/adapters/aiosqlite/__init__.py +19 -0
  14. sqlspec/adapters/aiosqlite/_types.py +13 -0
  15. sqlspec/adapters/aiosqlite/config.py +253 -0
  16. sqlspec/adapters/aiosqlite/driver.py +248 -0
  17. sqlspec/adapters/asyncmy/__init__.py +19 -0
  18. sqlspec/adapters/asyncmy/_types.py +12 -0
  19. sqlspec/adapters/asyncmy/config.py +180 -0
  20. sqlspec/adapters/asyncmy/driver.py +274 -0
  21. sqlspec/adapters/asyncpg/__init__.py +21 -0
  22. sqlspec/adapters/asyncpg/_types.py +17 -0
  23. sqlspec/adapters/asyncpg/config.py +229 -0
  24. sqlspec/adapters/asyncpg/driver.py +344 -0
  25. sqlspec/adapters/bigquery/__init__.py +18 -0
  26. sqlspec/adapters/bigquery/_types.py +12 -0
  27. sqlspec/adapters/bigquery/config.py +298 -0
  28. sqlspec/adapters/bigquery/driver.py +558 -0
  29. sqlspec/adapters/duckdb/__init__.py +22 -0
  30. sqlspec/adapters/duckdb/_types.py +12 -0
  31. sqlspec/adapters/duckdb/config.py +504 -0
  32. sqlspec/adapters/duckdb/driver.py +368 -0
  33. sqlspec/adapters/oracledb/__init__.py +32 -0
  34. sqlspec/adapters/oracledb/_types.py +14 -0
  35. sqlspec/adapters/oracledb/config.py +317 -0
  36. sqlspec/adapters/oracledb/driver.py +538 -0
  37. sqlspec/adapters/psqlpy/__init__.py +16 -0
  38. sqlspec/adapters/psqlpy/_types.py +11 -0
  39. sqlspec/adapters/psqlpy/config.py +214 -0
  40. sqlspec/adapters/psqlpy/driver.py +530 -0
  41. sqlspec/adapters/psycopg/__init__.py +32 -0
  42. sqlspec/adapters/psycopg/_types.py +17 -0
  43. sqlspec/adapters/psycopg/config.py +426 -0
  44. sqlspec/adapters/psycopg/driver.py +796 -0
  45. sqlspec/adapters/sqlite/__init__.py +15 -0
  46. sqlspec/adapters/sqlite/_types.py +11 -0
  47. sqlspec/adapters/sqlite/config.py +240 -0
  48. sqlspec/adapters/sqlite/driver.py +294 -0
  49. sqlspec/base.py +571 -0
  50. sqlspec/builder/__init__.py +62 -0
  51. sqlspec/builder/_base.py +473 -0
  52. sqlspec/builder/_column.py +320 -0
  53. sqlspec/builder/_ddl.py +1346 -0
  54. sqlspec/builder/_ddl_utils.py +103 -0
  55. sqlspec/builder/_delete.py +76 -0
  56. sqlspec/builder/_insert.py +256 -0
  57. sqlspec/builder/_merge.py +71 -0
  58. sqlspec/builder/_parsing_utils.py +140 -0
  59. sqlspec/builder/_select.py +170 -0
  60. sqlspec/builder/_update.py +188 -0
  61. sqlspec/builder/mixins/__init__.py +55 -0
  62. sqlspec/builder/mixins/_cte_and_set_ops.py +222 -0
  63. sqlspec/builder/mixins/_delete_operations.py +41 -0
  64. sqlspec/builder/mixins/_insert_operations.py +244 -0
  65. sqlspec/builder/mixins/_join_operations.py +122 -0
  66. sqlspec/builder/mixins/_merge_operations.py +476 -0
  67. sqlspec/builder/mixins/_order_limit_operations.py +135 -0
  68. sqlspec/builder/mixins/_pivot_operations.py +153 -0
  69. sqlspec/builder/mixins/_select_operations.py +603 -0
  70. sqlspec/builder/mixins/_update_operations.py +187 -0
  71. sqlspec/builder/mixins/_where_clause.py +621 -0
  72. sqlspec/cli.py +247 -0
  73. sqlspec/config.py +395 -0
  74. sqlspec/core/__init__.py +63 -0
  75. sqlspec/core/cache.cpython-311-aarch64-linux-gnu.so +0 -0
  76. sqlspec/core/cache.py +871 -0
  77. sqlspec/core/compiler.cpython-311-aarch64-linux-gnu.so +0 -0
  78. sqlspec/core/compiler.py +417 -0
  79. sqlspec/core/filters.cpython-311-aarch64-linux-gnu.so +0 -0
  80. sqlspec/core/filters.py +830 -0
  81. sqlspec/core/hashing.cpython-311-aarch64-linux-gnu.so +0 -0
  82. sqlspec/core/hashing.py +310 -0
  83. sqlspec/core/parameters.cpython-311-aarch64-linux-gnu.so +0 -0
  84. sqlspec/core/parameters.py +1237 -0
  85. sqlspec/core/result.cpython-311-aarch64-linux-gnu.so +0 -0
  86. sqlspec/core/result.py +677 -0
  87. sqlspec/core/splitter.cpython-311-aarch64-linux-gnu.so +0 -0
  88. sqlspec/core/splitter.py +819 -0
  89. sqlspec/core/statement.cpython-311-aarch64-linux-gnu.so +0 -0
  90. sqlspec/core/statement.py +676 -0
  91. sqlspec/driver/__init__.py +19 -0
  92. sqlspec/driver/_async.py +502 -0
  93. sqlspec/driver/_common.py +631 -0
  94. sqlspec/driver/_sync.py +503 -0
  95. sqlspec/driver/mixins/__init__.py +6 -0
  96. sqlspec/driver/mixins/_result_tools.py +193 -0
  97. sqlspec/driver/mixins/_sql_translator.py +86 -0
  98. sqlspec/exceptions.py +193 -0
  99. sqlspec/extensions/__init__.py +0 -0
  100. sqlspec/extensions/aiosql/__init__.py +10 -0
  101. sqlspec/extensions/aiosql/adapter.py +461 -0
  102. sqlspec/extensions/litestar/__init__.py +6 -0
  103. sqlspec/extensions/litestar/_utils.py +52 -0
  104. sqlspec/extensions/litestar/cli.py +48 -0
  105. sqlspec/extensions/litestar/config.py +92 -0
  106. sqlspec/extensions/litestar/handlers.py +260 -0
  107. sqlspec/extensions/litestar/plugin.py +145 -0
  108. sqlspec/extensions/litestar/providers.py +454 -0
  109. sqlspec/loader.cpython-311-aarch64-linux-gnu.so +0 -0
  110. sqlspec/loader.py +760 -0
  111. sqlspec/migrations/__init__.py +35 -0
  112. sqlspec/migrations/base.py +414 -0
  113. sqlspec/migrations/commands.py +443 -0
  114. sqlspec/migrations/loaders.py +402 -0
  115. sqlspec/migrations/runner.py +213 -0
  116. sqlspec/migrations/tracker.py +140 -0
  117. sqlspec/migrations/utils.py +129 -0
  118. sqlspec/protocols.py +407 -0
  119. sqlspec/py.typed +0 -0
  120. sqlspec/storage/__init__.py +23 -0
  121. sqlspec/storage/backends/__init__.py +0 -0
  122. sqlspec/storage/backends/base.py +163 -0
  123. sqlspec/storage/backends/fsspec.py +386 -0
  124. sqlspec/storage/backends/obstore.py +459 -0
  125. sqlspec/storage/capabilities.py +102 -0
  126. sqlspec/storage/registry.py +239 -0
  127. sqlspec/typing.py +299 -0
  128. sqlspec/utils/__init__.py +3 -0
  129. sqlspec/utils/correlation.py +150 -0
  130. sqlspec/utils/deprecation.py +106 -0
  131. sqlspec/utils/fixtures.cpython-311-aarch64-linux-gnu.so +0 -0
  132. sqlspec/utils/fixtures.py +58 -0
  133. sqlspec/utils/logging.py +127 -0
  134. sqlspec/utils/module_loader.py +89 -0
  135. sqlspec/utils/serializers.py +4 -0
  136. sqlspec/utils/singleton.py +32 -0
  137. sqlspec/utils/sync_tools.cpython-311-aarch64-linux-gnu.so +0 -0
  138. sqlspec/utils/sync_tools.py +237 -0
  139. sqlspec/utils/text.cpython-311-aarch64-linux-gnu.so +0 -0
  140. sqlspec/utils/text.py +96 -0
  141. sqlspec/utils/type_guards.cpython-311-aarch64-linux-gnu.so +0 -0
  142. sqlspec/utils/type_guards.py +1139 -0
  143. sqlspec-0.16.1.dist-info/METADATA +365 -0
  144. sqlspec-0.16.1.dist-info/RECORD +148 -0
  145. sqlspec-0.16.1.dist-info/WHEEL +7 -0
  146. sqlspec-0.16.1.dist-info/entry_points.txt +2 -0
  147. sqlspec-0.16.1.dist-info/licenses/LICENSE +21 -0
  148. sqlspec-0.16.1.dist-info/licenses/NOTICE +29 -0
@@ -0,0 +1,298 @@
1
+ """BigQuery database configuration with direct field-based configuration."""
2
+
3
+ import contextlib
4
+ import logging
5
+ from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypedDict, Union
6
+
7
+ from google.cloud.bigquery import LoadJobConfig, QueryJobConfig
8
+ from typing_extensions import NotRequired
9
+
10
+ from sqlspec.adapters.bigquery._types import BigQueryConnection
11
+ from sqlspec.adapters.bigquery.driver import BigQueryCursor, BigQueryDriver, bigquery_statement_config
12
+ from sqlspec.config import NoPoolSyncConfig
13
+ from sqlspec.exceptions import ImproperConfigurationError
14
+ from sqlspec.typing import Empty
15
+
16
+ if TYPE_CHECKING:
17
+ from collections.abc import Generator
18
+
19
+ from google.api_core.client_info import ClientInfo
20
+ from google.api_core.client_options import ClientOptions
21
+ from google.auth.credentials import Credentials
22
+
23
+ from sqlspec.core.statement import StatementConfig
24
+
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ class BigQueryConnectionParams(TypedDict, total=False):
30
+ """Standard BigQuery connection parameters.
31
+
32
+ Includes both official BigQuery client parameters and BigQuery-specific configuration options.
33
+ """
34
+
35
+ # Official BigQuery client constructor parameters
36
+ project: NotRequired[str]
37
+ location: NotRequired[str]
38
+ credentials: NotRequired["Credentials"]
39
+ client_options: NotRequired["ClientOptions"]
40
+ client_info: NotRequired["ClientInfo"]
41
+
42
+ # BigQuery-specific configuration options
43
+ default_query_job_config: NotRequired[QueryJobConfig]
44
+ default_load_job_config: NotRequired[LoadJobConfig]
45
+ dataset_id: NotRequired[str]
46
+ credentials_path: NotRequired[str]
47
+ use_query_cache: NotRequired[bool]
48
+ maximum_bytes_billed: NotRequired[int]
49
+ enable_bigquery_ml: NotRequired[bool]
50
+ enable_gemini_integration: NotRequired[bool]
51
+ query_timeout_ms: NotRequired[int]
52
+ job_timeout_ms: NotRequired[int]
53
+ reservation_id: NotRequired[str]
54
+ edition: NotRequired[str]
55
+ enable_cross_cloud: NotRequired[bool]
56
+ enable_bigquery_omni: NotRequired[bool]
57
+ use_avro_logical_types: NotRequired[bool]
58
+ parquet_enable_list_inference: NotRequired[bool]
59
+ enable_column_level_security: NotRequired[bool]
60
+ enable_row_level_security: NotRequired[bool]
61
+ enable_dataframes: NotRequired[bool]
62
+ dataframes_backend: NotRequired[str]
63
+ enable_continuous_queries: NotRequired[bool]
64
+ enable_vector_search: NotRequired[bool]
65
+ extra: NotRequired[dict[str, Any]]
66
+
67
+
68
+ class BigQueryDriverFeatures(TypedDict, total=False):
69
+ """BigQuery driver-specific features configuration.
70
+
71
+ Only non-standard BigQuery client parameters that are SQLSpec-specific extensions.
72
+ """
73
+
74
+ on_job_start: NotRequired["Callable[[str], None]"]
75
+ on_job_complete: NotRequired["Callable[[str, Any], None]"]
76
+ on_connection_create: NotRequired["Callable[[Any], None]"]
77
+
78
+
79
+ __all__ = ("BigQueryConfig", "BigQueryConnectionParams", "BigQueryDriverFeatures")
80
+
81
+
82
+ class BigQueryConfig(NoPoolSyncConfig[BigQueryConnection, BigQueryDriver]):
83
+ """Enhanced BigQuery configuration with comprehensive feature support.
84
+
85
+ BigQuery is Google Cloud's serverless, highly scalable data warehouse with
86
+ advanced analytics, machine learning, and AI capabilities. This configuration
87
+ supports all BigQuery features including:
88
+ """
89
+
90
+ driver_type: ClassVar[type[BigQueryDriver]] = BigQueryDriver
91
+ connection_type: "ClassVar[type[BigQueryConnection]]" = BigQueryConnection
92
+
93
+ def __init__(
94
+ self,
95
+ *,
96
+ connection_instance: "Optional[BigQueryConnection]" = None,
97
+ connection_config: "Optional[Union[BigQueryConnectionParams, dict[str, Any]]]" = None,
98
+ migration_config: Optional[dict[str, Any]] = None,
99
+ statement_config: "Optional[StatementConfig]" = None,
100
+ driver_features: "Optional[Union[BigQueryDriverFeatures, dict[str, Any]]]" = None,
101
+ ) -> None:
102
+ """Initialize BigQuery configuration with comprehensive feature support.
103
+
104
+ Args:
105
+ connection_config: Standard connection configuration parameters
106
+ connection_instance: Existing connection instance to use
107
+ migration_config: Migration configuration
108
+ statement_config: Statement configuration override
109
+ driver_features: BigQuery-specific driver features and configurations
110
+
111
+ Example:
112
+ >>> # Basic BigQuery connection
113
+ >>> config = BigQueryConfig(
114
+ ... connection_config={
115
+ ... "project": "my-project",
116
+ ... "location": "US",
117
+ ... }
118
+ ... )
119
+
120
+ >>> # Advanced configuration with ML and AI features
121
+ >>> config = BigQueryConfig(
122
+ ... connection_config={
123
+ ... "project": "my-project",
124
+ ... "location": "US",
125
+ ... "enable_bigquery_ml": True,
126
+ ... "enable_gemini_integration": True,
127
+ ... "enable_dataframes": True,
128
+ ... "enable_vector_search": True,
129
+ ... "maximum_bytes_billed": 1000000000, # 1GB limit
130
+ ... }
131
+ ... )
132
+
133
+ >>> # Enterprise configuration with reservations
134
+ >>> config = BigQueryConfig(
135
+ ... connection_config={
136
+ ... "project": "my-project",
137
+ ... "location": "US",
138
+ ... "edition": "Enterprise Plus",
139
+ ... "reservation_id": "my-reservation",
140
+ ... "enable_continuous_queries": True,
141
+ ... "enable_cross_cloud": True,
142
+ ... }
143
+ ... )
144
+ """
145
+
146
+ # Store connection instance
147
+ self._connection_instance = connection_instance
148
+
149
+ # Setup configuration following DuckDB pattern
150
+ self.connection_config: dict[str, Any] = dict(connection_config) if connection_config else {}
151
+ if "extra" in self.connection_config:
152
+ extras = self.connection_config.pop("extra")
153
+ self.connection_config.update(extras)
154
+
155
+ # Setup driver features
156
+ self.driver_features: dict[str, Any] = dict(driver_features) if driver_features else {}
157
+
158
+ # Setup default job config if not provided
159
+ if "default_query_job_config" not in self.connection_config:
160
+ self._setup_default_job_config()
161
+
162
+ if statement_config is None:
163
+ statement_config = bigquery_statement_config
164
+
165
+ super().__init__(
166
+ connection_config=self.connection_config,
167
+ migration_config=migration_config,
168
+ statement_config=statement_config,
169
+ driver_features=self.driver_features,
170
+ )
171
+
172
+ def _setup_default_job_config(self) -> None:
173
+ """Set up default job configuration based on connection config."""
174
+ # Check if already provided in connection_config
175
+ if self.connection_config.get("default_query_job_config") is not None:
176
+ return
177
+
178
+ job_config = QueryJobConfig()
179
+
180
+ dataset_id = self.connection_config.get("dataset_id")
181
+ project = self.connection_config.get("project")
182
+ if dataset_id and project and "." not in dataset_id:
183
+ job_config.default_dataset = f"{project}.{dataset_id}"
184
+
185
+ use_query_cache = self.connection_config.get("use_query_cache")
186
+ if use_query_cache is not None:
187
+ job_config.use_query_cache = use_query_cache
188
+ else:
189
+ job_config.use_query_cache = True # Default to True
190
+
191
+ # Configure cost controls
192
+ maximum_bytes_billed = self.connection_config.get("maximum_bytes_billed")
193
+ if maximum_bytes_billed is not None:
194
+ job_config.maximum_bytes_billed = maximum_bytes_billed
195
+
196
+ # Configure timeouts
197
+ query_timeout_ms = self.connection_config.get("query_timeout_ms")
198
+ if query_timeout_ms is not None:
199
+ job_config.job_timeout_ms = query_timeout_ms
200
+
201
+ self.connection_config["default_query_job_config"] = job_config
202
+
203
+ def create_connection(self) -> BigQueryConnection:
204
+ """Create and return a new BigQuery Client instance.
205
+
206
+ Returns:
207
+ A new BigQuery Client instance.
208
+
209
+ Raises:
210
+ ImproperConfigurationError: If the connection could not be established.
211
+ """
212
+
213
+ if self._connection_instance is not None:
214
+ return self._connection_instance
215
+
216
+ try:
217
+ # Filter out extra fields and keep only official BigQuery client constructor fields
218
+ client_fields = {"project", "location", "credentials", "client_options", "client_info"}
219
+ config_dict: dict[str, Any] = {
220
+ field: value
221
+ for field, value in self.connection_config.items()
222
+ if field in client_fields and value is not None and value is not Empty
223
+ }
224
+ connection = self.connection_type(**config_dict)
225
+
226
+ # Store BigQuery-specific config in driver_features for driver access
227
+ default_query_job_config = self.connection_config.get("default_query_job_config")
228
+ if default_query_job_config is not None:
229
+ self.driver_features["default_query_job_config"] = default_query_job_config
230
+
231
+ default_load_job_config = self.connection_config.get("default_load_job_config")
232
+ if default_load_job_config is not None:
233
+ self.driver_features["default_load_job_config"] = default_load_job_config
234
+
235
+ # Call connection create callback from driver features
236
+ on_connection_create = self.driver_features.get("on_connection_create")
237
+ if on_connection_create:
238
+ on_connection_create(connection)
239
+
240
+ self._connection_instance = connection
241
+
242
+ except Exception as e:
243
+ project = self.connection_config.get("project", "Unknown")
244
+ msg = f"Could not configure BigQuery connection for project '{project}'. Error: {e}"
245
+ raise ImproperConfigurationError(msg) from e
246
+ return connection
247
+
248
+ @contextlib.contextmanager
249
+ def provide_connection(self, *_args: Any, **_kwargs: Any) -> "Generator[BigQueryConnection, None, None]":
250
+ """Provide a BigQuery client within a context manager.
251
+
252
+ Args:
253
+ *args: Additional arguments.
254
+ **kwargs: Additional keyword arguments.
255
+
256
+ Yields:
257
+ A BigQuery Client instance.
258
+ """
259
+ connection = self.create_connection()
260
+ yield connection
261
+
262
+ @contextlib.contextmanager
263
+ def provide_session(
264
+ self, *_args: Any, statement_config: "Optional[StatementConfig]" = None, **_kwargs: Any
265
+ ) -> "Generator[BigQueryDriver, None, None]":
266
+ """Provide a BigQuery driver session context manager.
267
+
268
+ Args:
269
+ *args: Additional arguments.
270
+ statement_config: Optional statement configuration override.
271
+ **kwargs: Additional keyword arguments.
272
+
273
+ Yields:
274
+ A context manager that yields a BigQueryDriver instance.
275
+ """
276
+
277
+ with self.provide_connection(*_args, **_kwargs) as connection:
278
+ # Use shared config or user-provided config or instance default
279
+ final_statement_config = statement_config or self.statement_config
280
+
281
+ driver = self.driver_type(
282
+ connection=connection, statement_config=final_statement_config, driver_features=self.driver_features
283
+ )
284
+ yield driver
285
+
286
+ def get_signature_namespace(self) -> "dict[str, type[Any]]":
287
+ """Get the signature namespace for BigQuery types.
288
+
289
+ This provides all BigQuery-specific types that Litestar needs to recognize
290
+ to avoid serialization attempts.
291
+
292
+ Returns:
293
+ Dictionary mapping type names to types.
294
+ """
295
+
296
+ namespace = super().get_signature_namespace()
297
+ namespace.update({"BigQueryConnection": BigQueryConnection, "BigQueryCursor": BigQueryCursor})
298
+ return namespace