sql-dialect-master 1.6.0__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/PKG-INFO +2 -2
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/README.md +1 -1
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/metadata.py +2 -2
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/ir.py +3 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/orchestrator.py +231 -33
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/renderer.py +7 -3
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/pyproject.toml +1 -1
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/PKG-INFO +2 -2
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/LICENSE +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/auth.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/client_identity.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/main.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/metrics.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/middleware.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/rate_limit_store.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/readiness.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/workers.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/cache.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/column_hint_validation.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/config.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/constants.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/exceptions.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/function_call_scanner.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/function_semantics.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/functions_db.json +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/functions_lookup.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/aggregations.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/boolean_conditions.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/core_extract.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/evidence.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/mappings.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/relations.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/templates.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/tokenizer.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_legacy.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_llm.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/aggregations.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/clause_extract.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/dialect.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/intent.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/models.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/predicates.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/resolution.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/suggestions.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/templates.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/validation.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_schema.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/p1_sql_scanner.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/p2_data_validation.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/parser.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/post_processor.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/rules.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/semantic_diff.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/sql_statements.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/transpiler.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.json +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/utils/__init__.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/utils/validators.py +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/setup.cfg +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/SOURCES.txt +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/dependency_links.txt +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/requires.txt +0 -0
- {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-dialect-master
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: SQL Dialect Master - Multi-database SQL conversion engine
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -38,7 +38,7 @@ Dynamic: license-file
|
|
|
38
38
|
|
|
39
39
|
Enterprise-grade multi-database SQL conversion engine supporting 12 database dialects.
|
|
40
40
|
|
|
41
|
-
Current release: 1.
|
|
41
|
+
Current release: 1.8.0
|
|
42
42
|
|
|
43
43
|
[](https://www.python.org/downloads/)
|
|
44
44
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Enterprise-grade multi-database SQL conversion engine supporting 12 database dialects.
|
|
4
4
|
|
|
5
|
-
Current release: 1.
|
|
5
|
+
Current release: 1.8.0
|
|
6
6
|
|
|
7
7
|
[](https://www.python.org/downloads/)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -17,8 +17,8 @@ Design rules:
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
# ── Release version facts (sole source of truth) ────────────────────────
|
|
20
|
-
PROJECT_VERSION = "1.
|
|
21
|
-
API_VERSION = "1.
|
|
20
|
+
PROJECT_VERSION = "1.8.0"
|
|
21
|
+
API_VERSION = "1.8.0"
|
|
22
22
|
# Frontend v2 architecture — independent of the product release version.
|
|
23
23
|
FRONTEND_ARCHITECTURE_VERSION = 2
|
|
24
24
|
|
|
@@ -35,6 +35,7 @@ class QueryIR:
|
|
|
35
35
|
distinct: bool
|
|
36
36
|
dialect: str
|
|
37
37
|
evidence: GenerationEvidence = field(default_factory=GenerationEvidence)
|
|
38
|
+
orderings: Optional[List[Tuple[str, str]]] = None
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
def build_ir(
|
|
@@ -49,6 +50,7 @@ def build_ir(
|
|
|
49
50
|
joins: List[Dict],
|
|
50
51
|
distinct: bool,
|
|
51
52
|
dialect: str,
|
|
53
|
+
orderings: Optional[List[Tuple[str, str]]] = None,
|
|
52
54
|
) -> QueryIR:
|
|
53
55
|
"""Thin positional-arg adapter mirroring the legacy call site.
|
|
54
56
|
|
|
@@ -67,4 +69,5 @@ def build_ir(
|
|
|
67
69
|
joins=joins,
|
|
68
70
|
distinct=distinct,
|
|
69
71
|
dialect=dialect,
|
|
72
|
+
orderings=orderings,
|
|
70
73
|
)
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/orchestrator.py
RENAMED
|
@@ -125,6 +125,18 @@ _SCHEMA_JOINED_WITH_PREFIX = re.compile(
|
|
|
125
125
|
r"([A-Za-z_][A-Za-z0-9_$]*(?:\.[A-Za-z_][A-Za-z0-9_$]*)?)\b",
|
|
126
126
|
re.IGNORECASE,
|
|
127
127
|
)
|
|
128
|
+
_SCHEMA_DIAGNOSTIC_VALUES = {
|
|
129
|
+
"active", "inactive", "enabled", "disabled", "valid", "invalid",
|
|
130
|
+
"completed", "pending", "paid", "unpaid", "done", "true", "false",
|
|
131
|
+
}
|
|
132
|
+
_SCHEMA_DIAGNOSTIC_KEYWORDS = {
|
|
133
|
+
"and", "or", "not", "is", "where", "with", "by", "group", "grouped",
|
|
134
|
+
"order", "ordered", "sort", "sorted", "asc", "desc", "ascending",
|
|
135
|
+
"descending", "users", "user", "show", "list", "find", "display",
|
|
136
|
+
}
|
|
137
|
+
_SCHEMA_DIAGNOSTIC_COLUMN_ALLOWLIST = {
|
|
138
|
+
"password", "nickname", "token", "hash", "bio", "avatar",
|
|
139
|
+
}
|
|
128
140
|
_SCHEMA_GROUP_LABEL_COLUMNS = {
|
|
129
141
|
"部门": ("department", "dept"),
|
|
130
142
|
"状态": ("status",),
|
|
@@ -971,39 +983,52 @@ class PipelineNL2SQLGenerator:
|
|
|
971
983
|
text: str,
|
|
972
984
|
table: SchemaTableContext,
|
|
973
985
|
schema: SchemaContext,
|
|
974
|
-
) ->
|
|
975
|
-
"""Resolve
|
|
986
|
+
) -> list[tuple[str, str]]:
|
|
987
|
+
"""Resolve schema-aware ORDER BY targets without changing no-schema extraction."""
|
|
976
988
|
match = re.search(
|
|
977
|
-
r"\b(?:order(?:ed)?|sort(?:ed)?)\s+by\s+"
|
|
978
|
-
r"([A-Za-z_][A-Za-z0-9_$]*(?:\.[A-Za-z_][A-Za-z0-9_$]*)?)"
|
|
979
|
-
r"(.*)$",
|
|
989
|
+
r"\b(?:order(?:ed)?|sort(?:ed)?)\s+by\s+",
|
|
980
990
|
text,
|
|
981
991
|
re.IGNORECASE,
|
|
982
992
|
)
|
|
983
993
|
if match is None:
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
994
|
+
legacy = self._extract_ordering(text)
|
|
995
|
+
return [legacy] if legacy else []
|
|
996
|
+
tail = text[match.end():]
|
|
997
|
+
boundary = re.search(r"\b(?:where|whose|limit)\b", tail, re.IGNORECASE)
|
|
998
|
+
clause = tail[:boundary.start()] if boundary else tail
|
|
999
|
+
if re.search(r"\bor\b|[()\u4e00-\u9fff]", clause, re.IGNORECASE):
|
|
1000
|
+
raise SchemaValidationError("unsupported multi-column ordering syntax")
|
|
1001
|
+
items = re.split(r"\s*,\s*|\s+and\s+", clause, flags=re.IGNORECASE)
|
|
1002
|
+
if not items or any(not item.strip() for item in items) or len(items) > 5:
|
|
1003
|
+
raise SchemaValidationError("invalid or excessive ORDER BY columns")
|
|
1004
|
+
resolved: list[tuple[str, str]] = []
|
|
1005
|
+
seen: set[str] = set()
|
|
1006
|
+
identifier = r"[A-Za-z_][A-Za-z0-9_$]*(?:\.[A-Za-z_][A-Za-z0-9_$]*){0,2}"
|
|
1007
|
+
item_pattern = re.compile(
|
|
1008
|
+
rf"^\s*({identifier})\s*(?:(ascending|descending|asc|desc)\s*)?$",
|
|
990
1009
|
re.IGNORECASE,
|
|
991
1010
|
)
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1011
|
+
for item in items:
|
|
1012
|
+
item_match = item_pattern.fullmatch(item)
|
|
1013
|
+
if item_match is None:
|
|
1014
|
+
raise SchemaValidationError("invalid ORDER BY column")
|
|
1015
|
+
raw_column, raw_direction = item_match.groups()
|
|
1016
|
+
parts = raw_column.split(".")
|
|
1017
|
+
column_name = parts[-1]
|
|
1018
|
+
if len(parts) > 1:
|
|
1019
|
+
candidates = schema.table_candidates(".".join(parts[:-1]))
|
|
1020
|
+
if len(candidates) != 1 or candidates[0].key != table.key:
|
|
1021
|
+
raise SchemaValidationError("ordering column table is not the selected schema table")
|
|
1022
|
+
canonical = schema.canonical_column(table, column_name)
|
|
1023
|
+
if canonical is None:
|
|
1024
|
+
raise SchemaValidationError("ordering column is outside the schema")
|
|
1025
|
+
key = canonical.casefold()
|
|
1026
|
+
if key in seen:
|
|
1027
|
+
raise SchemaValidationError("duplicate ORDER BY column")
|
|
1028
|
+
seen.add(key)
|
|
1029
|
+
direction = "DESC" if raw_direction and raw_direction.casefold() in {"descending", "desc"} else "ASC"
|
|
1030
|
+
resolved.append((canonical, direction))
|
|
1031
|
+
return resolved
|
|
1007
1032
|
|
|
1008
1033
|
def _schema_resolve_count_metric(
|
|
1009
1034
|
self,
|
|
@@ -1282,7 +1307,11 @@ class PipelineNL2SQLGenerator:
|
|
|
1282
1307
|
if re.search(r"\bor\b|\bwhose\b|[()]", tail, re.IGNORECASE):
|
|
1283
1308
|
raise SchemaValidationError("complex whose predicates are unsupported")
|
|
1284
1309
|
stripped_tail = tail.strip()
|
|
1285
|
-
if stripped_tail and not re.match(
|
|
1310
|
+
if stripped_tail and not re.match(
|
|
1311
|
+
r"^(?:and|order(?:ed)?\s+by|sort(?:ed)?\s+by)\b",
|
|
1312
|
+
stripped_tail,
|
|
1313
|
+
re.IGNORECASE,
|
|
1314
|
+
):
|
|
1286
1315
|
raise SchemaValidationError("unexpected text after whose predicate")
|
|
1287
1316
|
span = (match.start(), value_end)
|
|
1288
1317
|
return predicate, span
|
|
@@ -1340,7 +1369,11 @@ class PipelineNL2SQLGenerator:
|
|
|
1340
1369
|
|
|
1341
1370
|
tail = executable[value_end:]
|
|
1342
1371
|
stripped_tail = tail.strip()
|
|
1343
|
-
if stripped_tail and not re.match(
|
|
1372
|
+
if stripped_tail and not re.match(
|
|
1373
|
+
r"^(?:where|whose|order(?:ed)?\s+by|sort(?:ed)?\s+by)\b",
|
|
1374
|
+
stripped_tail,
|
|
1375
|
+
re.IGNORECASE,
|
|
1376
|
+
):
|
|
1344
1377
|
raise SchemaValidationError("unexpected text after joined-on equality")
|
|
1345
1378
|
|
|
1346
1379
|
def resolve_endpoint(raw: str) -> tuple[SchemaTableContext, str]:
|
|
@@ -1456,7 +1489,11 @@ class PipelineNL2SQLGenerator:
|
|
|
1456
1489
|
|
|
1457
1490
|
tail = executable[match.end():]
|
|
1458
1491
|
stripped_tail = tail.strip()
|
|
1459
|
-
if stripped_tail and not re.match(
|
|
1492
|
+
if stripped_tail and not re.match(
|
|
1493
|
+
r"^(?:where|whose|order(?:ed)?\s+by|sort(?:ed)?\s+by)\b",
|
|
1494
|
+
stripped_tail,
|
|
1495
|
+
re.IGNORECASE,
|
|
1496
|
+
):
|
|
1460
1497
|
raise SchemaValidationError("unexpected text after joined-with target")
|
|
1461
1498
|
relationships = [
|
|
1462
1499
|
relationship for relationship in schema.relationships
|
|
@@ -1481,6 +1518,134 @@ class PipelineNL2SQLGenerator:
|
|
|
1481
1518
|
"join_spec": JoinSpec(kind=kind, matched_text="joined with"),
|
|
1482
1519
|
}], span
|
|
1483
1520
|
|
|
1521
|
+
def _schema_diagnostic_suggestions(
|
|
1522
|
+
self,
|
|
1523
|
+
text: str,
|
|
1524
|
+
table: SchemaTableContext,
|
|
1525
|
+
schema: SchemaContext,
|
|
1526
|
+
columns: list[str],
|
|
1527
|
+
existing: list,
|
|
1528
|
+
) -> list:
|
|
1529
|
+
"""Return high-confidence unmapped-column suggestions for schema success."""
|
|
1530
|
+
if not table.has_column_metadata:
|
|
1531
|
+
return list(existing)
|
|
1532
|
+
masked = mask_non_executable(text)
|
|
1533
|
+
schema_tables = {candidate.key for candidate in schema.tables}
|
|
1534
|
+
table_aliases = {
|
|
1535
|
+
pattern.casefold() for pattern in self.TABLE_PATTERNS
|
|
1536
|
+
} | {
|
|
1537
|
+
mapped.casefold() for mapped in self.TABLE_PATTERNS.values()
|
|
1538
|
+
}
|
|
1539
|
+
schema_columns = {column.casefold() for column in table.columns}
|
|
1540
|
+
mapped_aliases = {
|
|
1541
|
+
alias.casefold(): canonical
|
|
1542
|
+
for alias, canonical in self.COLUMN_PATTERNS.items()
|
|
1543
|
+
}
|
|
1544
|
+
warnings: list[tuple[int, str]] = []
|
|
1545
|
+
seen: set[str] = set()
|
|
1546
|
+
|
|
1547
|
+
def add_warning(position: int, token: str, *, projection: bool = False) -> None:
|
|
1548
|
+
key = token.casefold()
|
|
1549
|
+
if key in seen or key in schema_columns:
|
|
1550
|
+
return
|
|
1551
|
+
canonical = mapped_aliases.get(key)
|
|
1552
|
+
if canonical is not None and canonical.casefold() in schema_columns:
|
|
1553
|
+
return
|
|
1554
|
+
message = (
|
|
1555
|
+
f'Possible projection term "{token}" was not resolved against the selected schema table.'
|
|
1556
|
+
if projection else
|
|
1557
|
+
f'Possible unmapped column reference: "{token}". '
|
|
1558
|
+
"Provide it in column_hints if it is a schema column."
|
|
1559
|
+
)
|
|
1560
|
+
seen.add(key)
|
|
1561
|
+
warnings.append((position, message))
|
|
1562
|
+
|
|
1563
|
+
# Strong identifier contexts: `with token` and `by snake_case`.
|
|
1564
|
+
for match in re.finditer(
|
|
1565
|
+
r"\b(?:with|by)\s+([A-Za-z_][A-Za-z0-9_$]*)",
|
|
1566
|
+
masked,
|
|
1567
|
+
re.IGNORECASE,
|
|
1568
|
+
):
|
|
1569
|
+
token = match.group(1)
|
|
1570
|
+
lowered = token.casefold()
|
|
1571
|
+
if lowered in _SCHEMA_DIAGNOSTIC_KEYWORDS | _SCHEMA_DIAGNOSTIC_VALUES:
|
|
1572
|
+
continue
|
|
1573
|
+
if schema.table_candidates(token) or lowered in schema_tables:
|
|
1574
|
+
continue
|
|
1575
|
+
if lowered in table_aliases:
|
|
1576
|
+
continue
|
|
1577
|
+
if schema.canonical_column(table, token) is not None:
|
|
1578
|
+
continue
|
|
1579
|
+
if lowered in mapped_aliases and mapped_aliases[lowered].casefold() in schema_columns:
|
|
1580
|
+
continue
|
|
1581
|
+
if match.group(0).casefold().startswith("by ") and "_" not in token:
|
|
1582
|
+
continue
|
|
1583
|
+
add_warning(match.start(1), token)
|
|
1584
|
+
|
|
1585
|
+
# Explicit projection conjunctions: only mapped aliases after a
|
|
1586
|
+
# show/list/display marker, before any predicate/clause boundary.
|
|
1587
|
+
projection_marker = re.search(r"\b(?:show|list|display|select)\b", masked, re.IGNORECASE)
|
|
1588
|
+
if projection_marker:
|
|
1589
|
+
boundary = re.search(
|
|
1590
|
+
r"\b(?:where|whose|order(?:ed)?\s+by|sort(?:ed)?\s+by|group(?:ed)?\s+by)\b",
|
|
1591
|
+
masked[projection_marker.end():],
|
|
1592
|
+
re.IGNORECASE,
|
|
1593
|
+
)
|
|
1594
|
+
projection_end = (
|
|
1595
|
+
projection_marker.end() + boundary.start()
|
|
1596
|
+
if boundary is not None else len(masked)
|
|
1597
|
+
)
|
|
1598
|
+
for alias, canonical in sorted(self.COLUMN_PATTERNS.items(), key=lambda item: -len(item[0])):
|
|
1599
|
+
if canonical.casefold() in schema_columns:
|
|
1600
|
+
continue
|
|
1601
|
+
aliases = [alias]
|
|
1602
|
+
if alias.isascii() and not alias.casefold().endswith("s"):
|
|
1603
|
+
aliases.append(alias + "s")
|
|
1604
|
+
for candidate_alias in aliases:
|
|
1605
|
+
expression = re.escape(candidate_alias)
|
|
1606
|
+
if not re.search(r"[\u4e00-\u9fff]", candidate_alias):
|
|
1607
|
+
expression = rf"(?<![\w$]){expression}(?![\w$])"
|
|
1608
|
+
for match in re.finditer(expression, masked[projection_marker.end():projection_end], re.IGNORECASE):
|
|
1609
|
+
add_warning(
|
|
1610
|
+
projection_marker.end() + match.start(),
|
|
1611
|
+
alias,
|
|
1612
|
+
projection=True,
|
|
1613
|
+
)
|
|
1614
|
+
projection_slice = masked[projection_marker.end():projection_end]
|
|
1615
|
+
for token_match in re.finditer(
|
|
1616
|
+
r"[A-Za-z_][A-Za-z0-9_$]*", projection_slice
|
|
1617
|
+
):
|
|
1618
|
+
token = token_match.group(0)
|
|
1619
|
+
lowered = token.casefold()
|
|
1620
|
+
if (
|
|
1621
|
+
lowered in _SCHEMA_DIAGNOSTIC_KEYWORDS
|
|
1622
|
+
or lowered in _SCHEMA_DIAGNOSTIC_VALUES
|
|
1623
|
+
or lowered in table_aliases
|
|
1624
|
+
or lowered in schema_tables
|
|
1625
|
+
or lowered in schema_columns
|
|
1626
|
+
):
|
|
1627
|
+
continue
|
|
1628
|
+
canonical = mapped_aliases.get(lowered)
|
|
1629
|
+
if canonical is not None and canonical.casefold() in schema_columns:
|
|
1630
|
+
continue
|
|
1631
|
+
if canonical is None and (
|
|
1632
|
+
"_" not in token and lowered not in _SCHEMA_DIAGNOSTIC_COLUMN_ALLOWLIST
|
|
1633
|
+
):
|
|
1634
|
+
continue
|
|
1635
|
+
add_warning(
|
|
1636
|
+
projection_marker.end() + token_match.start(),
|
|
1637
|
+
canonical or token,
|
|
1638
|
+
projection=True,
|
|
1639
|
+
)
|
|
1640
|
+
|
|
1641
|
+
warnings.sort(key=lambda item: item[0])
|
|
1642
|
+
diagnostic_messages = [message for _, message in warnings[:3]]
|
|
1643
|
+
combined: list = []
|
|
1644
|
+
for suggestion in [*existing, *diagnostic_messages]:
|
|
1645
|
+
if suggestion not in combined:
|
|
1646
|
+
combined.append(suggestion)
|
|
1647
|
+
return combined[:3]
|
|
1648
|
+
|
|
1484
1649
|
def _schema_resolve_joins(
|
|
1485
1650
|
self,
|
|
1486
1651
|
text: str,
|
|
@@ -1699,13 +1864,34 @@ class PipelineNL2SQLGenerator:
|
|
|
1699
1864
|
text_lower, table_context, schema, aggregations
|
|
1700
1865
|
)
|
|
1701
1866
|
)
|
|
1702
|
-
|
|
1867
|
+
distinct = self._check_distinct(text_lower)
|
|
1868
|
+
ordering_candidates = (
|
|
1703
1869
|
self._schema_resolve_ordering(text_lower, table_context, schema)
|
|
1704
1870
|
if self._schema_has_explicit_ordering(text_lower)
|
|
1705
|
-
else
|
|
1871
|
+
else []
|
|
1706
1872
|
)
|
|
1873
|
+
if len(ordering_candidates) > 1 and (
|
|
1874
|
+
group_by or aggregations or label_resolution is not None
|
|
1875
|
+
):
|
|
1876
|
+
raise SchemaValidationError(
|
|
1877
|
+
"multi-column ORDER BY combinations are unsupported"
|
|
1878
|
+
)
|
|
1879
|
+
if len(ordering_candidates) > 1 and distinct:
|
|
1880
|
+
if columns == ["*"]:
|
|
1881
|
+
raise SchemaValidationError(
|
|
1882
|
+
"DISTINCT * cannot be combined with multi-column ORDER BY"
|
|
1883
|
+
)
|
|
1884
|
+
projected = {
|
|
1885
|
+
column.rsplit(".", 1)[-1].casefold()
|
|
1886
|
+
for column in columns
|
|
1887
|
+
}
|
|
1888
|
+
if any(column.casefold() not in projected for column, _ in ordering_candidates):
|
|
1889
|
+
raise SchemaValidationError(
|
|
1890
|
+
"DISTINCT ORDER BY columns must be projected"
|
|
1891
|
+
)
|
|
1892
|
+
ordering = ordering_candidates[0] if len(ordering_candidates) == 1 else None
|
|
1893
|
+
orderings = ordering_candidates if len(ordering_candidates) > 1 else None
|
|
1707
1894
|
limit = self._extract_limit(text_lower)
|
|
1708
|
-
distinct = self._check_distinct(text_lower)
|
|
1709
1895
|
render_columns = ["*"] if aggregations and not group_by else columns
|
|
1710
1896
|
sql, explanation, confidence, evidence = self._build_sql_enhanced(
|
|
1711
1897
|
operation,
|
|
@@ -1719,6 +1905,7 @@ class PipelineNL2SQLGenerator:
|
|
|
1719
1905
|
joins,
|
|
1720
1906
|
distinct,
|
|
1721
1907
|
dialect,
|
|
1908
|
+
orderings=orderings,
|
|
1722
1909
|
)
|
|
1723
1910
|
result = self._apply_confidence_policy(NL2SQLResult(
|
|
1724
1911
|
success=sql is not None,
|
|
@@ -1734,7 +1921,16 @@ class PipelineNL2SQLGenerator:
|
|
|
1734
1921
|
),
|
|
1735
1922
|
parsed_elements=parsed,
|
|
1736
1923
|
))
|
|
1737
|
-
|
|
1924
|
+
finalized = self._schema_finalize(result, schema)
|
|
1925
|
+
if finalized.success and finalized.schema_used:
|
|
1926
|
+
finalized.suggestions = self._schema_diagnostic_suggestions(
|
|
1927
|
+
text,
|
|
1928
|
+
table_context,
|
|
1929
|
+
schema,
|
|
1930
|
+
columns,
|
|
1931
|
+
list(finalized.suggestions),
|
|
1932
|
+
)
|
|
1933
|
+
return finalized
|
|
1738
1934
|
except (SchemaValidationError, ValueError):
|
|
1739
1935
|
return self._schema_failure(
|
|
1740
1936
|
text,
|
|
@@ -1916,6 +2112,7 @@ class PipelineNL2SQLGenerator:
|
|
|
1916
2112
|
joins,
|
|
1917
2113
|
distinct,
|
|
1918
2114
|
dialect,
|
|
2115
|
+
orderings=None,
|
|
1919
2116
|
) -> tuple:
|
|
1920
2117
|
"""Build SQL statement from extracted components.
|
|
1921
2118
|
|
|
@@ -1926,6 +2123,7 @@ class PipelineNL2SQLGenerator:
|
|
|
1926
2123
|
ir = _nl2sql_ir.build_ir(
|
|
1927
2124
|
operation, table, columns, conditions, aggregations,
|
|
1928
2125
|
group_by, ordering, limit, joins, distinct, dialect,
|
|
2126
|
+
orderings=orderings,
|
|
1929
2127
|
)
|
|
1930
2128
|
return _render_sql_impl(ir)
|
|
1931
2129
|
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/renderer.py
RENAMED
|
@@ -223,9 +223,13 @@ def render_sql(ir: QueryIR) -> Tuple[Optional[str], str, float, GenerationEviden
|
|
|
223
223
|
group_cols = [c for c in columns if c != "*"]
|
|
224
224
|
if group_cols:
|
|
225
225
|
sql += f"\nGROUP BY {', '.join(group_cols)}"
|
|
226
|
-
if ordering
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
active_orderings = ir.orderings or ([ordering] if ordering else [])
|
|
227
|
+
if active_orderings:
|
|
228
|
+
ordering_sql = ", ".join(
|
|
229
|
+
f"{column} {direction}" for column, direction in active_orderings
|
|
230
|
+
)
|
|
231
|
+
sql += f"\nORDER BY {ordering_sql}"
|
|
232
|
+
explanation_parts.append(f"排序: {ordering_sql}")
|
|
229
233
|
if limit is not None:
|
|
230
234
|
sql = add_limit(sql, limit, dialect)
|
|
231
235
|
explanation_parts.append(f"限制: {limit}条")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-dialect-master
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: SQL Dialect Master - Multi-database SQL conversion engine
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -38,7 +38,7 @@ Dynamic: license-file
|
|
|
38
38
|
|
|
39
39
|
Enterprise-grade multi-database SQL conversion engine supporting 12 database dialects.
|
|
40
40
|
|
|
41
|
-
Current release: 1.
|
|
41
|
+
Current release: 1.8.0
|
|
42
42
|
|
|
43
43
|
[](https://www.python.org/downloads/)
|
|
44
44
|
[](https://opensource.org/licenses/MIT)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/column_hint_validation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/__init__.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/aggregations.py
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/core_extract.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/evidence.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/mappings.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/relations.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/tokenizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/__init__.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/aggregations.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/clause_extract.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/dialect.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/intent.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/models.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/predicates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/resolution.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/suggestions.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/validation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/requires.txt
RENAMED
|
File without changes
|
{sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/top_level.txt
RENAMED
|
File without changes
|