sql-dialect-master 1.1.1__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.
- backend/__init__.py +1 -0
- backend/api/__init__.py +1 -0
- backend/api/main.py +732 -0
- backend/api/middleware.py +274 -0
- backend/api/rate_limit_store.py +105 -0
- backend/api/readiness.py +178 -0
- backend/core/__init__.py +57 -0
- backend/core/cache.py +261 -0
- backend/core/column_hint_validation.py +22 -0
- backend/core/config.py +546 -0
- backend/core/constants.py +84 -0
- backend/core/exceptions.py +124 -0
- backend/core/function_call_scanner.py +64 -0
- backend/core/function_semantics.py +148 -0
- backend/core/functions_db.json +601 -0
- backend/core/functions_lookup.py +332 -0
- backend/core/metadata.py +71 -0
- backend/core/nl2sql.py +85 -0
- backend/core/nl2sql_components/__init__.py +72 -0
- backend/core/nl2sql_components/aggregations.py +35 -0
- backend/core/nl2sql_components/boolean_conditions.py +279 -0
- backend/core/nl2sql_components/core_extract.py +106 -0
- backend/core/nl2sql_components/evidence.py +122 -0
- backend/core/nl2sql_components/mappings.py +185 -0
- backend/core/nl2sql_components/relations.py +180 -0
- backend/core/nl2sql_components/templates.py +130 -0
- backend/core/nl2sql_components/tokenizer.py +187 -0
- backend/core/nl2sql_legacy.py +22 -0
- backend/core/nl2sql_pipeline/__init__.py +13 -0
- backend/core/nl2sql_pipeline/aggregations.py +26 -0
- backend/core/nl2sql_pipeline/clause_extract.py +97 -0
- backend/core/nl2sql_pipeline/dialect.py +139 -0
- backend/core/nl2sql_pipeline/intent.py +85 -0
- backend/core/nl2sql_pipeline/ir.py +70 -0
- backend/core/nl2sql_pipeline/models.py +30 -0
- backend/core/nl2sql_pipeline/orchestrator.py +576 -0
- backend/core/nl2sql_pipeline/predicates.py +182 -0
- backend/core/nl2sql_pipeline/renderer.py +248 -0
- backend/core/nl2sql_pipeline/resolution.py +69 -0
- backend/core/nl2sql_pipeline/suggestions.py +30 -0
- backend/core/nl2sql_pipeline/templates.py +371 -0
- backend/core/nl2sql_pipeline/validation.py +28 -0
- backend/core/p1_sql_scanner.py +196 -0
- backend/core/p2_data_validation.py +72 -0
- backend/core/parser.py +280 -0
- backend/core/post_processor.py +129 -0
- backend/core/rules.py +808 -0
- backend/core/semantic_diff.py +385 -0
- backend/core/transpiler.py +791 -0
- backend/core/type_mapping.json +593 -0
- backend/core/type_mapping.py +765 -0
- backend/utils/__init__.py +2 -0
- backend/utils/validators.py +407 -0
- frontend/__init__.py +10 -0
- frontend/app_context_v2.py +201 -0
- frontend/core/__init__.py +33 -0
- frontend/core/design_tokens.py +127 -0
- frontend/core/escaping.py +13 -0
- frontend/core/navigation.py +135 -0
- frontend/core/state.py +612 -0
- frontend/core/styles.py +523 -0
- frontend/core/themes.py +69 -0
- frontend/core/viewmodels.py +499 -0
- frontend/pages/__init__.py +0 -0
- frontend/pages/convert.py +283 -0
- frontend/pages/diff.py +157 -0
- frontend/pages/functions.py +100 -0
- frontend/pages/history.py +144 -0
- frontend/pages/lineage.py +168 -0
- frontend/pages/nl2sql.py +305 -0
- frontend/pages/query_analysis.py +120 -0
- frontend/pages/runtime.py +66 -0
- frontend/pages/settings.py +60 -0
- frontend/pages/templates.py +67 -0
- frontend/pages/types.py +110 -0
- frontend/templates_v2.py +53 -0
- frontend/ui/__init__.py +0 -0
- frontend/ui/command_palette.py +153 -0
- frontend/ui/diff.py +275 -0
- frontend/ui/editor.py +102 -0
- frontend/ui/status.py +255 -0
- sql_dialect_master-1.1.1.dist-info/METADATA +360 -0
- sql_dialect_master-1.1.1.dist-info/RECORD +86 -0
- sql_dialect_master-1.1.1.dist-info/WHEEL +5 -0
- sql_dialect_master-1.1.1.dist-info/licenses/LICENSE +21 -0
- sql_dialect_master-1.1.1.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sql-dialect-master
|
|
3
|
+
Version: 1.1.1
|
|
4
|
+
Summary: SQL Dialect Master - Multi-database SQL conversion engine
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: sqlglot>=25.0.0
|
|
9
|
+
Requires-Dist: streamlit>=1.38.0
|
|
10
|
+
Requires-Dist: fastapi>=0.115.0
|
|
11
|
+
Requires-Dist: uvicorn>=0.30.0
|
|
12
|
+
Requires-Dist: pydantic>=2.9.0
|
|
13
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: hypothesis>=6.112.0; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest>=8.3.0; extra == "dev"
|
|
17
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
18
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
19
|
+
Provides-Extra: qa
|
|
20
|
+
Requires-Dist: ruff>=0.6; extra == "qa"
|
|
21
|
+
Requires-Dist: bandit>=1.7; extra == "qa"
|
|
22
|
+
Requires-Dist: pip-audit>=2.7; extra == "qa"
|
|
23
|
+
Provides-Extra: semantic
|
|
24
|
+
Requires-Dist: duckdb>=1.5.5; extra == "semantic"
|
|
25
|
+
Requires-Dist: psycopg[binary]>=3.3.5; extra == "semantic"
|
|
26
|
+
Provides-Extra: redis
|
|
27
|
+
Requires-Dist: redis>=5.0.0; extra == "redis"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# 🔄 SQL Dialect Master
|
|
31
|
+
|
|
32
|
+
Enterprise-grade multi-database SQL conversion engine supporting 12 database dialects.
|
|
33
|
+
|
|
34
|
+
Current release: 1.1.1
|
|
35
|
+
|
|
36
|
+
[](https://www.python.org/downloads/)
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
[](https://fastapi.tiangolo.com/)
|
|
39
|
+
[](https://streamlit.io/)
|
|
40
|
+
|
|
41
|
+
## ✨ Features
|
|
42
|
+
|
|
43
|
+
| Feature | Description |
|
|
44
|
+
|---------|-------------|
|
|
45
|
+
| 🔄 **SQL Conversion** | Convert SQL between 12 database dialects with a complete 12 × 12 conversion matrix |
|
|
46
|
+
| ✅ **Output Validation** | Validate converted SQL with target-dialect parsing plus safe generic-parser fallback |
|
|
47
|
+
| 🧠 **Semantic Regression Coverage** | Preserve predicates, joins, grouping, ordering, limits, windows, and round-trip validity |
|
|
48
|
+
| 🔍 **AST Semantic Diff** | Compare dialect-aware SQL ASTs to detect structural changes introduced by conversion |
|
|
49
|
+
| 🗄️ **Runtime Semantic Tests** | Execute representative conversions against PostgreSQL and DuckDB and compare result sets |
|
|
50
|
+
| 📚 **Function Encyclopedia** | 298 SQL functions with cross-database comparison |
|
|
51
|
+
| 🗂️ **Type Mapping** | 39 data types × 12 databases matrix |
|
|
52
|
+
| 💬 **NL2SQL** | Natural language to SQL (Chinese/English) |
|
|
53
|
+
| 🔧 **Rule Engine** | Deterministic priority ordering, compiled patterns, dialect-aware conflict detection |
|
|
54
|
+
| 🛡️ **Security Validation** | Statement-level stacked-query detection with configurable blocking policy |
|
|
55
|
+
| ⚡ **Performance** | Rule-aware cache versioning, bounded async batch conversion, and reproducible benchmark |
|
|
56
|
+
| 🎨 **Modern UI** | Streamlit developer workspace: dark / light theme system, sidebar navigation, command palette |
|
|
57
|
+
|
|
58
|
+
## 💾 Supported Databases
|
|
59
|
+
|
|
60
|
+
| Category | Databases |
|
|
61
|
+
|----------|-----------|
|
|
62
|
+
| **RDBMS** | MySQL 🐬, PostgreSQL 🐘, Oracle 🔴, SQL Server 🟦 |
|
|
63
|
+
| **Big Data** | Hive 🐝, Spark ⚡, Trino 🔷, Databricks 🧱 |
|
|
64
|
+
| **Cloud DW** | Snowflake ❄️, Redshift 🔶 |
|
|
65
|
+
| **OLAP** | ClickHouse 🏠, DuckDB 🦆 |
|
|
66
|
+
|
|
67
|
+
## 🚀 Quick Start
|
|
68
|
+
|
|
69
|
+
### Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Clone the repository
|
|
73
|
+
git clone https://github.com/zengxiangdi/sql-dialect-master.git
|
|
74
|
+
cd sql-dialect-master
|
|
75
|
+
|
|
76
|
+
# Install the application package
|
|
77
|
+
python -m pip install -e .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For development and testing, install the optional development dependencies:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python -m pip install -e ".[dev]"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
For database-backed semantic tests:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python -m pip install -e ".[dev,semantic]"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Run Streamlit UI (Recommended)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
streamlit run sdm_local_v2.py
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Open http://localhost:8501 in your browser.
|
|
99
|
+
|
|
100
|
+
### Run FastAPI Backend
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uvicorn backend.api.main:app --reload
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
API docs available at http://localhost:8000/docs
|
|
107
|
+
|
|
108
|
+
## 📖 Usage Examples
|
|
109
|
+
|
|
110
|
+
### Python SDK
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from backend.core import SQLTranspiler
|
|
114
|
+
|
|
115
|
+
transpiler = SQLTranspiler()
|
|
116
|
+
result = transpiler.transpile(
|
|
117
|
+
sql="SELECT DATE_FORMAT(created_at, '%Y-%m-%d') FROM orders LIMIT 10",
|
|
118
|
+
source="mysql",
|
|
119
|
+
target="postgres"
|
|
120
|
+
)
|
|
121
|
+
print(result.target_sql)
|
|
122
|
+
# Output: SELECT TO_CHAR(created_at, 'YYYY-MM-DD') FROM orders LIMIT 10
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### REST API
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
curl -X POST http://localhost:8000/api/convert \
|
|
129
|
+
-H "Content-Type: application/json" \
|
|
130
|
+
-d '{
|
|
131
|
+
"sql": "SELECT * FROM users LIMIT 10",
|
|
132
|
+
"source_dialect": "mysql",
|
|
133
|
+
"target_dialect": "hive"
|
|
134
|
+
}'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Successful and failed conversions return structured metadata. Failed conversions expose a stable machine-readable `error_code` alongside the human-readable `error` message.
|
|
138
|
+
|
|
139
|
+
### NL2SQL (Natural Language)
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from backend.core import NL2SQLGenerator
|
|
143
|
+
|
|
144
|
+
generator = NL2SQLGenerator()
|
|
145
|
+
result = generator.generate("查询最近7天的订单", dialect="mysql")
|
|
146
|
+
print(result.sql)
|
|
147
|
+
# Output: SELECT * FROM orders WHERE created_at >= DATE_SUB(CURRENT_DATE, 7)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Relational Query Support (D2)
|
|
151
|
+
|
|
152
|
+
NL2SQL supports existential relationship queries using `EXISTS` / `NOT EXISTS` subqueries instead of physical `JOIN`s, preserving row count and avoiding duplicate expansion from 1:N relationships.
|
|
153
|
+
|
|
154
|
+
**Known relationships** (explicit mapping):
|
|
155
|
+
- `users ↔ orders`: `users.id = orders.user_id`
|
|
156
|
+
- `customers ↔ orders`: `customers.id = orders.customer_id`
|
|
157
|
+
- `orders ↔ products`: `orders.product_id = products.id`
|
|
158
|
+
- `employees ↔ departments`: `employees.dept_id = departments.id`
|
|
159
|
+
|
|
160
|
+
**Examples:**
|
|
161
|
+
```python
|
|
162
|
+
# Positive relational query → EXISTS
|
|
163
|
+
result = generator.generate("find users who have orders", "postgres")
|
|
164
|
+
# Output: SELECT * FROM users WHERE EXISTS (SELECT 1 FROM orders WHERE users.id = orders.user_id)
|
|
165
|
+
|
|
166
|
+
# Negative relational query → NOT EXISTS
|
|
167
|
+
result = generator.generate("find users without orders", "postgres")
|
|
168
|
+
# Output: SELECT * FROM users WHERE NOT EXISTS (SELECT 1 FROM orders WHERE users.id = orders.user_id)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Unknown relationships fail safely:**
|
|
172
|
+
```python
|
|
173
|
+
result = generator.generate("find users who have invoices", "postgres")
|
|
174
|
+
# Output: success=False, explanation="Unable to safely infer the relationship..."
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Relationship inference uses explicit mapping only — no fabricated foreign keys. Use `table_hint` to specify schema-qualified tables when needed.
|
|
178
|
+
|
|
179
|
+
#### Date Arithmetic Semantics (D3)
|
|
180
|
+
|
|
181
|
+
Date expressions follow a **rolling vs calendar-relative** distinction:
|
|
182
|
+
|
|
183
|
+
| Expression | Semantic | DSL (postgres) |
|
|
184
|
+
|------------|----------|----------------|
|
|
185
|
+
| `today` | current calendar date | `= CURRENT_DATE` |
|
|
186
|
+
| `yesterday` | rolling -1 day | `= DATE_SUB(CURRENT_DATE, 1)` |
|
|
187
|
+
| `tomorrow` | rolling +1 day | `= DATE_ADD(CURRENT_DATE, 1)` |
|
|
188
|
+
| `last N days` | rolling N days | `>= DATE_SUB(CURRENT_DATE, N)` |
|
|
189
|
+
| `last N weeks` | rolling N×7 days | `>= DATE_SUB(CURRENT_DATE, N×7)` |
|
|
190
|
+
| `last week` | rolling 7 days | `>= DATE_SUB(CURRENT_DATE, 7)` |
|
|
191
|
+
| `last N months` | calendar -N months | `>= ADD_MONTHS(CURRENT_DATE, -N)` |
|
|
192
|
+
| `last month` | calendar -1 month | `>= ADD_MONTHS(CURRENT_DATE, -1)` |
|
|
193
|
+
| `last N years` | calendar -N years | `>= ADD_MONTHS(CURRENT_DATE, -N×12)` |
|
|
194
|
+
| `last year` | calendar -1 year | `>= ADD_MONTHS(CURRENT_DATE, -12)` |
|
|
195
|
+
|
|
196
|
+
**Key distinction:** `last week` uses a rolling 7-day window, while `last month`/`last year` use calendar arithmetic (`ADD_MONTHS`). This means `last month` from March 31 yields February 28/29 (not 30 days prior), and `last year` preserves month/day within the calendar.
|
|
197
|
+
|
|
198
|
+
Date conditions in combined queries (e.g., "users who have orders from last 7 days") are scoped to the relation table's date column inside the `EXISTS` subquery.
|
|
199
|
+
|
|
200
|
+
#### Type Mapping with Precision (D1)
|
|
201
|
+
|
|
202
|
+
TypeMapper now supports parameterized types and precision-aware warnings:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from backend.core import TypeMapper
|
|
206
|
+
|
|
207
|
+
mapper = TypeMapper()
|
|
208
|
+
result = mapper.map_type("VARCHAR2(2000)", "oracle", "postgres")
|
|
209
|
+
# Output: source_type="VARCHAR2(n)", target_type="VARCHAR(n)", precision=2000
|
|
210
|
+
|
|
211
|
+
result = mapper.map_type("VARCHAR2(8000)", "oracle", "postgres")
|
|
212
|
+
# Output: warnings include "exceeds Oracle's default VARCHAR2 limit of 4000"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Supports `VARCHAR`, `VARCHAR2`, `NVARCHAR`, `CHAR` with numeric precision or `MAX`. Unknown parameterized types resolve to the canonical base type.
|
|
216
|
+
|
|
217
|
+
## 🏗️ Project Structure
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
sql-dialect-master/
|
|
221
|
+
├── backend/
|
|
222
|
+
│ ├── api/
|
|
223
|
+
│ │ ├── main.py # FastAPI application
|
|
224
|
+
│ │ └── middleware.py # Rate limiting, logging
|
|
225
|
+
│ ├── benchmarks/
|
|
226
|
+
│ │ └── transpiler_benchmark.py # Reproducible conversion benchmark
|
|
227
|
+
│ ├── core/
|
|
228
|
+
│ │ ├── nl2sql_components/ # Modular NL2SQL components
|
|
229
|
+
│ │ │ ├── tokenizer.py # Language tokenization
|
|
230
|
+
│ │ │ ├── templates.py # Query templates
|
|
231
|
+
│ │ │ └── mappings.py # Language mappings
|
|
232
|
+
│ │ ├── config.py # Configuration management
|
|
233
|
+
│ │ ├── transpiler.py # SQL conversion engine
|
|
234
|
+
│ │ ├── parser.py # SQL parser
|
|
235
|
+
│ │ ├── semantic_diff.py # AST-based semantic difference detector
|
|
236
|
+
│ │ ├── rules.py # Transformation rules
|
|
237
|
+
│ │ ├── post_processor.py # Post-processing
|
|
238
|
+
│ │ ├── nl2sql.py # Natural language to SQL
|
|
239
|
+
│ │ ├── functions_lookup.py # Function encyclopedia
|
|
240
|
+
│ │ ├── functions_db.json # Functions database
|
|
241
|
+
│ │ ├── type_mapping.py # Type mapping
|
|
242
|
+
│ │ ├── type_mapping.json # Types database
|
|
243
|
+
│ │ ├── cache.py # TTL cache
|
|
244
|
+
│ │ └── exceptions.py # Custom exceptions + ErrorCode taxonomy
|
|
245
|
+
│ ├── utils/
|
|
246
|
+
│ │ └── validators.py # Input validation
|
|
247
|
+
│ │
|
|
248
|
+
│ └── tests/ # Test suite and regression coverage
|
|
249
|
+
├── frontend/ # Streamlit UI Components (v2 architecture)
|
|
250
|
+
│ ├── core/ # Cross-cutting concerns
|
|
251
|
+
│ │ ├── design_tokens.py # Theme model (dark/light) + semantic status
|
|
252
|
+
│ │ ├── navigation.py # NavigationIntent contract
|
|
253
|
+
│ │ ├── state.py # SessionState adapter
|
|
254
|
+
│ │ ├── themes.py # Theme switching (dark/light only)
|
|
255
|
+
│ │ ├── styles.py # CSS generation from design tokens
|
|
256
|
+
│ │ ├── escaping.py # HTML-safe rendering helpers
|
|
257
|
+
│ │ └── viewmodels.py # Typed view models
|
|
258
|
+
│ ├── pages/ # One module per workspace page
|
|
259
|
+
│ │ ├── convert.py
|
|
260
|
+
│ │ ├── nl2sql.py
|
|
261
|
+
│ │ ├── diff.py
|
|
262
|
+
│ │ ├── lineage.py
|
|
263
|
+
│ │ ├── runtime.py
|
|
264
|
+
│ │ ├── functions.py
|
|
265
|
+
│ │ ├── types.py
|
|
266
|
+
│ │ ├── templates.py
|
|
267
|
+
│ │ ├── history.py
|
|
268
|
+
│ │ ├── settings.py
|
|
269
|
+
│ │ └── query_analysis.py
|
|
270
|
+
│ ├── ui/ # Reusable UI widgets
|
|
271
|
+
│ │ ├── command_palette.py
|
|
272
|
+
│ │ ├── diff.py
|
|
273
|
+
│ │ ├── editor.py
|
|
274
|
+
│ │ └── status.py
|
|
275
|
+
│ ├── app_context_v2.py # Shared application context (v2)
|
|
276
|
+
│ └── templates_v2.py # SQL templates (v2)
|
|
277
|
+
├── examples/
|
|
278
|
+
│ ├── api_client.py # API usage examples
|
|
279
|
+
│ └── basic_usage.py # SDK usage examples
|
|
280
|
+
├── scripts/
|
|
281
|
+
│ └── verify_readme_consistency.py # README source-of-truth checks
|
|
282
|
+
├── sdm_local_v2.py # Streamlit Application Entry (v2)
|
|
283
|
+
├── pyproject.toml # Project configuration
|
|
284
|
+
├── requirements.txt # Legacy/runtime dependency list
|
|
285
|
+
├── .env.example # Environment template
|
|
286
|
+
├── LICENSE # MIT License
|
|
287
|
+
└── README.md
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## 🔧 API Endpoints
|
|
291
|
+
|
|
292
|
+
| Endpoint | Method | Description |
|
|
293
|
+
|----------|--------|-------------|
|
|
294
|
+
| `/api/convert` | POST | Convert SQL between dialects; response includes `error_code` on failure |
|
|
295
|
+
| `/api/parse` | POST | Parse SQL and extract structural elements |
|
|
296
|
+
| `/api/nl2sql` | POST | Generate SQL from natural language |
|
|
297
|
+
| `/api/functions` | GET | Search SQL functions |
|
|
298
|
+
| `/api/functions/{name}` | GET | Get function details |
|
|
299
|
+
| `/api/types` | GET | Get type mapping matrix |
|
|
300
|
+
| `/api/types/map` | POST | Map type between dialects |
|
|
301
|
+
| `/api/dialects` | GET | List supported dialects |
|
|
302
|
+
| `/health` | GET | Health check |
|
|
303
|
+
| `/health/deep` | GET | Deep health check |
|
|
304
|
+
| `/api/stats` | GET | Service and dataset statistics |
|
|
305
|
+
|
|
306
|
+
## 🧪 Quality, Validation & Performance
|
|
307
|
+
|
|
308
|
+
The project maintains a 12 × 12 source-to-target dialect regression matrix, semantic regression tests, post-processing safety regressions, security boundary checks, deterministic rule-engine tests, cache-versioning tests, async concurrency tests, and stable error-code tests.
|
|
309
|
+
|
|
310
|
+
Converted SQL is validated after post-processing. Target-dialect parsing is preferred; when a target parser limitation prevents validation but the generic parser accepts the SQL, the result is retained with a compatibility warning. Only when both validations fail is the conversion reported as unsuccessful.
|
|
311
|
+
|
|
312
|
+
The AST semantic diff utility canonicalizes source and target SQL through SQLGlot and reports structural changes such as different predicates or AST node shapes. It is a regression detector rather than a proof of runtime equivalence.
|
|
313
|
+
|
|
314
|
+
The semantic CI gate executes representative conversions against PostgreSQL and DuckDB and compares the source and converted result sets. This provides runtime evidence for supported SQL subsets without claiming universal cross-database semantic equivalence.
|
|
315
|
+
|
|
316
|
+
Security validation structurally detects stacked SQL statements using the parser when available, with configurable policy controlling whether dangerous input is blocked or only warned about.
|
|
317
|
+
|
|
318
|
+
The async batch API bounds concurrent work and preserves input order. A reproducible transpiler benchmark is available under `backend/benchmarks/` and is also executed in CI for performance observability. The benchmark intentionally reports measurements without failing the build on a fixed latency threshold because hosted CI timing is variable.
|
|
319
|
+
|
|
320
|
+
README source-of-truth checks run in CI and verify the release version, Python requirement, supported dialect list, and benchmark references against repository sources.
|
|
321
|
+
|
|
322
|
+
To run the benchmark locally:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
python backend/benchmarks/transpiler_benchmark.py --iterations 100 --repeats 3
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
To validate README consistency locally:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
python scripts/verify_readme_consistency.py
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## ⚠️ Limitations
|
|
335
|
+
|
|
336
|
+
SQL dialect conversion is not universally semantics-preserving. The engine validates generated SQL against the target parser, but parser acceptance does not prove equivalent runtime behavior. Database-specific differences in NULL handling, implicit casts, date/time semantics, collation, timezone behavior, JSON/array operations, and other vendor features may require manual review or execution against the target database.
|
|
337
|
+
|
|
338
|
+
NL2SQL is heuristic/template-driven rather than a calibrated probabilistic model. The returned confidence score should be treated as a generation-quality signal, not as a statistical probability that the SQL is correct.
|
|
339
|
+
|
|
340
|
+
## ⚙️ Configuration
|
|
341
|
+
|
|
342
|
+
The project uses `pydantic-settings` for robust configuration.
|
|
343
|
+
|
|
344
|
+
Copy `.env.example` to `.env` and customize:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
cp .env.example .env
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Key settings (prefixed with `SDM_`):
|
|
351
|
+
- `SDM_CACHE_ENABLED` - Enable/disable caching
|
|
352
|
+
|
|
353
|
+
### Rate limiting deployment
|
|
354
|
+
|
|
355
|
+
Rate limiting is on by default. The two backends are:
|
|
356
|
+
|
|
357
|
+
- `SDM_RATE_LIMIT_BACKEND=memory` (default) — per-process, thread-safe. Limits are **per instance**, not shared. Run this only when the API is served by a single process; in a multi-worker or multi-instance deployment each worker enforces its own limit, so the effective ceiling is `workers × SDM_RATE_LIMIT_REQUESTS`.
|
|
358
|
+
- `SDM_RATE_LIMIT_BACKEND=redis` — shared, atomic limits across all workers. Set `SDM_REDIS_URL` when using this backend. The store connects and pings Redis at startup and fails fast if it is unreachable; the `redis` package is required (install with `pip install redis`).
|
|
359
|
+
|
|
360
|
+
`SDM_RATE_LIMIT_ENABLED=false` disables enforcement entirely. Use the in-memory backend for local development and the Redis backend for any deployment with more than one worker or instance that must enforce a single global limit.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
backend/__init__.py,sha256=zVq9uJLNRIB3qXSZfnxi_dSb6ge6hNTEIlkcjyE9Stk,29
|
|
2
|
+
backend/api/__init__.py,sha256=qxJtk5A1QUgHXtk55_ZQEcZdpgX3fw5Cx4EjHGaQyvY,18
|
|
3
|
+
backend/api/main.py,sha256=YcN7daje0wOM4-MSJhbWonUv_RKNz1Txk37FcGZ9F3o,26599
|
|
4
|
+
backend/api/middleware.py,sha256=9F6FAhok89eoPbUrzTfSa_bQnZNktrzz50_gd8U-c1c,12406
|
|
5
|
+
backend/api/rate_limit_store.py,sha256=RV7E6hIalxSAOLYn-gJad_uO0_8qtSoGiuu-TdmfeF8,3902
|
|
6
|
+
backend/api/readiness.py,sha256=9DibD2ge3-kQIAA6cohI6bFCzvQOGyK7OiUApuCPbw8,7370
|
|
7
|
+
backend/core/__init__.py,sha256=qG4pdvI3hAoa6rAv2Q6v8oH4UHlwEs8-MBVSCSzOpS4,1384
|
|
8
|
+
backend/core/cache.py,sha256=KC61I8Vol3JYBLwEnCoECoFbUs9anEoEeYNXpi_G10w,9232
|
|
9
|
+
backend/core/column_hint_validation.py,sha256=uzowKpMqTrkB4ea0crlJGGgD8u0JRQrf32pvUHxSvG0,929
|
|
10
|
+
backend/core/config.py,sha256=7X-nmZbCzpgvtUaobDgMYImBoekPlLEC15fCF_Bwsno,19365
|
|
11
|
+
backend/core/constants.py,sha256=EZ8NUNM2IFj0JODqVRsZGcZ4MT31UxRgEMyLEbFCKrE,2854
|
|
12
|
+
backend/core/exceptions.py,sha256=xxtekNACUwcqIrsTamH-7f_V_lXjXXgQa7IOSyH9bPE,3849
|
|
13
|
+
backend/core/function_call_scanner.py,sha256=iBFF0RPonIpSfGpo-nkcwJm-0tPe2vv9fLsJw5IpWZs,1688
|
|
14
|
+
backend/core/function_semantics.py,sha256=Sb1MkJr-2mwtQRnjzckzFsGDM7XfwWKoF9VPK1fRpiY,6575
|
|
15
|
+
backend/core/functions_db.json,sha256=Ux-ku162DsHaNgfqXIyZKfoVFr0vZpISd-lFjbWyn1o,143386
|
|
16
|
+
backend/core/functions_lookup.py,sha256=I0pNZI-ztpgYZsh2BYfaiRQwqjdWFEMsdoGMoeThp7c,13441
|
|
17
|
+
backend/core/metadata.py,sha256=njwt9B-vS0atNtUoqp4thD_cf76yw_xZIyXXOhp2RF4,2471
|
|
18
|
+
backend/core/nl2sql.py,sha256=2UDUtIvjwOWRTebKUqgHRwutUYr4ENAXuYrh7EOKj5o,3203
|
|
19
|
+
backend/core/nl2sql_legacy.py,sha256=9BQdEApTdoJqBM6IP2Sykxm9yeZ52lTKXKw44D3tZl4,861
|
|
20
|
+
backend/core/p1_sql_scanner.py,sha256=MWrKM2nhuPMaosxBPNXejSuTSNKXwtaraXoH6wiL4Eo,5940
|
|
21
|
+
backend/core/p2_data_validation.py,sha256=cSRj6SMF2941NSNqEhA0KpqamVQc-mRR8m6GJFwIHlw,3532
|
|
22
|
+
backend/core/parser.py,sha256=x0AvxrbpMV36xztQaM57Y7kwCdNzusGSdup8OorLUnw,10309
|
|
23
|
+
backend/core/post_processor.py,sha256=na_rqdYMiWVj7zLhXMUHh27KOzGQMO-syOHccEb3jvU,5606
|
|
24
|
+
backend/core/rules.py,sha256=rkyJHphbwVoUwjPHTZAkXO6di_Bo932zgpSC6Wswnyg,29366
|
|
25
|
+
backend/core/semantic_diff.py,sha256=Mi4UsAmlbbSmGopuffIiGk4ZhnwQxgFHJktU3OjkEnw,16040
|
|
26
|
+
backend/core/transpiler.py,sha256=in1ccjCfD3fpf0MU8kCIw9pZOljqcHi3TJQiyHTzQf8,36328
|
|
27
|
+
backend/core/type_mapping.json,sha256=FuE4uWq2O5gJVE4x8_W7lvXN8wt1disDIEQl8t-Umy8,16786
|
|
28
|
+
backend/core/type_mapping.py,sha256=nxPKgWxko-LyKic1zW68Jy69I3prxiWzWMPnL-i8IOU,28789
|
|
29
|
+
backend/core/nl2sql_components/__init__.py,sha256=kAltTZGM-KKAD0bXTPdYNTnZjwxnr18IU9To2ZUOFNA,2026
|
|
30
|
+
backend/core/nl2sql_components/aggregations.py,sha256=K-rCgojfrlA_xch09FiAvRunxcUzvdCQzPfVN7Bguis,1474
|
|
31
|
+
backend/core/nl2sql_components/boolean_conditions.py,sha256=UVq0SpMMnJhA1Yf5ngG4Ipbj0Vl8GAd-HJ8FHe7tLzA,9931
|
|
32
|
+
backend/core/nl2sql_components/core_extract.py,sha256=76xGnqR2ZdoMRuK7aVqUPQsjvYNuERx2hNi4LJBW7eQ,3707
|
|
33
|
+
backend/core/nl2sql_components/evidence.py,sha256=6dn0mDpKfXnI6cBUlgHBjsI8hBjrPoWgifyHtI0FPhM,3853
|
|
34
|
+
backend/core/nl2sql_components/mappings.py,sha256=GGIXw0u8vlfMxoaPVAaMqw2uBbeCIBShVBr56uCklvA,9541
|
|
35
|
+
backend/core/nl2sql_components/relations.py,sha256=1iohSMyhTvMdgFSxPx-XRG6lhrfazBAFidhw4IKN9mM,7127
|
|
36
|
+
backend/core/nl2sql_components/templates.py,sha256=KvOSy_xRIddzqTqWIaVD4Claf0QFKF-cfDlUBLzfXw4,5470
|
|
37
|
+
backend/core/nl2sql_components/tokenizer.py,sha256=3MxqXuPkCRG0_UXnClWCGgpryQRzLcp-EqQFaot8GjY,7197
|
|
38
|
+
backend/core/nl2sql_pipeline/__init__.py,sha256=BcKKTeK36WO1uFaY4q5JetvQd5ix9g1O8Dgh3YriPyo,582
|
|
39
|
+
backend/core/nl2sql_pipeline/aggregations.py,sha256=nYPN2QoU_qHELG5BfPuurOfV6WbOFioglX0W8qY6RPA,965
|
|
40
|
+
backend/core/nl2sql_pipeline/clause_extract.py,sha256=bQgoSa4raLZ6ErAbxEDczSUpkp7r_Kq-fUbbvtUkevY,3786
|
|
41
|
+
backend/core/nl2sql_pipeline/dialect.py,sha256=oZlk8HOXIft2YZ-CZWq5OCOXMMFu27Ox1MIFxovQiCw,5011
|
|
42
|
+
backend/core/nl2sql_pipeline/intent.py,sha256=awwrWX_tydqUOZqLY9AxuqQsavbGwun8h0vod9pJUF4,2884
|
|
43
|
+
backend/core/nl2sql_pipeline/ir.py,sha256=DocA9ixBLeu273dAw9Ytj-Ts5xgjyQBI4zEYrHaA9bA,2029
|
|
44
|
+
backend/core/nl2sql_pipeline/models.py,sha256=a3flaEh4Oveyfi802GrAHfdquTGUG9LMDOxd1N44COg,1017
|
|
45
|
+
backend/core/nl2sql_pipeline/orchestrator.py,sha256=0X1Sbj2bBb4O-KAuYFLitX6BYKfYxQlU9zyggLXEdW4,22682
|
|
46
|
+
backend/core/nl2sql_pipeline/predicates.py,sha256=aet6RJyAa0AUhFiJhzoezhRU3-AYNbKEsTDqMIh5kJg,8142
|
|
47
|
+
backend/core/nl2sql_pipeline/renderer.py,sha256=1uXSUoLoM0Yk5mGygE7kxghgJCLARXdFR_3JFDOSXzc,10966
|
|
48
|
+
backend/core/nl2sql_pipeline/resolution.py,sha256=lyO0L7jaW-MdROatH6UBz5W4lz9WQCgecu2itGtos7U,2976
|
|
49
|
+
backend/core/nl2sql_pipeline/suggestions.py,sha256=PuREuQZ9M367mjRyCDGqnHiZ2w_z4tT4RbIoP_tO0TE,1585
|
|
50
|
+
backend/core/nl2sql_pipeline/templates.py,sha256=ThlaLo3ZdO4XFvfdeiGODATMgR7yjqMlb5kUB-DH2Bo,16306
|
|
51
|
+
backend/core/nl2sql_pipeline/validation.py,sha256=UgqIPSxuXBfWkuDAlFP0jcyVY0C0zb7_DrQdoUjMILg,939
|
|
52
|
+
backend/utils/__init__.py,sha256=dJumBhEtq3iLtCvvgL0zhscQyC4n6LBkExxnpHi9qzQ,69
|
|
53
|
+
backend/utils/validators.py,sha256=3f2XVa4sRsHjgH-lEqMU7jgY_gxFsYdkFeu2OY0B718,12291
|
|
54
|
+
frontend/__init__.py,sha256=CCg24gL5IYqpwYkOCvBMxm9e3Kt6SErQuo8dqp53grg,326
|
|
55
|
+
frontend/app_context_v2.py,sha256=QY0U3AYDsKwNO_r9jJZ4S1xTcdgEUM6m-BZSHD7EuC0,6213
|
|
56
|
+
frontend/templates_v2.py,sha256=nXcc0kZIjKMV8mwwIsarljNNY1P4AWDsB9ydQB8QEl4,3703
|
|
57
|
+
frontend/core/__init__.py,sha256=6bV3Zz18h1sM6en0xv_ZOnWXSg2h69MajtO60P0dJZg,605
|
|
58
|
+
frontend/core/design_tokens.py,sha256=Vgm7V04DrG5eRjCTRryv17a30whFI0gN1NslbNDel90,3058
|
|
59
|
+
frontend/core/escaping.py,sha256=Wo8GRHdqGpKm3nBAE60bXHl1acAlrHUagUisjOcR-C0,404
|
|
60
|
+
frontend/core/navigation.py,sha256=kimt_H8wq31Q5S2NDnioaOdYneBuQ44pgGLGvFJMC0o,4081
|
|
61
|
+
frontend/core/state.py,sha256=tETRZaXfVBBf5-Fl9ZcW3-Qq1JKlg1ptUxlJDc_HuXA,22827
|
|
62
|
+
frontend/core/styles.py,sha256=rwa1wb1dM_IQZUdvO7cW_YrBg3sDX6iCnDgnDPwqCX8,13829
|
|
63
|
+
frontend/core/themes.py,sha256=RImKMngxMsqsq1qp7sBodB85673cvPoCn6DAMxJeQ7k,1834
|
|
64
|
+
frontend/core/viewmodels.py,sha256=UQVBKZETwujucE0akMwrw0mGjIqM08GExlIHWcRvfxY,16541
|
|
65
|
+
frontend/pages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
|
+
frontend/pages/convert.py,sha256=XSNmoK_Xwe9__f5v6619pDx_PJ2Nl5td-QRy_6ucT_Q,11206
|
|
67
|
+
frontend/pages/diff.py,sha256=Jcmhj7Ln3AzkmGJ6xedUpv7E2Jox_AKbudfeSo7lGi0,5514
|
|
68
|
+
frontend/pages/functions.py,sha256=pW_NVdCyXL-EBFH2sM5KwAE06GoSThUaVP3h56M6T1M,3381
|
|
69
|
+
frontend/pages/history.py,sha256=Xnxo7WjapXhYJ3ISektgQVueFh_7zFew-m3c0HYblZY,5036
|
|
70
|
+
frontend/pages/lineage.py,sha256=gj04M2ouvil2P64e3NZrwMatlrFL4E2E9xfmI7Lz9tw,5518
|
|
71
|
+
frontend/pages/nl2sql.py,sha256=6U1yBrkDNcJtZt_Iodj8gcN4AsNKQprw2HV02gI5m74,10138
|
|
72
|
+
frontend/pages/query_analysis.py,sha256=3Q_slQMIbcP0d_ejvLLrlsH8mbjapTeWUOM798uJ9C4,4279
|
|
73
|
+
frontend/pages/runtime.py,sha256=8iWV_IuWpAPXmys61iv8qnolf3kdh9eVe-k07vs1coU,2479
|
|
74
|
+
frontend/pages/settings.py,sha256=HPboLiu4kveBF9BC1otd_KBT-wqV7N6aZduG6Kt33RM,1894
|
|
75
|
+
frontend/pages/templates.py,sha256=swkkfJj7GsXQrSf92NrsvlRz_AB93ldorUl3EvO0xx4,2315
|
|
76
|
+
frontend/pages/types.py,sha256=tD6YLPxKxMbRI-RdHmm3cNJouiyWcg2glhQ0QXn6sWA,4212
|
|
77
|
+
frontend/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
|
+
frontend/ui/command_palette.py,sha256=01JyPIazmw7clvImC3vJjZS9cZD_m7wdmlP7Wn1FxtA,5247
|
|
79
|
+
frontend/ui/diff.py,sha256=wH-Q26gPgXbytNz3hlSYBfUowewhZ4dZdyaNKUSk6Vk,10676
|
|
80
|
+
frontend/ui/editor.py,sha256=uM2OwOF67LtiMQAGM6UPxUd8eoyf-XnPpYzxHNLq7dk,3597
|
|
81
|
+
frontend/ui/status.py,sha256=ApngcPMw59FN-wDg-adZbW2GGYrMSo9OLMARVmFSQrg,9196
|
|
82
|
+
sql_dialect_master-1.1.1.dist-info/licenses/LICENSE,sha256=dUhuoK-TCRQMpuLEAdfme-qPSJI0TlcH9jlNxeg9_EQ,1056
|
|
83
|
+
sql_dialect_master-1.1.1.dist-info/METADATA,sha256=WNgeKizIyZM5sJBguHs-5vy1ru-P3YlXevNp_B87t3M,16556
|
|
84
|
+
sql_dialect_master-1.1.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
85
|
+
sql_dialect_master-1.1.1.dist-info/top_level.txt,sha256=7xo0crJn5dRzmIuCbDBgy7tJWauQa6M7uXafP2-BI0Q,17
|
|
86
|
+
sql_dialect_master-1.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|