httk.store.backend.sql.provenance_edges¶
Store-scoped SQL scanning of StrongLink edges.
Run provenance edges (inputs/artifacts/outputs on
Run) are child fields whose element class is an edge record
carrying the string fields label, entry_type, and entry_id. Both the
database-backed StoreEntryProvider
and the durable StoredEntryFederation
serve these edges as OPTIMADE relationships in both directions. This module holds
the shared discovery and SQL scanning so both serve them identically, and so the
declaring family is always discovered from the store’s registered families (never
a hardcoded record class).
The forward view projects one run’s own edges. The reverse view is derived,
never stored: it filters alt_kind IS NULL (run alternatives are separate
lineages that must not emit reverse identifiers) and reduces each run lineage to
its latest main row, so a target entry names only the runs whose latest main
revision still references it.
Classes¶
One store-registered family whose backing declares StrongLink edge fields. |
Functions¶
|
Return the store's registered families whose backings declare StrongLink fields. |
|
Return the served (wire) entry-type name for an edge's internal target type. |
|
Return each run's own edges keyed by run sid, in field then row order. |
|
Return each run lineage's latest main row sid ( |
|
Return the correlated predicate selecting a run lineage's latest main row. |
|
Return the reverse edges pointing at each target id, keyed by target id. |
Module Contents¶
- class httk.store.backend.sql.provenance_edges.StrongLinkFamily¶
One store-registered family whose backing declares StrongLink edge fields.
- Parameters:
internal_type – The family’s internal (unprefixed) entry-type name.
wire_type – The family’s served (wire) entry-type name.
definition_id – The family’s entry-type definition IRI, whose prefix names the wire relationship keys.
backing – The concrete backing record class carrying the edge fields.
schema – The backing’s resolved storage schema.
markers – The backing’s StrongLink markers keyed by field name.
- httk.store.backend.sql.provenance_edges.strong_link_families(store)¶
Return the store’s registered families whose backings declare StrongLink fields.
- Parameters:
store (httk.store.backend.sql.store.SqlStore) – The SQL store whose configured families are inspected.
- Returns:
One
StrongLinkFamilyper StrongLink-declaring backing.- Return type:
- httk.store.backend.sql.provenance_edges.wire_type_for_internal(store, internal_type)¶
Return the served (wire) entry-type name for an edge’s internal target type.
Resolves via the target family’s served definition — the same
EntryTypeDefinition.served_form()source used elsewhere — so a target such asrecordsserves as_httk_recordswhile a standard name (or any unregistered target) passes through unchanged.- Parameters:
store (httk.store.backend.sql.store.SqlStore) – The SQL store whose configured families supply the mapping.
internal_type (str) – The edge’s internal (unprefixed) target entry-type name.
- Returns:
The served (wire) entry-type name, or
internal_typeunchanged.- Return type:
- httk.store.backend.sql.provenance_edges.forward_run_edges(connection, store, family, run_sids)¶
Return each run’s own edges keyed by run sid, in field then row order.
- Parameters:
connection (Any) – An open read connection to
store.store (httk.store.backend.sql.store.SqlStore) – The SQL store backing the run family.
family (StrongLinkFamily) – The StrongLink family whose edges are read.
run_sids (collections.abc.Collection[int]) – The run row sids to project edges for.
- Returns:
run sid -> [((internal_target_type, target_id, label), marker)].- Return type:
dict[int, list[tuple[tuple[str, str, str], httk.core.storage.StrongLink]]]
- httk.store.backend.sql.provenance_edges.latest_main_run_sids(connection, run_table)¶
Return each run lineage’s latest main row sid (
alt_kind IS NULL).
- httk.store.backend.sql.provenance_edges.latest_main_condition(run_table, run_alias)¶
Return the correlated predicate selecting a run lineage’s latest main row.
The SQL-predicate counterpart of
latest_main_run_sids()for use inside a correlatedEXISTS(e.g. reverse-relationship filtering):run_aliasis a main row (alt_kind IS NULL) and no newer main row of the same lineage exists. The same constraint the reverse serving path applies through a Python-side max-sid-per-lineage scan.- Parameters:
run_table (sqlalchemy.Table) – The run family’s parent table (used to alias the newer-row probe).
run_alias (sqlalchemy.FromClause) – The run parent alias being constrained inside the outer query.
- Returns:
The
alt_kind IS NULLand latest-of-lineage boolean predicate.- Return type:
sqlalchemy.ColumnElement[bool]
- httk.store.backend.sql.provenance_edges.reverse_run_edges(connection, store, family, target_type, target_ids)¶
Return the reverse edges pointing at each target id, keyed by target id.
Only a run lineage’s latest main row contributes (
alt_kind IS NULL, latest sid per lineage); an edge deduped across lineages still yields one reverse identifier per referencing lineage. Because the join back through the child tables has no index, this is a per-page scan of the run edges.- Parameters:
connection (Any) – An open read connection to
store.store (httk.store.backend.sql.store.SqlStore) – The SQL store backing the run family.
family (StrongLinkFamily) – The StrongLink family whose reverse edges are derived.
target_type (str) – The edge’s internal (unprefixed) target entry-type name to match.
target_ids (collections.abc.Sequence[str]) – The raw stored target ids to match.
- Returns:
target id -> [(run raw id, edge label, marker)], ordered per target by(run raw id, field/marker order, edge row order).- Return type:
dict[str, list[tuple[str, str, httk.core.storage.StrongLink]]]