fix(dwh): align adapter sampling contract
This commit is contained in:
@@ -2,16 +2,12 @@
|
||||
|
||||
from tht.config import DatabaseConfig, RestConfig
|
||||
from tht.db.introspect import introspect_rest
|
||||
from tht.execute import ExecResult, PlanSummary
|
||||
from tht.db import sampling
|
||||
from tht.execute import ExecResult, ExecutionError, PlanSummary
|
||||
from tht.mschema.models import PhysicalSchema
|
||||
from tht.ports.dwh import DwhCapabilities, DwhHealth
|
||||
from tht.ports.dwh import DistinctValues, DwhCapabilities, DwhHealth
|
||||
from tht.rest.client import RestClient, RestError
|
||||
from tht.rest.execute import (
|
||||
distinct_values_rest,
|
||||
explain_rest,
|
||||
run_controlled_rest,
|
||||
sample_column_rest,
|
||||
)
|
||||
from tht.rest.execute import explain_rest, run_controlled_rest
|
||||
|
||||
|
||||
class ThothRestDwhAdapter:
|
||||
@@ -34,18 +30,24 @@ class ThothRestDwhAdapter:
|
||||
self._client, self._database.database, self._database.db_schema
|
||||
)
|
||||
|
||||
def run_query(self, sql: str, *, limit: int | None = None) -> ExecResult:
|
||||
return run_controlled_rest(self._client, sql, limit=10 if limit is None else limit)
|
||||
def run_query(self, sql: str, *, limit: int) -> ExecResult:
|
||||
return run_controlled_rest(self._client, sql, limit=limit)
|
||||
|
||||
def explain(self, sql: str) -> PlanSummary:
|
||||
return explain_rest(self._client, sql)
|
||||
|
||||
def sample_column(self, table: str, column: str, *, limit: int) -> list[object]:
|
||||
return sample_column_rest(
|
||||
self._client, self._database.db_schema, table, column, limit=limit
|
||||
)
|
||||
try:
|
||||
return sampling.sample_column_rest(
|
||||
self._client, self._database.db_schema, table, column, limit=limit
|
||||
)
|
||||
except RestError as exc:
|
||||
raise ExecutionError(str(exc)) from exc
|
||||
|
||||
def distinct_values(self, table: str, column: str) -> list[object]:
|
||||
return distinct_values_rest(
|
||||
self._client, self._database.db_schema, table, column
|
||||
)
|
||||
def distinct_values(self, table: str, column: str) -> DistinctValues:
|
||||
try:
|
||||
return sampling.distinct_values_rest(
|
||||
self._client, self._database.db_schema, table, column
|
||||
)
|
||||
except RestError as exc:
|
||||
raise ExecutionError(str(exc)) from exc
|
||||
|
||||
Reference in New Issue
Block a user