fix(core): preserve adapter command contracts

This commit is contained in:
2026-07-11 21:00:50 +02:00
parent dbbab6d005
commit a35efa16de
20 changed files with 163 additions and 143 deletions
+19 -12
View File
@@ -1,4 +1,5 @@
from pathlib import Path
import logging
import typer
from tht.adapters.factory import build_dwh
@@ -8,6 +9,23 @@ from tht.db.sampling import is_text_type
from tht.mschema.eligibility import classify_all
schema_app = typer.Typer(help="Gestione mschema (rappresentazione canonica dello schema)")
logger = logging.getLogger(__name__)
def _add_examples(dwh, phys, examples) -> None:
for table_name, table in phys.tables.items():
for column_name, column in table.columns.items():
if not is_text_type(column.type):
continue
try:
sampled = dwh.sample_column(
table_name, column_name, limit=examples.max_per_column
)
except Exception as exc:
logger.warning("Campionamento saltato per %s.%s: %s",
table_name, column_name, exc)
continue
column.examples = [str(value) for value in sampled if value not in (None, "")]
def _load_config_or_exit(config: Path):
@@ -64,18 +82,7 @@ def introspect_cmd(
try:
dwh = build_dwh(cfg)
phys = dwh.introspect()
for table_name, table in phys.tables.items():
for column_name, column in table.columns.items():
if is_text_type(column.type):
column.examples = [
str(value)
for value in dwh.sample_column(
table_name,
column_name,
limit=cfg.examples.max_per_column,
)
if value not in (None, "")
]
_add_examples(dwh, phys, cfg.examples)
classify_all(phys, cfg.eligibility)
except Exception as e:
typer.secho(f"ERRORE: {e}", fg=typer.colors.RED, err=True)