Skip to content

tdfs4ds.genai.documentation_tracking

tdfs4ds.genai.documentation_tracking

Who wrote each piece of documentation, and what was done to it (0.3.2.1).

Two optional tables, created when missing; the six documentation tables (business dictionary + process documentation) are never altered:

FS_DOCUMENTATION_PROVENANCE (VALIDTIME) One row per human-authored or copied documentation part: (DATABASE_NAME, OBJECT_NAME, PART, PART_NAME) + DOC_SOURCE (IMPORTED | MANUAL | PROPAGATED), DB_USER (the database USER, authoritative), EDITOR_NAME (declared by the person: the admin app connects with one account for everybody) and the EVENT_ID of the log row that set it. No row = written by the LLM, or before 0.3.2.1. The LLM pipelines write no provenance, and keep every IMPORTED / MANUAL part (:func:protected_parts).

FS_DOCUMENTATION_LOG (plain, append-only) One row per documentation action, opened RUNNING and closed with its status like FS_FOLLOW_UP, with RUN_ID / PROCESS_ID so the two join. It is deliberately NOT the follow-up table: every follow-up reader treats a row as a process execution (run() skips a computation that already has a COMPLETED row at its valid time), and that table cannot take a column.

A part is keyed on the object it documents, with the business dictionary's identity: a feature is (view db, process view, 'COLUMN', feature) - one key for its two storage places - a process's business logic is (view db, process view, 'BUSINESS_LOGIC', ''), an object's description (db, object, 'DESCRIPTION', ''), a section ('SECTION', name).

Everything here is fail-open: a missing or unwritable table gives one warning and the documentation action itself still happens.

PROTECTED module-attribute

PROTECTED = ('MANUAL', 'IMPORTED')

SOURCES module-attribute

SOURCES = ('MANUAL', 'IMPORTED', 'PROPAGATED')

PARTS module-attribute

PARTS = ('DESCRIPTION', 'SECTION', 'COLUMN', 'BUSINESS_LOGIC', 'ENTITY_COLUMN')

ACTIONS module-attribute

ACTIONS = ('MANUAL_EDIT', 'IMPORT', 'PROPAGATE', 'PROTECT', 'RELEASE', 'LLM_DOCUMENT', 'CASCADE', 'INDEX_REFRESH')

_STATE module-attribute

_STATE: Dict[str, Optional[bool]] = {'provenance': None, 'log': None}

_WARNED module-attribute

_WARNED: Set[str] = set()

_OVERWRITE module-attribute

_OVERWRITE = ContextVar('tdfs4ds_doc_overwrite_manual', default=False)

_ORIGIN module-attribute

_ORIGIN = ContextVar('tdfs4ds_doc_origin', default='api')

_EDITOR module-attribute

_EDITOR = ContextVar('tdfs4ds_doc_editor', default=None)

Key module-attribute

Key = Tuple[str, str, str, str]

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.

_warn_once

_warn_once(key: str, message: str) -> None

reset_tracking_state

reset_tracking_state() -> None

Forget what was learnt about the two tables (tests, or after setup()).

overwriting_manual

overwriting_manual(flag: bool = True)

Within the block, LLM writers may replace IMPORTED / MANUAL parts.

overwrite_manual_active

overwrite_manual_active() -> bool

documentation_origin

documentation_origin(origin: str, editor: Optional[str] = None)

Label the actions of the block (ORIGIN), and their declared editor.

current_origin

current_origin() -> str

current_editor

current_editor(author: Optional[str] = None) -> Optional[str]

The declared editor: author=, else the block's editor, else the OS user.

provenance_ddl

provenance_ddl() -> str

log_ddl

log_ddl() -> str

provenance_view_sql

provenance_view_sql() -> str

log_view_sql

log_view_sql() -> str

_create

_create(kind: str, ddl: str, view_sql: str, table: str) -> bool

documentation_tracking_creation

documentation_tracking_creation() -> dict

Create the provenance and log tables (and their views) when missing.

Never raises: a failure is remembered (no retry on reads) and reported once. Returns {'provenance': bool, 'log': bool}.

ensure_documentation_tracking

ensure_documentation_tracking(existing: Optional[Iterable[str]] = None) -> dict

connect() hook: create the tracking tables that are missing.

existing is the lower-cased object set connect() already read from DBC; a table found there is only marked available (its view is refreshed, REPLACE VIEW being idempotent), so an up-to-date store pays no CREATE. Never raises.

_table_exists

_table_exists(table: str) -> bool

available

available(kind: str) -> bool

Whether the provenance / log table can be used (checked once per process).

_lit

_lit(v) -> str

_detail_text

_detail_text(detail) -> Optional[str]

log_open

log_open(action: str, target_kind: str, *, database=None, obj=None, part=None, part_name=None, process_id=None, editor=None, detail=None, parent_event_id=None) -> Optional[str]

Insert a RUNNING row; returns its EVENT_ID, or None when not logged.

log_close

log_close(event_id: Optional[str], status: str = 'COMPLETED', detail=None) -> None

logged

logged(action: str, target_kind: str, **kw)

Open a log row for the block and close it COMPLETED or FAILED,.

Yields a dict: event_id, detail (filled by the block and stored when it closes) and status (overridable, e.g. 'COMPLETED,2 kept').

documentation_log

documentation_log(target=None, since=None, actions=None, limit: Optional[int] = None)

The documentation activity log as a teradataml DataFrame (sort it with .sort).

target: an object name ('DB.OBJ' or 'OBJ'); since: a timestamp string; actions: a list of ACTION values.

log_rows

log_rows(database=None, obj=None, limit: int = 20) -> pd.DataFrame

Latest log rows of one object, as pandas (newest first). Empty when unavailable.

_norm_key

_norm_key(database, obj, part, part_name) -> Key

provenance_rows

provenance_rows(database=None, obj=None) -> pd.DataFrame

Current provenance rows (all, or of one object), as pandas.

provenance_index

provenance_index(database=None, obj=None) -> Dict[Key, dict]

{normalised key: row dict} of the current provenance rows.

protected_parts

protected_parts(database, obj) -> Set[Tuple[str, str]]

{(PART, PART_NAME_UPPER)} of the IMPORTED / MANUAL parts of an object.

Empty when overwriting is allowed (overwriting_manual) or the table is unavailable - LLM runs then behave as before 0.3.2.1.

record_provenance

record_provenance(keys: Iterable[Tuple[str, str, str, str]], source: str, editor: Optional[str] = None, event_id: Optional[str] = None) -> int

Mark parts as IMPORTED / MANUAL / PROPAGATED (one MERGE per 50 parts).

Returns the number of parts marked; 0 when the table is unavailable.

clear_provenance

clear_provenance(keys: Iterable[Tuple[str, str, str, str]]) -> int

Close the provenance rows of these parts: the LLM may rewrite them again.