sql-dialect-master 1.7.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.7.0 → sql_dialect_master-1.8.0}/PKG-INFO +2 -2
  2. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/README.md +1 -1
  3. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/metadata.py +2 -2
  4. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/ir.py +3 -0
  5. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/orchestrator.py +81 -32
  6. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/renderer.py +7 -3
  7. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/pyproject.toml +1 -1
  8. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/PKG-INFO +2 -2
  9. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/LICENSE +0 -0
  10. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/__init__.py +0 -0
  11. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/__init__.py +0 -0
  12. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/auth.py +0 -0
  13. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/client_identity.py +0 -0
  14. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/main.py +0 -0
  15. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/metrics.py +0 -0
  16. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/middleware.py +0 -0
  17. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/rate_limit_store.py +0 -0
  18. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/readiness.py +0 -0
  19. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/api/workers.py +0 -0
  20. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/__init__.py +0 -0
  21. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/cache.py +0 -0
  22. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/column_hint_validation.py +0 -0
  23. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/config.py +0 -0
  24. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/constants.py +0 -0
  25. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/exceptions.py +0 -0
  26. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/function_call_scanner.py +0 -0
  27. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/function_semantics.py +0 -0
  28. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/functions_db.json +0 -0
  29. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/functions_lookup.py +0 -0
  30. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql.py +0 -0
  31. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/__init__.py +0 -0
  32. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/aggregations.py +0 -0
  33. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/boolean_conditions.py +0 -0
  34. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/core_extract.py +0 -0
  35. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/evidence.py +0 -0
  36. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/mappings.py +0 -0
  37. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/relations.py +0 -0
  38. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/templates.py +0 -0
  39. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_components/tokenizer.py +0 -0
  40. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_legacy.py +0 -0
  41. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_llm.py +0 -0
  42. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/__init__.py +0 -0
  43. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/aggregations.py +0 -0
  44. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/clause_extract.py +0 -0
  45. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/dialect.py +0 -0
  46. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/intent.py +0 -0
  47. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/models.py +0 -0
  48. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/predicates.py +0 -0
  49. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/resolution.py +0 -0
  50. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/suggestions.py +0 -0
  51. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/templates.py +0 -0
  52. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_pipeline/validation.py +0 -0
  53. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/nl2sql_schema.py +0 -0
  54. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/p1_sql_scanner.py +0 -0
  55. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/p2_data_validation.py +0 -0
  56. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/parser.py +0 -0
  57. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/post_processor.py +0 -0
  58. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/rules.py +0 -0
  59. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/semantic_diff.py +0 -0
  60. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/sql_statements.py +0 -0
  61. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/transpiler.py +0 -0
  62. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.json +0 -0
  63. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/core/type_mapping.py +0 -0
  64. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/utils/__init__.py +0 -0
  65. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/backend/utils/validators.py +0 -0
  66. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/setup.cfg +0 -0
  67. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/SOURCES.txt +0 -0
  68. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/dependency_links.txt +0 -0
  69. {sql_dialect_master-1.7.0 → sql_dialect_master-1.8.0}/sql_dialect_master.egg-info/requires.txt +0 -0
  70. {sql_dialect_master-1.7.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.7.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.7.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.7.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.7.0"
21
- API_VERSION = "1.7.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
  )
@@ -983,39 +983,52 @@ class PipelineNL2SQLGenerator:
983
983
  text: str,
984
984
  table: SchemaTableContext,
985
985
  schema: SchemaContext,
986
- ) -> Optional[Tuple[str, str]]:
987
- """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."""
988
988
  match = re.search(
989
- r"\b(?:order(?:ed)?|sort(?:ed)?)\s+by\s+"
990
- r"([A-Za-z_][A-Za-z0-9_$]*(?:\.[A-Za-z_][A-Za-z0-9_$]*)?)"
991
- r"(.*)$",
989
+ r"\b(?:order(?:ed)?|sort(?:ed)?)\s+by\s+",
992
990
  text,
993
991
  re.IGNORECASE,
994
992
  )
995
993
  if match is None:
996
- return self._extract_ordering(text)
997
- raw_column, tail = match.groups()
998
- direction = "ASC"
999
- direction_match = re.match(
1000
- r"\s+(ascending|descending|asc|desc|升序|降序)\b",
1001
- 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*)?$",
1002
1009
  re.IGNORECASE,
1003
1010
  )
1004
- if direction_match:
1005
- direction = "DESC" if direction_match.group(1).casefold() in {"descending", "desc", "降序"} else "ASC"
1006
- tail = tail[direction_match.end():]
1007
- if tail.strip(" \t\r\n,.;,。;"):
1008
- raise SchemaValidationError("multiple schema-aware ordering columns are unsupported")
1009
- parts = raw_column.split(".")
1010
- column_name = parts[-1]
1011
- if len(parts) > 1:
1012
- candidates = schema.table_candidates(".".join(parts[:-1]))
1013
- if len(candidates) != 1 or candidates[0].key != table.key:
1014
- raise SchemaValidationError("ordering column table is not the selected schema table")
1015
- canonical = schema.canonical_column(table, column_name)
1016
- if canonical is None:
1017
- raise SchemaValidationError("ordering column is outside the schema")
1018
- 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
1019
1032
 
1020
1033
  def _schema_resolve_count_metric(
1021
1034
  self,
@@ -1294,7 +1307,11 @@ class PipelineNL2SQLGenerator:
1294
1307
  if re.search(r"\bor\b|\bwhose\b|[()]", tail, re.IGNORECASE):
1295
1308
  raise SchemaValidationError("complex whose predicates are unsupported")
1296
1309
  stripped_tail = tail.strip()
1297
- 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
+ ):
1298
1315
  raise SchemaValidationError("unexpected text after whose predicate")
1299
1316
  span = (match.start(), value_end)
1300
1317
  return predicate, span
@@ -1352,7 +1369,11 @@ class PipelineNL2SQLGenerator:
1352
1369
 
1353
1370
  tail = executable[value_end:]
1354
1371
  stripped_tail = tail.strip()
1355
- 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
+ ):
1356
1377
  raise SchemaValidationError("unexpected text after joined-on equality")
1357
1378
 
1358
1379
  def resolve_endpoint(raw: str) -> tuple[SchemaTableContext, str]:
@@ -1468,7 +1489,11 @@ class PipelineNL2SQLGenerator:
1468
1489
 
1469
1490
  tail = executable[match.end():]
1470
1491
  stripped_tail = tail.strip()
1471
- 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
+ ):
1472
1497
  raise SchemaValidationError("unexpected text after joined-with target")
1473
1498
  relationships = [
1474
1499
  relationship for relationship in schema.relationships
@@ -1839,13 +1864,34 @@ class PipelineNL2SQLGenerator:
1839
1864
  text_lower, table_context, schema, aggregations
1840
1865
  )
1841
1866
  )
1842
- ordering = (
1867
+ distinct = self._check_distinct(text_lower)
1868
+ ordering_candidates = (
1843
1869
  self._schema_resolve_ordering(text_lower, table_context, schema)
1844
1870
  if self._schema_has_explicit_ordering(text_lower)
1845
- else None
1871
+ else []
1846
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
1847
1894
  limit = self._extract_limit(text_lower)
1848
- distinct = self._check_distinct(text_lower)
1849
1895
  render_columns = ["*"] if aggregations and not group_by else columns
1850
1896
  sql, explanation, confidence, evidence = self._build_sql_enhanced(
1851
1897
  operation,
@@ -1859,6 +1905,7 @@ class PipelineNL2SQLGenerator:
1859
1905
  joins,
1860
1906
  distinct,
1861
1907
  dialect,
1908
+ orderings=orderings,
1862
1909
  )
1863
1910
  result = self._apply_confidence_policy(NL2SQLResult(
1864
1911
  success=sql is not None,
@@ -2065,6 +2112,7 @@ class PipelineNL2SQLGenerator:
2065
2112
  joins,
2066
2113
  distinct,
2067
2114
  dialect,
2115
+ orderings=None,
2068
2116
  ) -> tuple:
2069
2117
  """Build SQL statement from extracted components.
2070
2118
 
@@ -2075,6 +2123,7 @@ class PipelineNL2SQLGenerator:
2075
2123
  ir = _nl2sql_ir.build_ir(
2076
2124
  operation, table, columns, conditions, aggregations,
2077
2125
  group_by, ordering, limit, joins, distinct, dialect,
2126
+ orderings=orderings,
2078
2127
  )
2079
2128
  return _render_sql_impl(ir)
2080
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.7.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.7.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.7.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)