sql-dialect-master 1.8.0__tar.gz → 1.9.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.8.0 → sql_dialect_master-1.9.0}/PKG-INFO +2 -2
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/README.md +1 -1
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/main.py +51 -4
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/metadata.py +2 -2
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/orchestrator.py +88 -15
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/renderer.py +15 -1
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_schema.py +68 -16
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/pyproject.toml +1 -1
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/PKG-INFO +2 -2
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/LICENSE +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/auth.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/client_identity.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/metrics.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/middleware.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/rate_limit_store.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/readiness.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/api/workers.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/cache.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/column_hint_validation.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/config.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/constants.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/exceptions.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/function_call_scanner.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/function_semantics.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/functions_db.json +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/functions_lookup.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/aggregations.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/boolean_conditions.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/core_extract.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/evidence.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/mappings.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/relations.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/templates.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/tokenizer.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_legacy.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_llm.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/aggregations.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/clause_extract.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/dialect.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/intent.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/ir.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/models.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/predicates.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/resolution.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/suggestions.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/templates.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/validation.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/p1_sql_scanner.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/p2_data_validation.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/parser.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/post_processor.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/rules.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/semantic_diff.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/sql_statements.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/transpiler.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/type_mapping.json +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/type_mapping.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/utils/__init__.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/utils/validators.py +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/setup.cfg +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/SOURCES.txt +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/dependency_links.txt +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/requires.txt +0 -0
- {sql_dialect_master-1.8.0 → sql_dialect_master-1.9.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.9.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.9.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.9.0
|
|
6
6
|
|
|
7
7
|
[](https://www.python.org/downloads/)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -53,7 +53,10 @@ from backend.core.functions_lookup import FunctionEncyclopedia
|
|
|
53
53
|
from backend.core.nl2sql import NL2SQLGenerator, NL2SQLResult
|
|
54
54
|
from backend.core.nl2sql_components.evidence import EvidenceItem, GenerationEvidence
|
|
55
55
|
from backend.core.nl2sql_llm import LLMError, LLMN2SQLClient, validate_llm_sql
|
|
56
|
-
from backend.core.nl2sql_schema import
|
|
56
|
+
from backend.core.nl2sql_schema import (
|
|
57
|
+
MAX_SCHEMA_RELATIONSHIP_COLUMN_PAIRS,
|
|
58
|
+
SchemaContext,
|
|
59
|
+
)
|
|
57
60
|
from backend.core.nl2sql_pipeline.orchestrator import SAFE_TABLE_HINT
|
|
58
61
|
from backend.core.parser import SUPPORTED_DIALECTS, SQLParser
|
|
59
62
|
from backend.core.semantic_diff import diff_sql_ast
|
|
@@ -460,11 +463,33 @@ class SchemaTable(BaseModel):
|
|
|
460
463
|
columns: List[SchemaColumn] = Field(default_factory=list, max_length=200)
|
|
461
464
|
|
|
462
465
|
|
|
466
|
+
class SchemaColumnPair(BaseModel):
|
|
467
|
+
from_column: SchemaIdentifier
|
|
468
|
+
to_column: SchemaIdentifier
|
|
469
|
+
|
|
470
|
+
|
|
463
471
|
class SchemaRelationship(BaseModel):
|
|
464
472
|
from_table: SchemaIdentifier
|
|
465
|
-
from_column: SchemaIdentifier
|
|
473
|
+
from_column: Optional[SchemaIdentifier] = None
|
|
466
474
|
to_table: SchemaIdentifier
|
|
467
|
-
to_column: SchemaIdentifier
|
|
475
|
+
to_column: Optional[SchemaIdentifier] = None
|
|
476
|
+
columns: Optional[List[SchemaColumnPair]] = Field(None, max_length=8)
|
|
477
|
+
|
|
478
|
+
@model_validator(mode="after")
|
|
479
|
+
def validate_representation(self):
|
|
480
|
+
legacy = "from_column" in self.model_fields_set or "to_column" in self.model_fields_set
|
|
481
|
+
composite = "columns" in self.model_fields_set
|
|
482
|
+
if legacy == composite:
|
|
483
|
+
raise ValueError("invalid schema relationship")
|
|
484
|
+
if legacy and (self.from_column is None or self.to_column is None):
|
|
485
|
+
raise ValueError("invalid schema relationship")
|
|
486
|
+
if composite:
|
|
487
|
+
if not self.columns or len(self.columns) < 1:
|
|
488
|
+
raise ValueError("invalid schema relationship")
|
|
489
|
+
pairs = {(pair.from_column.casefold(), pair.to_column.casefold()) for pair in self.columns}
|
|
490
|
+
if len(pairs) != len(self.columns):
|
|
491
|
+
raise ValueError("invalid schema relationship")
|
|
492
|
+
return self
|
|
468
493
|
|
|
469
494
|
|
|
470
495
|
class SchemaDefinition(BaseModel):
|
|
@@ -476,12 +501,34 @@ class SchemaDefinition(BaseModel):
|
|
|
476
501
|
if sum(len(table.columns) for table in self.tables) > 1000:
|
|
477
502
|
raise ValueError("Schema must contain at most 1000 columns in total")
|
|
478
503
|
table_names = {table.name.casefold() for table in self.tables}
|
|
504
|
+
tables_by_key = {table.name.casefold(): table for table in self.tables}
|
|
505
|
+
relationship_pair_count = 0
|
|
479
506
|
for relationship in self.relationships:
|
|
480
507
|
if (
|
|
481
508
|
relationship.from_table.casefold() not in table_names
|
|
482
509
|
or relationship.to_table.casefold() not in table_names
|
|
483
510
|
):
|
|
484
|
-
raise ValueError("
|
|
511
|
+
raise ValueError("invalid schema relationship")
|
|
512
|
+
pairs = (
|
|
513
|
+
[(relationship.from_column, relationship.to_column)]
|
|
514
|
+
if relationship.columns is None
|
|
515
|
+
else [(pair.from_column, pair.to_column) for pair in relationship.columns]
|
|
516
|
+
)
|
|
517
|
+
relationship_pair_count += len(pairs)
|
|
518
|
+
if relationship_pair_count > MAX_SCHEMA_RELATIONSHIP_COLUMN_PAIRS:
|
|
519
|
+
raise ValueError("invalid schema relationship")
|
|
520
|
+
from_context = tables_by_key[relationship.from_table.casefold()]
|
|
521
|
+
to_context = tables_by_key[relationship.to_table.casefold()]
|
|
522
|
+
if from_context.columns and any(
|
|
523
|
+
not any(column.name.casefold() == from_column.casefold() for column in from_context.columns)
|
|
524
|
+
for from_column, _ in pairs
|
|
525
|
+
):
|
|
526
|
+
raise ValueError("invalid schema relationship")
|
|
527
|
+
if to_context.columns and any(
|
|
528
|
+
not any(column.name.casefold() == to_column.casefold() for column in to_context.columns)
|
|
529
|
+
for _, to_column in pairs
|
|
530
|
+
):
|
|
531
|
+
raise ValueError("invalid schema relationship")
|
|
485
532
|
return self
|
|
486
533
|
|
|
487
534
|
|
|
@@ -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.9.0"
|
|
21
|
+
API_VERSION = "1.9.0"
|
|
22
22
|
# Frontend v2 architecture — independent of the product release version.
|
|
23
23
|
FRONTEND_ARCHITECTURE_VERSION = 2
|
|
24
24
|
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/orchestrator.py
RENAMED
|
@@ -820,7 +820,9 @@ class PipelineNL2SQLGenerator:
|
|
|
820
820
|
f"{table_singular}_id".casefold(),
|
|
821
821
|
f"{table_basename}_id".casefold(),
|
|
822
822
|
}
|
|
823
|
-
|
|
823
|
+
if len(relationships[0].column_pairs) != 1:
|
|
824
|
+
raise SchemaValidationError("composite group-label relationship is unsupported")
|
|
825
|
+
from_column = relationships[0].column_pairs[0][0]
|
|
824
826
|
if from_column.casefold() not in allowed_foreign_keys:
|
|
825
827
|
raise SchemaValidationError(
|
|
826
828
|
"schema group label relationship has an unsupported foreign key"
|
|
@@ -1411,9 +1413,12 @@ class PipelineNL2SQLGenerator:
|
|
|
1411
1413
|
]
|
|
1412
1414
|
if raw_relationships:
|
|
1413
1415
|
def matches_relationship(relationship) -> bool:
|
|
1416
|
+
if len(relationship.column_pairs) != 1:
|
|
1417
|
+
return False
|
|
1418
|
+
from_column, to_column = relationship.column_pairs[0]
|
|
1414
1419
|
declared = {
|
|
1415
|
-
(relationship.from_table.casefold(),
|
|
1416
|
-
(relationship.to_table.casefold(),
|
|
1420
|
+
(relationship.from_table.casefold(), from_column.casefold()),
|
|
1421
|
+
(relationship.to_table.casefold(), to_column.casefold()),
|
|
1417
1422
|
}
|
|
1418
1423
|
supplied = {
|
|
1419
1424
|
(left_table.key, left_column.casefold()),
|
|
@@ -1504,9 +1509,9 @@ class PipelineNL2SQLGenerator:
|
|
|
1504
1509
|
if len(relationships) != 1:
|
|
1505
1510
|
raise SchemaValidationError("joined-with relationship is not unique")
|
|
1506
1511
|
relationship = relationships[0]
|
|
1507
|
-
condition = (
|
|
1508
|
-
f"{relationship.from_table}.{
|
|
1509
|
-
|
|
1512
|
+
condition = " AND ".join(
|
|
1513
|
+
f"{relationship.from_table}.{from_column} = {relationship.to_table}.{to_column}"
|
|
1514
|
+
for from_column, to_column in relationship.column_pairs
|
|
1510
1515
|
)
|
|
1511
1516
|
span = (match.start(), match.end())
|
|
1512
1517
|
return subject, [{
|
|
@@ -1675,6 +1680,56 @@ class PipelineNL2SQLGenerator:
|
|
|
1675
1680
|
else:
|
|
1676
1681
|
subject = mentions[0]
|
|
1677
1682
|
|
|
1683
|
+
def raw_edges_between(left: str, right: str) -> list:
|
|
1684
|
+
return [
|
|
1685
|
+
relationship for relationship in schema.relationships
|
|
1686
|
+
if {relationship.from_table.casefold(), relationship.to_table.casefold()}
|
|
1687
|
+
== {left.casefold(), right.casefold()}
|
|
1688
|
+
]
|
|
1689
|
+
|
|
1690
|
+
def condition_for(relationship, left: str, right: str) -> str:
|
|
1691
|
+
if relationship.from_table.casefold() == left.casefold():
|
|
1692
|
+
pairs = relationship.column_pairs
|
|
1693
|
+
return " AND ".join(
|
|
1694
|
+
f"{relationship.from_table}.{from_column} = {relationship.to_table}.{to_column}"
|
|
1695
|
+
for from_column, to_column in pairs
|
|
1696
|
+
)
|
|
1697
|
+
return " AND ".join(
|
|
1698
|
+
f"{relationship.to_table}.{to_column} = {relationship.from_table}.{from_column}"
|
|
1699
|
+
for from_column, to_column in relationship.column_pairs
|
|
1700
|
+
)
|
|
1701
|
+
|
|
1702
|
+
def shortest_path(target: SchemaTableContext) -> list[tuple[SchemaTableContext, str]] | None:
|
|
1703
|
+
queue: list[tuple[SchemaTableContext, list[tuple[SchemaTableContext, str]]]] = [(subject, [])]
|
|
1704
|
+
candidates: list[list[tuple[SchemaTableContext, str]]] = []
|
|
1705
|
+
while queue:
|
|
1706
|
+
current, path = queue.pop(0)
|
|
1707
|
+
if len(path) >= 2:
|
|
1708
|
+
continue
|
|
1709
|
+
for edge in schema.relationships:
|
|
1710
|
+
endpoints = {edge.from_table.casefold(), edge.to_table.casefold()}
|
|
1711
|
+
if current.key not in endpoints:
|
|
1712
|
+
continue
|
|
1713
|
+
next_name = edge.to_table if edge.from_table.casefold() == current.key else edge.from_table
|
|
1714
|
+
next_candidates = schema.table_candidates(next_name)
|
|
1715
|
+
if len(next_candidates) != 1:
|
|
1716
|
+
continue
|
|
1717
|
+
next_table = next_candidates[0]
|
|
1718
|
+
if next_table.key in {table.key for table, _ in path} or next_table.key == subject.key:
|
|
1719
|
+
continue
|
|
1720
|
+
next_path = [*path, (next_table, condition_for(edge, current.name, next_table.name))]
|
|
1721
|
+
if next_table.key == target.key:
|
|
1722
|
+
candidates.append(next_path)
|
|
1723
|
+
else:
|
|
1724
|
+
queue.append((next_table, next_path))
|
|
1725
|
+
if not candidates:
|
|
1726
|
+
return None
|
|
1727
|
+
shortest = min(len(path) for path in candidates)
|
|
1728
|
+
shortest_paths = [path for path in candidates if len(path) == shortest]
|
|
1729
|
+
if len(shortest_paths) != 1:
|
|
1730
|
+
raise SchemaValidationError("schema relationship path is ambiguous")
|
|
1731
|
+
return shortest_paths[0]
|
|
1732
|
+
|
|
1678
1733
|
relational = self._has_relational_keyword(text.lower())
|
|
1679
1734
|
lowered = text.lower()
|
|
1680
1735
|
unsupported_outer = (
|
|
@@ -1725,20 +1780,33 @@ class PipelineNL2SQLGenerator:
|
|
|
1725
1780
|
for related in mentions:
|
|
1726
1781
|
if related.key == subject.key:
|
|
1727
1782
|
continue
|
|
1728
|
-
|
|
1783
|
+
raw_candidates = raw_edges_between(subject.name, related.name)
|
|
1729
1784
|
condition = None
|
|
1730
|
-
if len(
|
|
1731
|
-
relationship
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1785
|
+
if len(raw_candidates) > 1:
|
|
1786
|
+
raise SchemaValidationError("schema relationship is ambiguous")
|
|
1787
|
+
if len(raw_candidates) == 1:
|
|
1788
|
+
condition = condition_for(raw_candidates[0], subject.name, related.name)
|
|
1789
|
+
joins.append({
|
|
1790
|
+
"type": join_type,
|
|
1791
|
+
"table": related.name,
|
|
1792
|
+
"subject": subject.name,
|
|
1793
|
+
"condition": condition,
|
|
1794
|
+
"relational": relational,
|
|
1795
|
+
"join_spec": join_spec,
|
|
1796
|
+
})
|
|
1797
|
+
continue
|
|
1798
|
+
if not relational:
|
|
1799
|
+
raise SchemaValidationError("multi-hop physical joins are unsupported")
|
|
1800
|
+
path = shortest_path(related)
|
|
1801
|
+
if path is None:
|
|
1802
|
+
raise SchemaValidationError("schema relationship path is missing")
|
|
1736
1803
|
joins.append({
|
|
1737
1804
|
"type": join_type,
|
|
1738
1805
|
"table": related.name,
|
|
1739
1806
|
"subject": subject.name,
|
|
1740
|
-
"condition":
|
|
1741
|
-
"
|
|
1807
|
+
"condition": path[0][1],
|
|
1808
|
+
"path": [{"table": table.name, "condition": edge_condition} for table, edge_condition in path],
|
|
1809
|
+
"relational": True,
|
|
1742
1810
|
"join_spec": join_spec,
|
|
1743
1811
|
})
|
|
1744
1812
|
return subject, joins
|
|
@@ -1865,6 +1933,11 @@ class PipelineNL2SQLGenerator:
|
|
|
1865
1933
|
)
|
|
1866
1934
|
)
|
|
1867
1935
|
distinct = self._check_distinct(text_lower)
|
|
1936
|
+
if any(join.get("path") for join in joins):
|
|
1937
|
+
if conditions or aggregations or group_by or label_resolution is not None or distinct:
|
|
1938
|
+
raise SchemaValidationError(
|
|
1939
|
+
"multi-hop paths cannot be combined with filters or aggregation"
|
|
1940
|
+
)
|
|
1868
1941
|
ordering_candidates = (
|
|
1869
1942
|
self._schema_resolve_ordering(text_lower, table_context, schema)
|
|
1870
1943
|
if self._schema_has_explicit_ordering(text_lower)
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/renderer.py
RENAMED
|
@@ -93,6 +93,8 @@ def render_sql(ir: QueryIR) -> Tuple[Optional[str], str, float, GenerationEviden
|
|
|
93
93
|
``(sql, explanation, confidence, evidence)``.
|
|
94
94
|
"""
|
|
95
95
|
for join in ir.joins:
|
|
96
|
+
if join.get("path"):
|
|
97
|
+
continue
|
|
96
98
|
if join.get("condition") is None:
|
|
97
99
|
subject = join.get("subject") or ir.table
|
|
98
100
|
pair_desc = f"{subject} ⟷ {join['table']}"
|
|
@@ -163,7 +165,19 @@ def render_sql(ir: QueryIR) -> Tuple[Optional[str], str, float, GenerationEviden
|
|
|
163
165
|
# Multiple relational EXISTS clauses compose into ONE WHERE:
|
|
164
166
|
# the first gets its own WHERE, the rest append with AND,
|
|
165
167
|
# mirroring standard SQL 'WHERE EXISTS (...) AND EXISTS (...)'.
|
|
166
|
-
|
|
168
|
+
if join.get("path"):
|
|
169
|
+
path = join["path"]
|
|
170
|
+
subquery = f"SELECT 1\n FROM {path[0]['table']}\n WHERE {path[0]['condition']}"
|
|
171
|
+
indent = " "
|
|
172
|
+
for step in path[1:]:
|
|
173
|
+
subquery += (
|
|
174
|
+
f"\n AND EXISTS (\n {indent}SELECT 1\n"
|
|
175
|
+
f" {indent}FROM {step['table']}\n"
|
|
176
|
+
f" {indent}WHERE {step['condition']}\n {indent})"
|
|
177
|
+
)
|
|
178
|
+
indent += " "
|
|
179
|
+
else:
|
|
180
|
+
subquery = f"SELECT 1\n FROM {join['table']}\n WHERE {join['condition']}"
|
|
167
181
|
# Merge date conditions into subquery if present
|
|
168
182
|
if conditions:
|
|
169
183
|
cond_sql = conditions if isinstance(conditions, str) else " AND ".join(conditions)
|
|
@@ -22,6 +22,9 @@ class SchemaValidationError(ValueError):
|
|
|
22
22
|
"""Raised when generated SQL cannot be grounded in a schema."""
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
MAX_SCHEMA_RELATIONSHIP_COLUMN_PAIRS = 1024
|
|
26
|
+
|
|
27
|
+
|
|
25
28
|
def _identifier_parts(value: object) -> tuple[str, ...]:
|
|
26
29
|
if not isinstance(value, str):
|
|
27
30
|
raise SchemaValidationError("invalid schema identifier")
|
|
@@ -53,9 +56,20 @@ class SchemaRelationshipContext:
|
|
|
53
56
|
"""One explicitly declared relationship between two schema tables."""
|
|
54
57
|
|
|
55
58
|
from_table: str
|
|
56
|
-
from_column: str
|
|
57
59
|
to_table: str
|
|
58
|
-
|
|
60
|
+
column_pairs: tuple[tuple[str, str], ...]
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def from_column(self) -> str:
|
|
64
|
+
if len(self.column_pairs) != 1:
|
|
65
|
+
raise SchemaValidationError("composite relationship has no single from_column")
|
|
66
|
+
return self.column_pairs[0][0]
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def to_column(self) -> str:
|
|
70
|
+
if len(self.column_pairs) != 1:
|
|
71
|
+
raise SchemaValidationError("composite relationship has no single to_column")
|
|
72
|
+
return self.column_pairs[0][1]
|
|
59
73
|
|
|
60
74
|
@property
|
|
61
75
|
def pair(self) -> tuple[str, str]:
|
|
@@ -144,6 +158,7 @@ class SchemaContext:
|
|
|
144
158
|
column_candidates.setdefault(_key(column), []).append(table)
|
|
145
159
|
|
|
146
160
|
relationships: list[SchemaRelationshipContext] = []
|
|
161
|
+
relationship_pair_count = 0
|
|
147
162
|
relationships_by_pair: dict[
|
|
148
163
|
tuple[str, str], list[SchemaRelationshipContext]
|
|
149
164
|
] = {}
|
|
@@ -153,37 +168,74 @@ class SchemaContext:
|
|
|
153
168
|
continue
|
|
154
169
|
try:
|
|
155
170
|
from_table = ".".join(_identifier_parts(raw_relationship.get("from_table")))
|
|
156
|
-
from_column = ".".join(_identifier_parts(raw_relationship.get("from_column")))
|
|
157
171
|
to_table = ".".join(_identifier_parts(raw_relationship.get("to_table")))
|
|
158
|
-
to_column = ".".join(_identifier_parts(raw_relationship.get("to_column")))
|
|
159
172
|
except SchemaValidationError:
|
|
160
173
|
valid = False
|
|
161
174
|
continue
|
|
175
|
+
has_legacy = "from_column" in raw_relationship or "to_column" in raw_relationship
|
|
176
|
+
has_composite = "columns" in raw_relationship
|
|
177
|
+
if has_legacy == has_composite:
|
|
178
|
+
valid = False
|
|
179
|
+
continue
|
|
180
|
+
if has_legacy:
|
|
181
|
+
try:
|
|
182
|
+
from_column = ".".join(_identifier_parts(raw_relationship.get("from_column")))
|
|
183
|
+
to_column = ".".join(_identifier_parts(raw_relationship.get("to_column")))
|
|
184
|
+
column_pairs = ((from_column, to_column),)
|
|
185
|
+
except SchemaValidationError:
|
|
186
|
+
valid = False
|
|
187
|
+
continue
|
|
188
|
+
else:
|
|
189
|
+
raw_pairs = raw_relationship.get("columns")
|
|
190
|
+
if not isinstance(raw_pairs, (list, tuple)) or not 1 <= len(raw_pairs) <= 8:
|
|
191
|
+
valid = False
|
|
192
|
+
continue
|
|
193
|
+
parsed_pairs: list[tuple[str, str]] = []
|
|
194
|
+
seen_pairs: set[tuple[str, str]] = set()
|
|
195
|
+
for raw_pair in raw_pairs:
|
|
196
|
+
if not isinstance(raw_pair, Mapping):
|
|
197
|
+
valid = False
|
|
198
|
+
break
|
|
199
|
+
try:
|
|
200
|
+
pair = (
|
|
201
|
+
".".join(_identifier_parts(raw_pair.get("from_column"))),
|
|
202
|
+
".".join(_identifier_parts(raw_pair.get("to_column"))),
|
|
203
|
+
)
|
|
204
|
+
except SchemaValidationError:
|
|
205
|
+
valid = False
|
|
206
|
+
break
|
|
207
|
+
pair_key = (_key(pair[0]), _key(pair[1]))
|
|
208
|
+
if pair_key in seen_pairs:
|
|
209
|
+
valid = False
|
|
210
|
+
break
|
|
211
|
+
seen_pairs.add(pair_key)
|
|
212
|
+
parsed_pairs.append(pair)
|
|
213
|
+
if not valid or len(parsed_pairs) == 0:
|
|
214
|
+
continue
|
|
215
|
+
column_pairs = tuple(parsed_pairs)
|
|
216
|
+
relationship_pair_count += len(column_pairs)
|
|
217
|
+
if relationship_pair_count > MAX_SCHEMA_RELATIONSHIP_COLUMN_PAIRS:
|
|
218
|
+
valid = False
|
|
219
|
+
continue
|
|
162
220
|
relationship = SchemaRelationshipContext(
|
|
163
221
|
from_table=from_table,
|
|
164
|
-
from_column=from_column,
|
|
165
222
|
to_table=to_table,
|
|
166
|
-
|
|
223
|
+
column_pairs=column_pairs,
|
|
167
224
|
)
|
|
168
225
|
from_context = tables_by_key.get(_key(from_table))
|
|
169
226
|
to_context = tables_by_key.get(_key(to_table))
|
|
170
227
|
if from_context is None or to_context is None:
|
|
171
228
|
valid = False
|
|
172
|
-
if from_context and from_context.has_column_metadata
|
|
173
|
-
_key(column) for column in from_context.columns
|
|
174
|
-
|
|
175
|
-
valid =
|
|
176
|
-
if to_context and to_context.has_column_metadata and _key(to_column) not in {
|
|
177
|
-
_key(column) for column in to_context.columns
|
|
178
|
-
}:
|
|
179
|
-
valid = False
|
|
229
|
+
if from_context and from_context.has_column_metadata:
|
|
230
|
+
valid = valid and all(_key(pair[0]) in {_key(column) for column in from_context.columns} for pair in column_pairs)
|
|
231
|
+
if to_context and to_context.has_column_metadata:
|
|
232
|
+
valid = valid and all(_key(pair[1]) in {_key(column) for column in to_context.columns} for pair in column_pairs)
|
|
180
233
|
relationships.append(relationship)
|
|
181
234
|
relationships_by_pair.setdefault(relationship.pair, []).append(relationship)
|
|
182
235
|
reverse = SchemaRelationshipContext(
|
|
183
236
|
from_table=to_table,
|
|
184
|
-
from_column=to_column,
|
|
185
237
|
to_table=from_table,
|
|
186
|
-
to_column
|
|
238
|
+
column_pairs=tuple((to_column, from_column) for from_column, to_column in column_pairs),
|
|
187
239
|
)
|
|
188
240
|
relationships_by_pair.setdefault(reverse.pair, []).append(reverse)
|
|
189
241
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-dialect-master
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9.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.9.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
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.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.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/__init__.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/aggregations.py
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/core_extract.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/evidence.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/mappings.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/relations.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_components/tokenizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/__init__.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/aggregations.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/clause_extract.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/dialect.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/intent.py
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/models.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/predicates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/resolution.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/suggestions.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/backend/core/nl2sql_pipeline/templates.py
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.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
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/requires.txt
RENAMED
|
File without changes
|
{sql_dialect_master-1.8.0 → sql_dialect_master-1.9.0}/sql_dialect_master.egg-info/top_level.txt
RENAMED
|
File without changes
|