File size: 721 Bytes
efc0c0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""SqlCompiler — IR → (SQL string, parameters list).

Identifiers (table, column names) come from the catalog (trusted).
Values come from IR.filters and are ALWAYS parameterized — never inlined.
Output is validated by sqlglot before reaching the executor.
"""

from dataclasses import dataclass

from ...catalog.models import Catalog
from ..ir.models import QueryIR
from .base import BaseCompiler


@dataclass
class CompiledSql:
    sql: str
    params: list[object]


class SqlCompiler(BaseCompiler):
    """Deterministic IR → SQL. No LLM."""

    def __init__(self, catalog: Catalog) -> None:
        self._catalog = catalog

    def compile(self, ir: QueryIR) -> CompiledSql:
        raise NotImplementedError