sqlspec 0.14.1__py3-none-any.whl → 0.16.0__py3-none-any.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.
- sqlspec/__init__.py +50 -25
- sqlspec/__main__.py +1 -1
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +1 -2
- sqlspec/_sql.py +480 -121
- sqlspec/_typing.py +278 -142
- sqlspec/adapters/adbc/__init__.py +4 -3
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +115 -260
- sqlspec/adapters/adbc/driver.py +462 -367
- sqlspec/adapters/aiosqlite/__init__.py +18 -3
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +199 -129
- sqlspec/adapters/aiosqlite/driver.py +230 -269
- sqlspec/adapters/asyncmy/__init__.py +18 -3
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +80 -168
- sqlspec/adapters/asyncmy/driver.py +260 -225
- sqlspec/adapters/asyncpg/__init__.py +19 -4
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +82 -181
- sqlspec/adapters/asyncpg/driver.py +285 -383
- sqlspec/adapters/bigquery/__init__.py +17 -3
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +191 -258
- sqlspec/adapters/bigquery/driver.py +474 -646
- sqlspec/adapters/duckdb/__init__.py +14 -3
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +415 -351
- sqlspec/adapters/duckdb/driver.py +343 -413
- sqlspec/adapters/oracledb/__init__.py +19 -5
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +123 -379
- sqlspec/adapters/oracledb/driver.py +507 -560
- sqlspec/adapters/psqlpy/__init__.py +13 -3
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +93 -254
- sqlspec/adapters/psqlpy/driver.py +505 -234
- sqlspec/adapters/psycopg/__init__.py +19 -5
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +143 -403
- sqlspec/adapters/psycopg/driver.py +706 -872
- sqlspec/adapters/sqlite/__init__.py +14 -3
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +202 -118
- sqlspec/adapters/sqlite/driver.py +264 -303
- sqlspec/base.py +105 -9
- sqlspec/{statement/builder → builder}/__init__.py +12 -14
- sqlspec/{statement/builder → builder}/_base.py +120 -55
- sqlspec/{statement/builder → builder}/_column.py +17 -6
- sqlspec/{statement/builder → builder}/_ddl.py +46 -79
- sqlspec/{statement/builder → builder}/_ddl_utils.py +5 -10
- sqlspec/{statement/builder → builder}/_delete.py +6 -25
- sqlspec/{statement/builder → builder}/_insert.py +18 -65
- sqlspec/builder/_merge.py +56 -0
- sqlspec/{statement/builder → builder}/_parsing_utils.py +8 -11
- sqlspec/{statement/builder → builder}/_select.py +11 -56
- sqlspec/{statement/builder → builder}/_update.py +12 -18
- sqlspec/{statement/builder → builder}/mixins/__init__.py +10 -14
- sqlspec/{statement/builder → builder}/mixins/_cte_and_set_ops.py +48 -59
- sqlspec/{statement/builder → builder}/mixins/_insert_operations.py +34 -18
- sqlspec/{statement/builder → builder}/mixins/_join_operations.py +1 -3
- sqlspec/{statement/builder → builder}/mixins/_merge_operations.py +19 -9
- sqlspec/{statement/builder → builder}/mixins/_order_limit_operations.py +3 -3
- sqlspec/{statement/builder → builder}/mixins/_pivot_operations.py +4 -8
- sqlspec/{statement/builder → builder}/mixins/_select_operations.py +25 -38
- sqlspec/{statement/builder → builder}/mixins/_update_operations.py +15 -16
- sqlspec/{statement/builder → builder}/mixins/_where_clause.py +210 -137
- sqlspec/cli.py +4 -5
- sqlspec/config.py +180 -133
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.py +873 -0
- sqlspec/core/compiler.py +396 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.py +1209 -0
- sqlspec/core/result.py +664 -0
- sqlspec/{statement → core}/splitter.py +321 -191
- sqlspec/core/statement.py +666 -0
- sqlspec/driver/__init__.py +7 -10
- sqlspec/driver/_async.py +387 -176
- sqlspec/driver/_common.py +527 -289
- sqlspec/driver/_sync.py +390 -172
- sqlspec/driver/mixins/__init__.py +2 -19
- sqlspec/driver/mixins/_result_tools.py +164 -0
- sqlspec/driver/mixins/_sql_translator.py +6 -3
- sqlspec/exceptions.py +5 -252
- sqlspec/extensions/aiosql/adapter.py +93 -96
- sqlspec/extensions/litestar/cli.py +1 -1
- sqlspec/extensions/litestar/config.py +0 -1
- sqlspec/extensions/litestar/handlers.py +15 -26
- sqlspec/extensions/litestar/plugin.py +18 -16
- sqlspec/extensions/litestar/providers.py +17 -52
- sqlspec/loader.py +424 -105
- sqlspec/migrations/__init__.py +12 -0
- sqlspec/migrations/base.py +92 -68
- sqlspec/migrations/commands.py +24 -106
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +49 -51
- sqlspec/migrations/tracker.py +31 -44
- sqlspec/migrations/utils.py +64 -24
- sqlspec/protocols.py +7 -183
- sqlspec/storage/__init__.py +1 -1
- sqlspec/storage/backends/base.py +37 -40
- sqlspec/storage/backends/fsspec.py +136 -112
- sqlspec/storage/backends/obstore.py +138 -160
- sqlspec/storage/capabilities.py +5 -4
- sqlspec/storage/registry.py +57 -106
- sqlspec/typing.py +136 -115
- sqlspec/utils/__init__.py +2 -3
- sqlspec/utils/correlation.py +0 -3
- sqlspec/utils/deprecation.py +6 -6
- sqlspec/utils/fixtures.py +6 -6
- sqlspec/utils/logging.py +0 -2
- sqlspec/utils/module_loader.py +7 -12
- sqlspec/utils/singleton.py +0 -1
- sqlspec/utils/sync_tools.py +17 -38
- sqlspec/utils/text.py +12 -51
- sqlspec/utils/type_guards.py +443 -232
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/METADATA +7 -2
- sqlspec-0.16.0.dist-info/RECORD +134 -0
- sqlspec/adapters/adbc/transformers.py +0 -108
- sqlspec/driver/connection.py +0 -207
- sqlspec/driver/mixins/_cache.py +0 -114
- sqlspec/driver/mixins/_csv_writer.py +0 -91
- sqlspec/driver/mixins/_pipeline.py +0 -508
- sqlspec/driver/mixins/_query_tools.py +0 -796
- sqlspec/driver/mixins/_result_utils.py +0 -138
- sqlspec/driver/mixins/_storage.py +0 -912
- sqlspec/driver/mixins/_type_coercion.py +0 -128
- sqlspec/driver/parameters.py +0 -138
- sqlspec/statement/__init__.py +0 -21
- sqlspec/statement/builder/_merge.py +0 -95
- sqlspec/statement/cache.py +0 -50
- sqlspec/statement/filters.py +0 -625
- sqlspec/statement/parameters.py +0 -956
- sqlspec/statement/pipelines/__init__.py +0 -210
- sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
- sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
- sqlspec/statement/pipelines/context.py +0 -109
- sqlspec/statement/pipelines/transformers/__init__.py +0 -7
- sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
- sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
- sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
- sqlspec/statement/pipelines/validators/__init__.py +0 -23
- sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
- sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
- sqlspec/statement/pipelines/validators/_performance.py +0 -714
- sqlspec/statement/pipelines/validators/_security.py +0 -967
- sqlspec/statement/result.py +0 -435
- sqlspec/statement/sql.py +0 -1774
- sqlspec/utils/cached_property.py +0 -25
- sqlspec/utils/statement_hashing.py +0 -203
- sqlspec-0.14.1.dist-info/RECORD +0 -145
- /sqlspec/{statement/builder → builder}/mixins/_delete_operations.py +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/entry_points.txt +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"""SQL Statement Processing Pipelines.
|
|
2
|
-
|
|
3
|
-
This module defines the framework for processing SQL statements through a series of
|
|
4
|
-
configurable stages: transformation, validation, and analysis.
|
|
5
|
-
|
|
6
|
-
Key Components:
|
|
7
|
-
- `SQLProcessingContext`: Holds shared data and state during pipeline execution.
|
|
8
|
-
- `StatementPipelineResult`: Encapsulates the final results of a pipeline run.
|
|
9
|
-
- `StatementPipeline`: The main orchestrator for executing the processing stages.
|
|
10
|
-
- `ProcessorProtocol`: The base protocol for all pipeline components (transformers,
|
|
11
|
-
validators, analyzers).
|
|
12
|
-
- `ValidationError`: Represents a single issue found during validation.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
from dataclasses import dataclass
|
|
16
|
-
from typing import TYPE_CHECKING, Optional
|
|
17
|
-
|
|
18
|
-
import sqlglot
|
|
19
|
-
from sqlglot import exp
|
|
20
|
-
from typing_extensions import TypeVar
|
|
21
|
-
|
|
22
|
-
from sqlspec.exceptions import RiskLevel
|
|
23
|
-
from sqlspec.protocols import ProcessorProtocol
|
|
24
|
-
from sqlspec.statement.pipelines.context import (
|
|
25
|
-
AnalysisFinding,
|
|
26
|
-
SQLProcessingContext,
|
|
27
|
-
TransformationLog,
|
|
28
|
-
ValidationError,
|
|
29
|
-
)
|
|
30
|
-
from sqlspec.statement.pipelines.transformers import (
|
|
31
|
-
CommentAndHintRemover,
|
|
32
|
-
ExpressionSimplifier,
|
|
33
|
-
ParameterizeLiterals,
|
|
34
|
-
SimplificationConfig,
|
|
35
|
-
)
|
|
36
|
-
from sqlspec.statement.pipelines.validators import (
|
|
37
|
-
DMLSafetyConfig,
|
|
38
|
-
DMLSafetyValidator,
|
|
39
|
-
ParameterStyleValidator,
|
|
40
|
-
PerformanceConfig,
|
|
41
|
-
PerformanceValidator,
|
|
42
|
-
SecurityValidator,
|
|
43
|
-
SecurityValidatorConfig,
|
|
44
|
-
)
|
|
45
|
-
from sqlspec.utils.correlation import CorrelationContext
|
|
46
|
-
from sqlspec.utils.logging import get_logger
|
|
47
|
-
|
|
48
|
-
if TYPE_CHECKING:
|
|
49
|
-
from sqlspec.statement.parameters import ParameterInfo
|
|
50
|
-
from sqlspec.typing import SQLParameterType
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
__all__ = (
|
|
54
|
-
"AnalysisFinding",
|
|
55
|
-
"CommentAndHintRemover",
|
|
56
|
-
"DMLSafetyConfig",
|
|
57
|
-
"DMLSafetyValidator",
|
|
58
|
-
"ExpressionSimplifier",
|
|
59
|
-
"ParameterStyleValidator",
|
|
60
|
-
"ParameterizeLiterals",
|
|
61
|
-
"PerformanceConfig",
|
|
62
|
-
"PerformanceValidator",
|
|
63
|
-
"PipelineResult",
|
|
64
|
-
"ProcessorProtocol",
|
|
65
|
-
"SQLProcessingContext",
|
|
66
|
-
"SecurityValidator",
|
|
67
|
-
"SecurityValidatorConfig",
|
|
68
|
-
"SimplificationConfig",
|
|
69
|
-
"StatementPipeline",
|
|
70
|
-
"TransformationLog",
|
|
71
|
-
"ValidationError",
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
logger = get_logger("pipelines")
|
|
75
|
-
|
|
76
|
-
ExpressionT = TypeVar("ExpressionT", bound="exp.Expression")
|
|
77
|
-
ResultT = TypeVar("ResultT")
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# Import from context module to avoid duplication
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@dataclass
|
|
84
|
-
class PipelineResult:
|
|
85
|
-
"""Final result of pipeline execution."""
|
|
86
|
-
|
|
87
|
-
expression: exp.Expression
|
|
88
|
-
"""The SQL expression after all transformations."""
|
|
89
|
-
|
|
90
|
-
context: SQLProcessingContext
|
|
91
|
-
"""Contains all collected results."""
|
|
92
|
-
|
|
93
|
-
@property
|
|
94
|
-
def validation_errors(self) -> list[ValidationError]:
|
|
95
|
-
"""Get validation errors from context."""
|
|
96
|
-
return self.context.validation_errors
|
|
97
|
-
|
|
98
|
-
@property
|
|
99
|
-
def has_errors(self) -> bool:
|
|
100
|
-
"""Check if any validation errors exist."""
|
|
101
|
-
return self.context.has_errors
|
|
102
|
-
|
|
103
|
-
@property
|
|
104
|
-
def risk_level(self) -> RiskLevel:
|
|
105
|
-
"""Get overall risk level."""
|
|
106
|
-
return self.context.risk_level
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def merged_parameters(self) -> "SQLParameterType":
|
|
110
|
-
"""Get merged parameters from context."""
|
|
111
|
-
return self.context.merged_parameters
|
|
112
|
-
|
|
113
|
-
@property
|
|
114
|
-
def parameter_info(self) -> "list[ParameterInfo]":
|
|
115
|
-
"""Get parameter info from context."""
|
|
116
|
-
return self.context.parameter_info
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
class StatementPipeline:
|
|
120
|
-
"""Orchestrates the processing of an SQL expression through transformers, validators, and analyzers."""
|
|
121
|
-
|
|
122
|
-
def __init__(
|
|
123
|
-
self,
|
|
124
|
-
transformers: Optional[list[ProcessorProtocol]] = None,
|
|
125
|
-
validators: Optional[list[ProcessorProtocol]] = None,
|
|
126
|
-
analyzers: Optional[list[ProcessorProtocol]] = None,
|
|
127
|
-
) -> None:
|
|
128
|
-
self.transformers = transformers or []
|
|
129
|
-
self.validators = validators or []
|
|
130
|
-
self.analyzers = analyzers or []
|
|
131
|
-
|
|
132
|
-
def _run_processors(
|
|
133
|
-
self,
|
|
134
|
-
processors: list[ProcessorProtocol],
|
|
135
|
-
context: SQLProcessingContext,
|
|
136
|
-
processor_type: str,
|
|
137
|
-
enable_flag: bool,
|
|
138
|
-
error_risk_level: RiskLevel,
|
|
139
|
-
) -> None:
|
|
140
|
-
if not enable_flag or context.current_expression is None:
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
for processor in processors:
|
|
144
|
-
processor_name = processor.__class__.__name__
|
|
145
|
-
try:
|
|
146
|
-
if processor_type == "transformer":
|
|
147
|
-
context.current_expression = processor.process(context.current_expression, context)
|
|
148
|
-
else:
|
|
149
|
-
processor.process(context.current_expression, context)
|
|
150
|
-
except Exception as e:
|
|
151
|
-
# In strict mode, re-raise validation exceptions
|
|
152
|
-
from sqlspec.exceptions import MissingParameterError
|
|
153
|
-
from sqlspec.statement.pipelines.validators._parameter_style import (
|
|
154
|
-
MixedParameterStyleError,
|
|
155
|
-
UnsupportedParameterStyleError,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
if not context.config.parse_errors_as_warnings and isinstance(
|
|
159
|
-
e, (MissingParameterError, MixedParameterStyleError, UnsupportedParameterStyleError)
|
|
160
|
-
):
|
|
161
|
-
raise
|
|
162
|
-
|
|
163
|
-
error = ValidationError(
|
|
164
|
-
message=f"{processor_type.capitalize()} {processor_name} failed: {e}",
|
|
165
|
-
code=f"{processor_type}-failure",
|
|
166
|
-
risk_level=error_risk_level,
|
|
167
|
-
processor=processor_name,
|
|
168
|
-
expression=context.current_expression,
|
|
169
|
-
)
|
|
170
|
-
context.validation_errors.append(error)
|
|
171
|
-
logger.exception("%s %s failed", processor_type.capitalize(), processor_name)
|
|
172
|
-
if processor_type == "transformer":
|
|
173
|
-
break # Stop further transformations if one fails
|
|
174
|
-
|
|
175
|
-
def execute_pipeline(self, context: "SQLProcessingContext") -> "PipelineResult":
|
|
176
|
-
"""Executes the full pipeline (transform, validate, analyze) using the SQLProcessingContext."""
|
|
177
|
-
CorrelationContext.get()
|
|
178
|
-
if context.current_expression is None:
|
|
179
|
-
try:
|
|
180
|
-
context.current_expression = sqlglot.parse_one(context.initial_sql_string, dialect=context.dialect)
|
|
181
|
-
except Exception as e:
|
|
182
|
-
error = ValidationError(
|
|
183
|
-
message=f"SQL Parsing Error: {e}",
|
|
184
|
-
code="parsing-error",
|
|
185
|
-
risk_level=RiskLevel.CRITICAL,
|
|
186
|
-
processor="StatementPipeline",
|
|
187
|
-
expression=None,
|
|
188
|
-
)
|
|
189
|
-
context.validation_errors.append(error)
|
|
190
|
-
return PipelineResult(expression=exp.Select(), context=context)
|
|
191
|
-
|
|
192
|
-
# Run transformers
|
|
193
|
-
if self.transformers:
|
|
194
|
-
self._run_processors(
|
|
195
|
-
self.transformers, context, "transformer", enable_flag=True, error_risk_level=RiskLevel.CRITICAL
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
# Run validators
|
|
199
|
-
if self.validators:
|
|
200
|
-
self._run_processors(
|
|
201
|
-
self.validators, context, "validator", enable_flag=True, error_risk_level=RiskLevel.CRITICAL
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
# Run analyzers
|
|
205
|
-
if self.analyzers:
|
|
206
|
-
self._run_processors(
|
|
207
|
-
self.analyzers, context, "analyzer", enable_flag=True, error_risk_level=RiskLevel.MEDIUM
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
return PipelineResult(expression=context.current_expression or exp.Select(), context=context)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"""SQL Analysis Pipeline Components.
|
|
2
|
-
|
|
3
|
-
This module provides analysis components that can extract metadata and insights
|
|
4
|
-
from SQL statements as part of the processing pipeline.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from sqlspec.statement.pipelines.analyzers._analyzer import StatementAnalysis, StatementAnalyzer
|
|
8
|
-
|
|
9
|
-
__all__ = ("StatementAnalysis", "StatementAnalyzer")
|