sql-dialect-master 1.10.0__tar.gz → 1.11.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.10.0 → sql_dialect_master-1.11.0}/PKG-INFO +2 -2
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/README.md +1 -1
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/metadata.py +2 -2
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/ir.py +11 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/orchestrator.py +16 -5
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/renderer.py +165 -1
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/pyproject.toml +1 -1
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/PKG-INFO +2 -2
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/LICENSE +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/auth.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/client_identity.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/main.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/metrics.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/middleware.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/rate_limit_store.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/readiness.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/api/workers.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/cache.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/column_hint_validation.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/config.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/constants.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/exceptions.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/function_call_scanner.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/function_semantics.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/functions_db.json +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/functions_lookup.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/aggregations.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/boolean_conditions.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/core_extract.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/evidence.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/mappings.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/relations.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/templates.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/tokenizer.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_legacy.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_llm.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/aggregations.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/clause_extract.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/dialect.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/intent.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/models.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/predicates.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/resolution.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/suggestions.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/templates.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/validation.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_schema.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/p1_sql_scanner.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/p2_data_validation.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/parser.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/post_processor.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/rules.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/semantic_diff.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/sql_statements.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/transpiler.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/type_mapping.json +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/type_mapping.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/utils/__init__.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/utils/validators.py +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/setup.cfg +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/SOURCES.txt +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/dependency_links.txt +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/requires.txt +0 -0
- {sql_dialect_master-1.10.0 → sql_dialect_master-1.11.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.11.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.11.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.11.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.11.0"
|
|
21
|
+
API_VERSION = "1.11.0"
|
|
22
22
|
# Frontend v2 architecture — independent of the product release version.
|
|
23
23
|
FRONTEND_ARCHITECTURE_VERSION = 2
|
|
24
24
|
|
|
@@ -13,6 +13,14 @@ from typing import Dict, List, Optional, Tuple, Union
|
|
|
13
13
|
from ..nl2sql_components.evidence import GenerationEvidence
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class DistinctCountPlan:
|
|
18
|
+
"""Validated identity columns for a derived distinct entity count."""
|
|
19
|
+
|
|
20
|
+
identity_columns: tuple[str, ...]
|
|
21
|
+
exclude_null_identity: bool = True
|
|
22
|
+
|
|
23
|
+
|
|
16
24
|
@dataclass
|
|
17
25
|
class QueryIR:
|
|
18
26
|
"""Structured intermediate representation for an NL2SQL query.
|
|
@@ -36,6 +44,7 @@ class QueryIR:
|
|
|
36
44
|
dialect: str
|
|
37
45
|
evidence: GenerationEvidence = field(default_factory=GenerationEvidence)
|
|
38
46
|
orderings: Optional[List[Tuple[str, str]]] = None
|
|
47
|
+
distinct_count_plan: Optional[DistinctCountPlan] = None
|
|
39
48
|
|
|
40
49
|
|
|
41
50
|
def build_ir(
|
|
@@ -51,6 +60,7 @@ def build_ir(
|
|
|
51
60
|
distinct: bool,
|
|
52
61
|
dialect: str,
|
|
53
62
|
orderings: Optional[List[Tuple[str, str]]] = None,
|
|
63
|
+
distinct_count_plan: Optional[DistinctCountPlan] = None,
|
|
54
64
|
) -> QueryIR:
|
|
55
65
|
"""Thin positional-arg adapter mirroring the legacy call site.
|
|
56
66
|
|
|
@@ -70,4 +80,5 @@ def build_ir(
|
|
|
70
80
|
distinct=distinct,
|
|
71
81
|
dialect=dialect,
|
|
72
82
|
orderings=orderings,
|
|
83
|
+
distinct_count_plan=distinct_count_plan,
|
|
73
84
|
)
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/orchestrator.py
RENAMED
|
@@ -1987,6 +1987,7 @@ class PipelineNL2SQLGenerator:
|
|
|
1987
1987
|
)
|
|
1988
1988
|
)
|
|
1989
1989
|
distinct = self._check_distinct(text_lower)
|
|
1990
|
+
distinct_count_plan = None
|
|
1990
1991
|
if unique_count_intent:
|
|
1991
1992
|
if len(unique_count_spans) != 1:
|
|
1992
1993
|
raise SchemaValidationError(
|
|
@@ -2003,9 +2004,9 @@ class PipelineNL2SQLGenerator:
|
|
|
2003
2004
|
raise SchemaValidationError(
|
|
2004
2005
|
"unique count with relationships is unsupported"
|
|
2005
2006
|
)
|
|
2006
|
-
if len(table_context.primary_key)
|
|
2007
|
+
if len(table_context.primary_key) == 0:
|
|
2007
2008
|
raise SchemaValidationError(
|
|
2008
|
-
"unique count requires
|
|
2009
|
+
"unique count requires a declared primary key"
|
|
2009
2010
|
)
|
|
2010
2011
|
if any(
|
|
2011
2012
|
not aggregation.upper().startswith("COUNT(")
|
|
@@ -2014,9 +2015,16 @@ class PipelineNL2SQLGenerator:
|
|
|
2014
2015
|
raise SchemaValidationError(
|
|
2015
2016
|
"unique count cannot combine with non-COUNT aggregation"
|
|
2016
2017
|
)
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2018
|
+
if len(table_context.primary_key) == 1:
|
|
2019
|
+
aggregations = [
|
|
2020
|
+
f"COUNT(DISTINCT {table_context.primary_key[0]}) AS count"
|
|
2021
|
+
]
|
|
2022
|
+
else:
|
|
2023
|
+
aggregations = []
|
|
2024
|
+
distinct_count_plan = _nl2sql_ir.DistinctCountPlan(
|
|
2025
|
+
tuple(table_context.primary_key),
|
|
2026
|
+
exclude_null_identity=True,
|
|
2027
|
+
)
|
|
2020
2028
|
distinct = False
|
|
2021
2029
|
if any(join.get("path") for join in joins):
|
|
2022
2030
|
if conditions or aggregations or group_by or label_resolution is not None or distinct:
|
|
@@ -2064,6 +2072,7 @@ class PipelineNL2SQLGenerator:
|
|
|
2064
2072
|
distinct,
|
|
2065
2073
|
dialect,
|
|
2066
2074
|
orderings=orderings,
|
|
2075
|
+
distinct_count_plan=distinct_count_plan,
|
|
2067
2076
|
)
|
|
2068
2077
|
result = self._apply_confidence_policy(NL2SQLResult(
|
|
2069
2078
|
success=sql is not None,
|
|
@@ -2271,6 +2280,7 @@ class PipelineNL2SQLGenerator:
|
|
|
2271
2280
|
distinct,
|
|
2272
2281
|
dialect,
|
|
2273
2282
|
orderings=None,
|
|
2283
|
+
distinct_count_plan=None,
|
|
2274
2284
|
) -> tuple:
|
|
2275
2285
|
"""Build SQL statement from extracted components.
|
|
2276
2286
|
|
|
@@ -2282,6 +2292,7 @@ class PipelineNL2SQLGenerator:
|
|
|
2282
2292
|
operation, table, columns, conditions, aggregations,
|
|
2283
2293
|
group_by, ordering, limit, joins, distinct, dialect,
|
|
2284
2294
|
orderings=orderings,
|
|
2295
|
+
distinct_count_plan=distinct_count_plan,
|
|
2285
2296
|
)
|
|
2286
2297
|
return _render_sql_impl(ir)
|
|
2287
2298
|
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/renderer.py
RENAMED
|
@@ -24,7 +24,7 @@ from ..nl2sql_components.evidence import (
|
|
|
24
24
|
GenerationEvidence,
|
|
25
25
|
)
|
|
26
26
|
from .dialect import apply_dialect_adjustments
|
|
27
|
-
from .ir import QueryIR
|
|
27
|
+
from .ir import DistinctCountPlan, QueryIR
|
|
28
28
|
from .validation import validate_sql
|
|
29
29
|
|
|
30
30
|
|
|
@@ -78,6 +78,167 @@ def parameter_placeholder(index: int, dialect: str) -> str:
|
|
|
78
78
|
return "?"
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
_SAFE_IDENTIFIER = re.compile(
|
|
82
|
+
r"[A-Za-z_][A-Za-z0-9_$]*(?:\.[A-Za-z_][A-Za-z0-9_$]*)*"
|
|
83
|
+
)
|
|
84
|
+
_DERIVED_COUNT_ALIAS = "_distinct_targets"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _safe_identifier(value: str) -> bool:
|
|
88
|
+
return isinstance(value, str) and _SAFE_IDENTIFIER.fullmatch(value) is not None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _render_plan_failure(reason: str) -> Tuple[None, str, float, GenerationEvidence]:
|
|
92
|
+
return None, f"Derived distinct count plan rejected: {reason}", 0.0, GenerationEvidence()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _render_distinct_count_plan(
|
|
96
|
+
ir: QueryIR,
|
|
97
|
+
) -> Tuple[Optional[str], str, float, GenerationEvidence]:
|
|
98
|
+
"""Render a validated composite-identity count through a derived table."""
|
|
99
|
+
plan: DistinctCountPlan = ir.distinct_count_plan # type: ignore[assignment]
|
|
100
|
+
if ir.operation != "SELECT":
|
|
101
|
+
return _render_plan_failure("only SELECT operations are supported")
|
|
102
|
+
if ir.joins:
|
|
103
|
+
return _render_plan_failure("joins are unsupported")
|
|
104
|
+
if ir.distinct:
|
|
105
|
+
return _render_plan_failure("DISTINCT projection is unsupported")
|
|
106
|
+
if ir.aggregations:
|
|
107
|
+
return _render_plan_failure("aggregations are unsupported")
|
|
108
|
+
if not plan.identity_columns or any(
|
|
109
|
+
not _safe_identifier(column) for column in plan.identity_columns
|
|
110
|
+
):
|
|
111
|
+
return _render_plan_failure("identity columns are invalid")
|
|
112
|
+
if not _safe_identifier(ir.table):
|
|
113
|
+
return _render_plan_failure("source table is invalid")
|
|
114
|
+
if any(not _safe_identifier(column) for column in ir.group_by):
|
|
115
|
+
return _render_plan_failure("group columns are invalid")
|
|
116
|
+
|
|
117
|
+
projection: list[str] = []
|
|
118
|
+
seen: set[str] = set()
|
|
119
|
+
for column in [*ir.group_by, *plan.identity_columns]:
|
|
120
|
+
key = column.casefold()
|
|
121
|
+
if key not in seen:
|
|
122
|
+
seen.add(key)
|
|
123
|
+
projection.append(column)
|
|
124
|
+
if not projection:
|
|
125
|
+
return _render_plan_failure("derived projection is empty")
|
|
126
|
+
|
|
127
|
+
conditions = ir.conditions
|
|
128
|
+
inner_conditions = (
|
|
129
|
+
[condition for condition in conditions if condition.strip()]
|
|
130
|
+
if isinstance(conditions, list)
|
|
131
|
+
else ([conditions] if conditions.strip() else [])
|
|
132
|
+
)
|
|
133
|
+
if plan.exclude_null_identity:
|
|
134
|
+
inner_conditions.extend(
|
|
135
|
+
f"{column} IS NOT NULL" for column in plan.identity_columns
|
|
136
|
+
)
|
|
137
|
+
inner_sql = (
|
|
138
|
+
f"SELECT DISTINCT {', '.join(projection)}\nFROM {ir.table}"
|
|
139
|
+
)
|
|
140
|
+
if inner_conditions:
|
|
141
|
+
inner_sql += "\nWHERE " + " AND ".join(inner_conditions)
|
|
142
|
+
indented_inner = "\n".join(
|
|
143
|
+
f" {line}" for line in inner_sql.splitlines()
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
select_clause = (
|
|
147
|
+
", ".join([*ir.group_by, "COUNT(*) AS count"])
|
|
148
|
+
if ir.group_by
|
|
149
|
+
else "COUNT(*) AS count"
|
|
150
|
+
)
|
|
151
|
+
sql = (
|
|
152
|
+
f"SELECT {select_clause}\n"
|
|
153
|
+
f"FROM (\n{indented_inner}\n) AS {_DERIVED_COUNT_ALIAS}"
|
|
154
|
+
)
|
|
155
|
+
explanation_parts = ["聚合: COUNT(*) AS count", f"表: {ir.table}"]
|
|
156
|
+
evidence = ir.evidence
|
|
157
|
+
evidence.items.append(EvidenceItem("base", "Base confidence for generated SQL", 0.5))
|
|
158
|
+
evidence.items.append(EvidenceItem(
|
|
159
|
+
EVIDENCE_AGGREGATION_PRESENT,
|
|
160
|
+
"Derived distinct entity count",
|
|
161
|
+
0.15,
|
|
162
|
+
detail=", ".join(plan.identity_columns),
|
|
163
|
+
))
|
|
164
|
+
if ir.table != "table_name":
|
|
165
|
+
evidence.items.append(EvidenceItem(
|
|
166
|
+
EVIDENCE_TABLE_KNOWN,
|
|
167
|
+
f"Table resolved to known name: {ir.table}",
|
|
168
|
+
0.2,
|
|
169
|
+
detail=ir.table,
|
|
170
|
+
))
|
|
171
|
+
if inner_conditions and isinstance(conditions, (list, str)) and conditions:
|
|
172
|
+
explanation_parts.append(
|
|
173
|
+
f"条件: {len(conditions) if isinstance(conditions, list) else 1}个"
|
|
174
|
+
)
|
|
175
|
+
evidence.items.append(EvidenceItem(
|
|
176
|
+
EVIDENCE_CONDITIONS_PRESENT,
|
|
177
|
+
"Explicit predicates in derived count input",
|
|
178
|
+
0.1,
|
|
179
|
+
))
|
|
180
|
+
if ir.group_by:
|
|
181
|
+
explanation_parts.append(f"分组: {', '.join(ir.group_by)}")
|
|
182
|
+
evidence.items.append(EvidenceItem(
|
|
183
|
+
EVIDENCE_GROUP_BY,
|
|
184
|
+
f"GROUP BY clause: {', '.join(ir.group_by)}",
|
|
185
|
+
0.1,
|
|
186
|
+
))
|
|
187
|
+
|
|
188
|
+
active_orderings = ir.orderings or ([ir.ordering] if ir.ordering else [])
|
|
189
|
+
ordering_sql = ""
|
|
190
|
+
if active_orderings:
|
|
191
|
+
group_keys = {column.casefold() for column in ir.group_by}
|
|
192
|
+
for column, direction in active_orderings:
|
|
193
|
+
if (
|
|
194
|
+
not _safe_identifier(column)
|
|
195
|
+
or direction not in {"ASC", "DESC"}
|
|
196
|
+
or column.casefold() == "count"
|
|
197
|
+
or column.casefold() not in group_keys
|
|
198
|
+
):
|
|
199
|
+
return _render_plan_failure(
|
|
200
|
+
"derived count ordering must use a grouped schema column"
|
|
201
|
+
)
|
|
202
|
+
ordering_sql = ", ".join(
|
|
203
|
+
f"{column} {direction}" for column, direction in active_orderings
|
|
204
|
+
)
|
|
205
|
+
explanation_parts.append(f"排序: {ordering_sql}")
|
|
206
|
+
if ir.group_by:
|
|
207
|
+
sql += f"\nGROUP BY {', '.join(ir.group_by)}"
|
|
208
|
+
if ordering_sql:
|
|
209
|
+
sql += f"\nORDER BY {ordering_sql}"
|
|
210
|
+
if ir.limit is not None:
|
|
211
|
+
sql = add_limit(sql, ir.limit, ir.dialect)
|
|
212
|
+
explanation_parts.append(f"限制: {ir.limit}条")
|
|
213
|
+
evidence.items.append(EvidenceItem(
|
|
214
|
+
EVIDENCE_LIMIT,
|
|
215
|
+
f"Explicit limit: {ir.limit}",
|
|
216
|
+
0.1,
|
|
217
|
+
detail=str(ir.limit),
|
|
218
|
+
))
|
|
219
|
+
|
|
220
|
+
sql = f"-- Generated for {ir.dialect.upper()}\n{sql}"
|
|
221
|
+
sql = apply_dialect_adjustments(sql, ir.dialect)
|
|
222
|
+
parse_adjustment = validate_sql(sql, ir.dialect)
|
|
223
|
+
if parse_adjustment > 0:
|
|
224
|
+
evidence.items.append(EvidenceItem(
|
|
225
|
+
EVIDENCE_PARSE_OK,
|
|
226
|
+
"Target dialect parser accepted the generated SQL",
|
|
227
|
+
parse_adjustment,
|
|
228
|
+
))
|
|
229
|
+
elif parse_adjustment < 0:
|
|
230
|
+
evidence.items.append(EvidenceItem(
|
|
231
|
+
EVIDENCE_PARSE_FAIL,
|
|
232
|
+
"Target dialect parser rejected the generated SQL",
|
|
233
|
+
parse_adjustment,
|
|
234
|
+
))
|
|
235
|
+
return None, (
|
|
236
|
+
"Generated SQL failed target-dialect validation: "
|
|
237
|
+
+ " | ".join(explanation_parts)
|
|
238
|
+
), 0.0, evidence
|
|
239
|
+
return sql, " | ".join(explanation_parts), evidence.score, evidence
|
|
240
|
+
|
|
241
|
+
|
|
81
242
|
# ── Renderer ────────────────────────────────────────────────────────────────
|
|
82
243
|
|
|
83
244
|
def render_sql(ir: QueryIR) -> Tuple[Optional[str], str, float, GenerationEvidence]:
|
|
@@ -92,6 +253,9 @@ def render_sql(ir: QueryIR) -> Tuple[Optional[str], str, float, GenerationEviden
|
|
|
92
253
|
Returns the same 4-tuple the legacy ``_build_sql_enhanced`` returns:
|
|
93
254
|
``(sql, explanation, confidence, evidence)``.
|
|
94
255
|
"""
|
|
256
|
+
if ir.distinct_count_plan is not None:
|
|
257
|
+
return _render_distinct_count_plan(ir)
|
|
258
|
+
|
|
95
259
|
for join in ir.joins:
|
|
96
260
|
if join.get("path"):
|
|
97
261
|
continue
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-dialect-master
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.11.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.11.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.10.0 → sql_dialect_master-1.11.0}/backend/core/column_hint_validation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/function_call_scanner.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/evidence.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/mappings.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/relations.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_components/tokenizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/__init__.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/aggregations.py
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/dialect.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/intent.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/models.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/predicates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/resolution.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/suggestions.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/backend/core/nl2sql_pipeline/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.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.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/requires.txt
RENAMED
|
File without changes
|
{sql_dialect_master-1.10.0 → sql_dialect_master-1.11.0}/sql_dialect_master.egg-info/top_level.txt
RENAMED
|
File without changes
|