refactor(core): route integrations through adapter factory
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
from pathlib import Path
|
||||
|
||||
import typer
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
from tht.adapters.factory import build_dwh
|
||||
from tht.cli.config_cmd import CONFIG_OPT
|
||||
from tht.config import ConfigError, load_config
|
||||
from tht.db.connection import make_engine
|
||||
from tht.db.introspect import IntrospectionError, introspect
|
||||
from tht.db.sampling import add_examples
|
||||
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)")
|
||||
@@ -64,32 +61,25 @@ def introspect_cmd(
|
||||
fg=typer.colors.GREEN,
|
||||
)
|
||||
return
|
||||
if cfg.database.transport == "rest":
|
||||
from tht.db.introspect import introspect_rest
|
||||
from tht.db.sampling import add_examples_rest
|
||||
from tht.rest.client import RestClient, RestError
|
||||
|
||||
client = RestClient(cfg.rest)
|
||||
try:
|
||||
phys = introspect_rest(
|
||||
client, database=cfg.database.database, schema=cfg.database.db_schema
|
||||
)
|
||||
add_examples_rest(client, phys, cfg.examples)
|
||||
classify_all(phys, cfg.eligibility)
|
||||
except RestError as e:
|
||||
typer.secho(f"ERRORE: {e}", fg=typer.colors.RED, err=True)
|
||||
raise typer.Exit(code=1)
|
||||
else:
|
||||
engine = make_engine(cfg.database)
|
||||
try:
|
||||
phys = introspect(
|
||||
engine, database=cfg.database.database, schema=cfg.database.db_schema
|
||||
)
|
||||
add_examples(engine, phys, cfg.examples)
|
||||
classify_all(phys, cfg.eligibility)
|
||||
except (OperationalError, IntrospectionError) as e:
|
||||
typer.secho(f"ERRORE: {e}", fg=typer.colors.RED, err=True)
|
||||
raise typer.Exit(code=1)
|
||||
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, "")
|
||||
]
|
||||
classify_all(phys, cfg.eligibility)
|
||||
except Exception as e:
|
||||
typer.secho(f"ERRORE: {e}", fg=typer.colors.RED, err=True)
|
||||
raise typer.Exit(code=1)
|
||||
phys.to_yaml(out)
|
||||
n_cols = sum(len(t.columns) for t in phys.tables.values())
|
||||
n_ignored = sum(
|
||||
|
||||
Reference in New Issue
Block a user