Skip to content

tdfs4ds.genai.attached_objects

tdfs4ds.genai.attached_objects

Views and tables attached to the feature store (0.3.5.2).

A view joining a registered dataset with a source table, or a table brought in by hand, is read by no process: the agent saw it "outside the feature store" and a full rebuild_lineage_graph() closed the edges an extra_views= call had recorded. attach_objects declares such objects part of the feature store's documented perimeter:

  • Marker: the reserved business-dictionary section ATTACHED on the object (JSON: kind, optional data domain, fingerprint, documentation time). No new table; every section reader skips it (deep_tables.RESERVED_SECTION_NAMES).
  • Lineage: an attached view's edges are recorded at once and every full rebuild seeds it, like a process view or a dataset.
  • Documentation: a column the view passes through unchanged takes the description of the column it comes from (PROPAGATED); computed columns and the object description go to the LLM. A table is documented by its owner (set_object_documentation).
  • Refresh: refresh_attached_objects compares the fingerprint (normalised view text and one hash per column, or the table's column types) and re-documents only what changed; an object gone from the database is detached, its documentation ended (still readable at a past date).

Parts written by a person (IMPORTED / MANUAL provenance) are never overwritten.

ATTACHED_SECTION module-attribute

ATTACHED_SECTION = 'ATTACHED'

KIND_TABLE module-attribute

KIND_TABLE = 'T'

KIND_VIEW module-attribute

KIND_VIEW = 'V'

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

attached_index

attached_index() -> Dict[Tuple[str, str], str]

{(DB, OBJ): 'V' | 'T'} of the attached objects (the agent's scope). Fail-open: {}.

attached_objects

attached_objects(data_domain: Optional[str] = None) -> pd.DataFrame

The attached objects: DATABASE_NAME, OBJECT_NAME, KIND ('V' / 'T'), DATA_DOMAIN, DOCUMENTED_AT (optionally of one data domain).

attached_view_names

attached_view_names() -> List[Tuple[str, str]]

[(db, view)] of the attached views (the lineage rebuild seeds them).

parse_marker

parse_marker(text) -> Optional[dict]

read_marker

read_marker(db: str, obj: str) -> Optional[dict]

_markers

_markers() -> List[Tuple[str, str, dict]]

_end_marker

_end_marker(db, obj)

detach_objects

detach_objects(objects, *, dry_run: bool = False) -> List[dict]

End the ATTACHED marker. The documentation stays; the lineage edges of a view are closed by the next full rebuild_lineage_graph (it is no longer seeded).

parse_view_sources

parse_view_sources(ddl: str, view_database: Optional[str] = None) -> dict

The relations a view reads and, for each output column, its source. Pure.

Returns {"ok": True, "view": [db, name], "sources": [[db, obj], ...], "columns": {view column: [db, obj, column]}, "star": [[db, obj], ...], "items": {view column: select item text}, "computed": [view columns]} or {"ok": False, "reason"}. A column is a source column when its select item is a plain column of one named relation (renamed or not); anything else is computed. A set operation at the top level makes every column computed. Several relations are fine (unlike parse_exposed_view).

_sha

_sha(text: str) -> str

view_fingerprint

view_fingerprint(ddl: str, info: dict) -> dict

{"text", "columns": {column: hash}, "sources": [...]} of a view. Pure.

text hashes the normalised view text (process_sql.normalise_sql, the package's one SQL normaliser); each column hashes its select item and its source.

table_fingerprint

table_fingerprint(columns: Dict[str, str]) -> dict

{"text", "columns": {column: type}} of a table. Pure.

compare_fingerprints

compare_fingerprints(stored: Optional[dict], current: dict) -> dict

{"same", "added", "changed", "removed", "sources_changed"}. Pure.

render_marker

render_marker(kind: str, data_domain: Optional[str], fingerprint: dict, documented_at: Optional[str]) -> str

propagation_rows

propagation_rows(view: Tuple[str, str], info: dict, source_docs: Dict[Tuple[str, str, str], str], view_columns: Optional[List[str]] = None, only: Optional[Iterable[str]] = None) -> List[dict]

BD_COLUMNS rows for the view's pass-through columns. Pure.

source_docs: {(DB, OBJ, COLUMN) upper: description} of the source columns. A column listed by a * of a source takes the description of the same-named column of that source (only for a column of view_columns). only: restrict to these view columns (upper).

_rows

_rows(sql: str)

_exec

_exec(sql: str)

_bd

_bd(name: str) -> str

_where_obj

_where_obj(db_col, obj_col, db, obj) -> str

_split

_split(name: str) -> Tuple[str, str]

_db_now

_db_now() -> str

_dbc_kind

_dbc_kind(db: str, obj: str) -> Optional[str]

'V' (view) / 'T' (table) / None (absent or not visible).

_table_column_types

_table_column_types(db: str, obj: str) -> Dict[str, str]

_view_columns

_view_columns(db: str, obj: str) -> List[str]

_feature_store_objects

_feature_store_objects() -> Dict[Tuple[str, str], str]

{(DB, OBJ): 'process' | 'dataset'} of the registered process views and datasets.

_source_docs

_source_docs(sources: Iterable[Tuple[str, str]]) -> Dict[Tuple[str, str, str], str]

Column descriptions of the source objects, one BD_COLUMNS read. A process view's or dataset's columns are its features: their text is there too.

_sources_changed_since

_sources_changed_since(sources: Iterable[Tuple[str, str]], since: Optional[str]) -> bool

Whether a source object's documentation (columns or description) was written after since.

_write_marker

_write_marker(db, obj, kind, data_domain, fingerprint, documented_at, event_id)

_end_columns

_end_columns(db, obj, columns, protected) -> Tuple[List[str], List[str]]

End the BD_COLUMNS rows of columns (removed from the view), except protected ones.

_end_documentation

_end_documentation(db, obj, protected) -> dict

End the object's BD rows (a disappeared object), protected parts aside.

_llm_document

_llm_document(db, obj, ddl, info) -> str

Object description and computed columns by the LLM (_document_intermediate_view with the view's sources as upstream context). Returns a status text; never raises.

_document_view

_document_view(db, obj, ddl, info, report, *, llm: bool, only_columns=None, author=None, event_id=None)

Propagate the pass-through columns (always), the LLM part when llm.

_resolve

_resolve(objects) -> List[Tuple[str, str]]

attach_objects

attach_objects(objects, data_domain: Optional[str] = None, *, document: bool = True, refresh_lineage: bool = True, refresh_index: bool = True, author: Optional[str] = None, dry_run: bool = False) -> List[dict]

Attach views and tables to the feature store's documented perimeter.

objects: 'DB.NAME' or a list. data_domain: optional; an object with one shows in that domain's summaries. A view: its lineage edges are recorded (and kept by every full rebuild_lineage_graph), its pass-through columns take their sources' documentation, and with document the LLM writes its description and computed columns. A table: registered as it is (document it with set_object_documentation). A process view, a dataset or an FS_* object is refused (already in the feature store); so is a name not found in the database. Returns one report per object.

refresh_attached_objects

refresh_attached_objects(objects=None, *, dry_run: bool = True, document: bool = True, refresh_index: bool = True, author: Optional[str] = None) -> List[dict]

Re-document the attached objects that changed; detach the ones that disappeared.

States: unchanged (skipped, no write, no LLM); sources_changed (a source's documentation changed: pass-through columns copied again, no LLM); changed (the view text or the table columns changed: added / changed columns re-documented, removed ones ended, the LLM pass only when a computed column or the sources changed, lineage re-recorded); broken (exists but no longer compiles: reported, nothing written); disappeared (gone: marker ended, lineage closed, documentation ended - still readable at a past date -, a person's parts kept and reported). dry_run=True (default) only classifies.

suggest_attachments

suggest_attachments(databases, *, include_processes: bool = True) -> pd.DataFrame

Views of databases that read a registered dataset (or process view) and are not attached. Read only: VIEW, READS, ATTACHED. Matching on whole qualified names.