Skip to content

tdfs4ds.genai.valid_from

tdfs4ds.genai.valid_from

Valid time of written documentation (0.3.7.34).

Documentation says what an object means, not what was true on the day it was typed. A row written with CURRENT VALIDTIME is valid only from the write time on, so a read at an earlier valid time (the domain clock's business date, a dataset built as_of, the agent's as-of date) found no documentation at all. The valid start of a written part is now chosen as follows. Metadata is valid in REAL time (CURRENT VALIDTIME at the write, first load included); data (feature values) is valid in business time. The agent reads documentation at the current time, so no backdating is needed:

  1. default: CURRENT VALIDTIME;
  2. valid_from= (explicit opt-in, a date the caller gives; one name everywhere documentation is written): a part with no row yet starts at that date; a later change to a part that already has a row keeps CURRENT VALIDTIME.

clock_first_date and FIRST_LOAD_VALID_FROM remain available for explicit use (backdate_documentation) but are not used by default.

Writes use the explicit period form VALIDTIME PERIOD '(t, UNTIL_CHANGED)' (the ingestion MERGE's own); a plain sequenced INSERT does not fill the period (Error 3811). Provenance and the activity log keep the write time: they record the act of writing.

Pure helpers first, then the one database read (the clock's first date). Never raises.

FIRST_LOAD_VALID_FROM module-attribute

FIRST_LOAD_VALID_FROM = '1900-01-01 00:00:00+00:00'

_VALID_FROM module-attribute

_VALID_FROM = contextvars.ContextVar('tdfs4ds_doc_valid_from', default=None)

_DOMAIN module-attribute

_DOMAIN = contextvars.ContextVar('tdfs4ds_doc_valid_from_domain', default=None)

_OFFSET_RE module-attribute

_OFFSET_RE = re.compile('(Z|[+-]\\d\\d:?\\d\\d)$', re.I)

normalise_valid_from

normalise_valid_from(value) -> Optional[str]

None / '' -> None; else 'YYYY-MM-DD HH:MM:SS[.f]+HH:MM' (no offset = UTC). Pure.

Raises ValueError for a date that cannot be read (never guessed).

validtime_qualifier

validtime_qualifier(valid_from: Optional[str]) -> str

The temporal qualifier opening a MERGE / DELETE: CURRENT VALIDTIME or the explicit period. Pure.

open_end

open_end() -> str

The valid end of an open first version written with explicit period columns, as SQL: the keyword UNTIL_CHANGED (live: accepted as a ValidEnd value, reads back as a CURRENT VALIDTIME write's 9999-12-31 23:59:59+00:00), else the store's END_PERIOD timestamp. Pure.

first_version_insert_sql

first_version_insert_sql(table: str, columns, source_sql: str, valid_from: str) -> str

The INSERT of the FIRST version of parts, valid from valid_from until changed (pure).

A sequenced MERGE / INSERT does not fill the period columns (Error 3811, ValidStart is NOT NULL), so the period is written explicitly: NONSEQUENCED VALIDTIME INSERT ... (cols, ValidStart, ValidEnd). table: the qualified table; source_sql: a table name or a SELECT / ( ... ) giving columns (the period columns are added). A change to a part that already has a row stays a CURRENT VALIDTIME MERGE / UPDATE (its previous text becomes history).

choose_valid_from

choose_valid_from(explicit: Optional[str], first_load: bool, clock_first: Optional[str]) -> Optional[str]

The valid start of a part (pure): the explicit valid_from= if given, else None = CURRENT VALIDTIME (real time), first load included. first_load and clock_first are kept for compatibility and ignored: metadata is valid in real time, data in business time.

split_first_load

split_first_load(keys: Iterable[Tuple], existing: Set[Tuple]) -> Set[Tuple]

The keys with no row at all yet (pure). Keys compare upper-cased and unquoted.

documentation_valid_from

documentation_valid_from(valid_from=None, data_domain=None)

Valid start of every documentation row written inside the block (valid_from=), and the data domain whose clock gives the first-load date (default tdfs4ds.DATA_DOMAIN).

explicit_valid_from

explicit_valid_from() -> Optional[str]

current_domain

current_domain() -> Optional[str]

with_valid_from

with_valid_from(fn)

Decorator: the function accepts valid_from= (and data_domain_for_clock= is not needed: the domain is the call's data_domain when it has one). The value is applied to every documentation row written inside the call.

_format_date

_format_date(v) -> Optional[str]

clock_first_date

clock_first_date(data_domain=None) -> Optional[str]

First date of the data domain's clock calendar as a valid-from text, or None (no domain, no clock, unreadable). Never raises.