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.
Files changed (70) hide show
  1. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/PKG-INFO +2 -2
  2. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/README.md +1 -1
  3. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/metadata.py +2 -2
  4. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/ir.py +3 -0
  5. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/orchestrator.py +231 -33
  6. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/renderer.py +7 -3
  7. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/pyproject.toml +1 -1
  8. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/PKG-INFO +2 -2
  9. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/LICENSE +0 -0
  10. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/__init__.py +0 -0
  11. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/__init__.py +0 -0
  12. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/auth.py +0 -0
  13. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/client_identity.py +0 -0
  14. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/main.py +0 -0
  15. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/metrics.py +0 -0
  16. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/middleware.py +0 -0
  17. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/rate_limit_store.py +0 -0
  18. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/readiness.py +0 -0
  19. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/api/workers.py +0 -0
  20. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/__init__.py +0 -0
  21. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/cache.py +0 -0
  22. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/column_hint_validation.py +0 -0
  23. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/config.py +0 -0
  24. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/constants.py +0 -0
  25. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/exceptions.py +0 -0
  26. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/function_call_scanner.py +0 -0
  27. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/function_semantics.py +0 -0
  28. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/functions_db.json +0 -0
  29. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/functions_lookup.py +0 -0
  30. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql.py +0 -0
  31. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/__init__.py +0 -0
  32. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/aggregations.py +0 -0
  33. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/boolean_conditions.py +0 -0
  34. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/core_extract.py +0 -0
  35. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/evidence.py +0 -0
  36. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/mappings.py +0 -0
  37. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/relations.py +0 -0
  38. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/templates.py +0 -0
  39. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/tokenizer.py +0 -0
  40. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_legacy.py +0 -0
  41. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_llm.py +0 -0
  42. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/__init__.py +0 -0
  43. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/aggregations.py +0 -0
  44. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/clause_extract.py +0 -0
  45. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/dialect.py +0 -0
  46. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/intent.py +0 -0
  47. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/models.py +0 -0
  48. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/predicates.py +0 -0
  49. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/resolution.py +0 -0
  50. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/suggestions.py +0 -0
  51. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/templates.py +0 -0
  52. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/validation.py +0 -0
  53. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_schema.py +0 -0
  54. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/p1_sql_scanner.py +0 -0
  55. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/p2_data_validation.py +0 -0
  56. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/parser.py +0 -0
  57. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/post_processor.py +0 -0
  58. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/rules.py +0 -0
  59. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/semantic_diff.py +0 -0
  60. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/sql_statements.py +0 -0
  61. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/transpiler.py +0 -0
  62. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.json +0 -0
  63. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.py +0 -0
  64. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/utils/__init__.py +0 -0
  65. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/backend/utils/validators.py +0 -0
  66. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/setup.cfg +0 -0
  67. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/SOURCES.txt +0 -0
  68. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/dependency_links.txt +0 -0
  69. {sql_dialect_master-1.6.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/requires.txt +0 -0
  70. {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.6.0
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.6.0
41
+ Current release: 1.8.0
42
42
 
43
43
  [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
44
44
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.6.0
5
+ Current release: 1.8.0
6
6
 
7
7
  [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.6.0"
21
- API_VERSION = "1.6.0"
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
  )
@@ -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
- ) -> Optional[Tuple[str, str]]:
975
- """Resolve one explicit schema-aware ORDER BY target."""
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
- return self._extract_ordering(text)
985
- raw_column, tail = match.groups()
986
- direction = "ASC"
987
- direction_match = re.match(
988
- r"\s+(ascending|descending|asc|desc|升序|降序)\b",
989
- tail,
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
- if direction_match:
993
- direction = "DESC" if direction_match.group(1).casefold() in {"descending", "desc", "降序"} else "ASC"
994
- tail = tail[direction_match.end():]
995
- if tail.strip(" \t\r\n,.;,。;"):
996
- raise SchemaValidationError("multiple schema-aware ordering columns are unsupported")
997
- parts = raw_column.split(".")
998
- column_name = parts[-1]
999
- if len(parts) > 1:
1000
- candidates = schema.table_candidates(".".join(parts[:-1]))
1001
- if len(candidates) != 1 or candidates[0].key != table.key:
1002
- raise SchemaValidationError("ordering column table is not the selected schema table")
1003
- canonical = schema.canonical_column(table, column_name)
1004
- if canonical is None:
1005
- raise SchemaValidationError("ordering column is outside the schema")
1006
- return canonical, direction
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(r"^and\b", stripped_tail, re.IGNORECASE):
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(r"^(?:where|whose)\b", stripped_tail, re.IGNORECASE):
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(r"^(?:where|whose)\b", stripped_tail, re.IGNORECASE):
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
- ordering = (
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 None
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
- return self._schema_finalize(result, schema)
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
 
@@ -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
- sql += f"\nORDER BY {ordering[0]} {ordering[1]}"
228
- explanation_parts.append(f"排序: {ordering[0]} {ordering[1]}")
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
  [project]
2
2
  name = "sql-dialect-master"
3
- version = "1.6.0"
3
+ version = "1.8.0"
4
4
  description = "SQL Dialect Master - Multi-database SQL conversion engine"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sql-dialect-master
3
- Version: 1.6.0
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.6.0
41
+ Current release: 1.8.0
42
42
 
43
43
  [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
44
44
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)