sql-dialect-master 1.1.1__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 (91) hide show
  1. sql_dialect_master-1.1.1/LICENSE +21 -0
  2. sql_dialect_master-1.1.1/PKG-INFO +360 -0
  3. sql_dialect_master-1.1.1/README.md +331 -0
  4. sql_dialect_master-1.1.1/backend/__init__.py +1 -0
  5. sql_dialect_master-1.1.1/backend/api/__init__.py +1 -0
  6. sql_dialect_master-1.1.1/backend/api/main.py +732 -0
  7. sql_dialect_master-1.1.1/backend/api/middleware.py +274 -0
  8. sql_dialect_master-1.1.1/backend/api/rate_limit_store.py +105 -0
  9. sql_dialect_master-1.1.1/backend/api/readiness.py +178 -0
  10. sql_dialect_master-1.1.1/backend/core/__init__.py +57 -0
  11. sql_dialect_master-1.1.1/backend/core/cache.py +261 -0
  12. sql_dialect_master-1.1.1/backend/core/column_hint_validation.py +22 -0
  13. sql_dialect_master-1.1.1/backend/core/config.py +546 -0
  14. sql_dialect_master-1.1.1/backend/core/constants.py +84 -0
  15. sql_dialect_master-1.1.1/backend/core/exceptions.py +124 -0
  16. sql_dialect_master-1.1.1/backend/core/function_call_scanner.py +64 -0
  17. sql_dialect_master-1.1.1/backend/core/function_semantics.py +148 -0
  18. sql_dialect_master-1.1.1/backend/core/functions_db.json +601 -0
  19. sql_dialect_master-1.1.1/backend/core/functions_lookup.py +332 -0
  20. sql_dialect_master-1.1.1/backend/core/metadata.py +71 -0
  21. sql_dialect_master-1.1.1/backend/core/nl2sql.py +85 -0
  22. sql_dialect_master-1.1.1/backend/core/nl2sql_components/__init__.py +72 -0
  23. sql_dialect_master-1.1.1/backend/core/nl2sql_components/aggregations.py +35 -0
  24. sql_dialect_master-1.1.1/backend/core/nl2sql_components/boolean_conditions.py +279 -0
  25. sql_dialect_master-1.1.1/backend/core/nl2sql_components/core_extract.py +106 -0
  26. sql_dialect_master-1.1.1/backend/core/nl2sql_components/evidence.py +122 -0
  27. sql_dialect_master-1.1.1/backend/core/nl2sql_components/mappings.py +185 -0
  28. sql_dialect_master-1.1.1/backend/core/nl2sql_components/relations.py +180 -0
  29. sql_dialect_master-1.1.1/backend/core/nl2sql_components/templates.py +130 -0
  30. sql_dialect_master-1.1.1/backend/core/nl2sql_components/tokenizer.py +187 -0
  31. sql_dialect_master-1.1.1/backend/core/nl2sql_legacy.py +22 -0
  32. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/__init__.py +13 -0
  33. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/aggregations.py +26 -0
  34. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/clause_extract.py +97 -0
  35. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/dialect.py +139 -0
  36. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/intent.py +85 -0
  37. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/ir.py +70 -0
  38. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/models.py +30 -0
  39. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/orchestrator.py +576 -0
  40. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/predicates.py +182 -0
  41. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/renderer.py +248 -0
  42. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/resolution.py +69 -0
  43. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/suggestions.py +30 -0
  44. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/templates.py +371 -0
  45. sql_dialect_master-1.1.1/backend/core/nl2sql_pipeline/validation.py +28 -0
  46. sql_dialect_master-1.1.1/backend/core/p1_sql_scanner.py +196 -0
  47. sql_dialect_master-1.1.1/backend/core/p2_data_validation.py +72 -0
  48. sql_dialect_master-1.1.1/backend/core/parser.py +280 -0
  49. sql_dialect_master-1.1.1/backend/core/post_processor.py +129 -0
  50. sql_dialect_master-1.1.1/backend/core/rules.py +808 -0
  51. sql_dialect_master-1.1.1/backend/core/semantic_diff.py +385 -0
  52. sql_dialect_master-1.1.1/backend/core/transpiler.py +791 -0
  53. sql_dialect_master-1.1.1/backend/core/type_mapping.json +593 -0
  54. sql_dialect_master-1.1.1/backend/core/type_mapping.py +765 -0
  55. sql_dialect_master-1.1.1/backend/utils/__init__.py +2 -0
  56. sql_dialect_master-1.1.1/backend/utils/validators.py +407 -0
  57. sql_dialect_master-1.1.1/frontend/__init__.py +10 -0
  58. sql_dialect_master-1.1.1/frontend/app_context_v2.py +201 -0
  59. sql_dialect_master-1.1.1/frontend/core/__init__.py +33 -0
  60. sql_dialect_master-1.1.1/frontend/core/design_tokens.py +127 -0
  61. sql_dialect_master-1.1.1/frontend/core/escaping.py +13 -0
  62. sql_dialect_master-1.1.1/frontend/core/navigation.py +135 -0
  63. sql_dialect_master-1.1.1/frontend/core/state.py +612 -0
  64. sql_dialect_master-1.1.1/frontend/core/styles.py +523 -0
  65. sql_dialect_master-1.1.1/frontend/core/themes.py +69 -0
  66. sql_dialect_master-1.1.1/frontend/core/viewmodels.py +499 -0
  67. sql_dialect_master-1.1.1/frontend/pages/__init__.py +0 -0
  68. sql_dialect_master-1.1.1/frontend/pages/convert.py +283 -0
  69. sql_dialect_master-1.1.1/frontend/pages/diff.py +157 -0
  70. sql_dialect_master-1.1.1/frontend/pages/functions.py +100 -0
  71. sql_dialect_master-1.1.1/frontend/pages/history.py +144 -0
  72. sql_dialect_master-1.1.1/frontend/pages/lineage.py +168 -0
  73. sql_dialect_master-1.1.1/frontend/pages/nl2sql.py +305 -0
  74. sql_dialect_master-1.1.1/frontend/pages/query_analysis.py +120 -0
  75. sql_dialect_master-1.1.1/frontend/pages/runtime.py +66 -0
  76. sql_dialect_master-1.1.1/frontend/pages/settings.py +60 -0
  77. sql_dialect_master-1.1.1/frontend/pages/templates.py +67 -0
  78. sql_dialect_master-1.1.1/frontend/pages/types.py +110 -0
  79. sql_dialect_master-1.1.1/frontend/templates_v2.py +53 -0
  80. sql_dialect_master-1.1.1/frontend/ui/__init__.py +0 -0
  81. sql_dialect_master-1.1.1/frontend/ui/command_palette.py +153 -0
  82. sql_dialect_master-1.1.1/frontend/ui/diff.py +275 -0
  83. sql_dialect_master-1.1.1/frontend/ui/editor.py +102 -0
  84. sql_dialect_master-1.1.1/frontend/ui/status.py +255 -0
  85. sql_dialect_master-1.1.1/pyproject.toml +50 -0
  86. sql_dialect_master-1.1.1/setup.cfg +4 -0
  87. sql_dialect_master-1.1.1/sql_dialect_master.egg-info/PKG-INFO +360 -0
  88. sql_dialect_master-1.1.1/sql_dialect_master.egg-info/SOURCES.txt +89 -0
  89. sql_dialect_master-1.1.1/sql_dialect_master.egg-info/dependency_links.txt +1 -0
  90. sql_dialect_master-1.1.1/sql_dialect_master.egg-info/requires.txt +24 -0
  91. sql_dialect_master-1.1.1/sql_dialect_master.egg-info/top_level.txt +2 -0
@@ -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.
@@ -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
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+ [![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-green.svg)](https://fastapi.tiangolo.com/)
39
+ [![Streamlit](https://img.shields.io/badge/Streamlit-1.38+-red.svg)](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.