graflo.architecture.evolution.rewrite¶
Structured rewrite of vertex names in pipeline dicts and related resource fields.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Functions:¶
cast_step(x)
¶
close_routers_in_pipeline(pipeline, vocabulary, *, declared_properties=None, pass_through=None)
¶
pipeline with every open router closed over vocabulary.
An open router passes a value missing from its type_map through as the
class name. Closing it lists each class of vocabulary the table does not
already key -- as itself -- and sets type_map_only, so it routes
exactly what it routed when vocabulary was the whole schema. A router
with vertex_types gets entries only for the classes it lists. Entries
already there, authored or written by a rename, are kept. Steps keep their
authored spelling, at every level.
A class the router reached only by pass-through took the part of the
router-level from it declares; a listed class must declare all of it.
Given declared_properties (property names per class), every class such
a value routes to after closing that lacks a target gets that declared
part as its vertex_from_map entry, so closing never refuses a
projection the open router accepted. pass_through names those values
when the table was rewritten since (see :func:pass_through_classes);
by default they are the values closing itself lists.
Source code in graflo/architecture/evolution/rewrite.py
collect_endpoint_selectors(pipeline)
¶
(vertex_name, selector) for every use of a secondary identity.
Each edge endpoint matched on one, and each class a vertex step or a
router finds by one (find). Endpoints resolving through the primary
identity are omitted — they carry no dependency on a named secondary
identity.
Source code in graflo/architecture/evolution/rewrite.py
edge_payloads(step)
¶
The edge payloads step carries, as mutable references into it.
An edge step is spelled three ways: nested under edge or
create_edge, or flat, with the endpoints on the step itself
({source, target} / {from, to}, or type: edge). A walker that
only looks under the two keys silently skips every flat step -- the form
most hand-written pipelines use.
Source code in graflo/architecture/evolution/rewrite.py
evolve_router(payload, classes, *, declared=None)
¶
The routers that replace a router once an op maps its classes by classes.
classes maps an old class to its new name, or to None when the op
removes it; a class it does not name is unchanged. declared is the
schema's classes before the op. Every discriminator value must route as
before, to its class renamed (or nowhere, if it was removed): the table's
values and vertex_types are renamed, and a pass-through router gains
{old: new} for each renamed class it reaches. A value that named no
class may come to route to a new name -- as an open router always routes
a declared name -- but only when the router reached every class renamed
onto it.
Where those fields cannot say that -- a vertex_types router reaching
one class of a merge and not another, or a removed table entry whose key
names a class -- the router is closed instead: type_map_only over
exactly the values it accepted, then renamed.
A merge of classes the router projects differently -- each its own
vertex_from_map entry, or the shared from -- cannot keep one
projection per class: the router is split into closed routers on the same
type_field and role, one per projection, each keyed by the values
that reached its classes. The values stay disjoint, so no row is routed
twice. Without declared the router's reach is unknown; it is neither
closed nor split, and colliding projections are unioned.
Without declared, a new name is taken to be new to the schema and every other name to be declared.
Returns the replacing payloads: one as a rule, none when the router routes nothing any more, several when it was split.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a merge joins a class the router only looks up with one it writes; one class cannot be both. |
Source code in graflo/architecture/evolution/rewrite.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
mark_find_in_pipeline(pipeline, vertex, selector)
¶
pipeline with every production of vertex found by selector.
A vertex step for it gains find: <selector>; a vertex_router
whose :func:router_reach includes it gains {vertex: selector} in its
find map, its other classes untouched. lookup_only is left as is:
a step that wrote the class now attaches to the node it finds, one that
only referenced it now references it by selector. Steps keep their
authored spelling, at every level.
Source code in graflo/architecture/evolution/rewrite.py
mark_lookup_only_in_pipeline(pipeline, vertex)
¶
pipeline with every production of vertex turned into a lookup.
A vertex step for it gains lookup_only: true. An open
vertex_router routes an unmapped value as the class name, so it can
produce vertex unless its vertex_types leaves it out, and a closed
one (type_map_only) can when its table routes to it -- its
:func:router_reach: such a router gains vertex in its lookup_only list,
and the other classes it routes to are still written. Steps keep their
authored spelling, at every level.
Source code in graflo/architecture/evolution/rewrite.py
pass_through_classes(pipeline, vocabulary)
¶
Classes of vocabulary the routers of pipeline reach only by pass-through.
Empty unless some router is open and unbounded. A class any router names
-- a table target, or a vertex_types entry -- is excluded: the router
already checked its from against that class at load.
Source code in graflo/architecture/evolution/rewrite.py
pipeline_mentions_any_vertex(steps, names)
¶
Return True if any pipeline step references a vertex name in names.
Source code in graflo/architecture/evolution/rewrite.py
rename_endpoint_selector_classes(payload, vertex_name)
¶
Rename the classes of payload's per-class source_match / target_match.
Source code in graflo/architecture/evolution/rewrite.py
renamed_lookup_classes(value, vertex_name)
¶
A router's lookup_only list with its classes renamed (merges deduplicated).
Source code in graflo/architecture/evolution/rewrite.py
rewrite_edge_endpoints_in_pipeline(pipeline, mapping)
¶
Repoint edge steps whose EdgeId appears in mapping at new endpoints.
Keyed on the full (source, target, relation) triple rather than on vertex
names, so an edge step between the same pair of types under a different relation
is left alone.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_edge_properties_in_pipeline(pipeline, *, renames_by_relation=None, removals_by_relation=None, renames_by_edge=None, removals_by_edge=None)
¶
Rewrite edge actor properties declarations by relation or by triple.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_endpoint_selectors_in_pipeline(pipeline, selectors)
¶
Pin primary-identity edge endpoints of selectors keys to a secondary identity.
selectors maps a vertex name to the secondary identity name its endpoints
should select. Used by ReplaceIdentityOp with endpoints: pin_to_retired so
edge steps keep matching on the identity that was just retired, and by merge
for a resource that references a re-keyed member. An endpoint a router role
fills is pinned per class ({Class: selector}).
Source code in graflo/architecture/evolution/rewrite.py
rewrite_entity_names_in_pipeline(step, *, vertices=None, edges=None, declared=None)
¶
Mutate a pipeline payload in place to rename vertices/relations.
declared is the schema's classes before the rename; a router is evolved
by :func:evolve_router against it.
Source code in graflo/architecture/evolution/rewrite.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
rewrite_extra_weights_vertex_field_names(entries, renames_by_vertex)
¶
Rewrite extra_weights[*].vertex_weights for vertex field renames.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_remove_edge_ids_in_pipeline(pipeline, removed_edge_ids)
¶
Drop edge/create_edge steps (and links) targeting removed edge triples.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_remove_relations_in_pipeline(pipeline, removed_relations)
¶
Drop edge/create_edge steps (and links) targeting removed relations.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_remove_vertex_properties_in_pipeline(pipeline, removals, *, declared=None)
¶
Remove references to dropped vertex fields from pipeline steps.
A router stops mapping them for each class it reaches -- declared is the
schema's classes, the ones an unbounded router reaches -- in that class's
own vertex_from_map entry, so the classes sharing its from keep it.
Source code in graflo/architecture/evolution/rewrite.py
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | |
rewrite_remove_vertices_in_pipeline(pipeline, removed, *, declared=None)
¶
Trim pipeline to what survives removing the classes in removed.
Step-wise, never resource-wise. A vertex or edge step naming a
removed class goes. A vertex_router is evolved by
:func:evolve_router against declared (the schema's classes before the
removal): it loses its entries for the class and keeps routing the rest,
and a router left routing nothing goes. The class also leaves the
per-class selectors of the edge steps that survive. An edge step
addressing a role that no step fills any more goes too. A descend
stays while anything survives under it; transforms are left as authored.
Untouched steps keep their authored spelling; a trimmed router is edited
in place, and a descend that lost a step comes back normalized.
Source code in graflo/architecture/evolution/rewrite.py
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 | |
rewrite_vertex_field_names_in_pipeline(pipeline, renames, *, available_vertices=None, declared=None)
¶
Rewrite vertex field names across a resource pipeline.
Walks the dict pipeline (no runtime tree mutation):
vertexsteps: ensurefrom:covers the rename. Existing{old_field: doc_col}becomes{new_field: doc_col}; missing entries are injected as{new_field: old_field}so the doc can still address the property by its original name.transformsteps withrename: rewrite values that pointed at renamed vertex fields.callsteps are unchanged.edgesteps: rewritevertex_weightsfield/map/filter keys perWeight.name.vertex_routersteps: the samefromrewrite, per class the router reaches, in that class'svertex_from_mapentry.descendsteps: recurse with an extendedavailable_verticesset.
available_vertices is the set of vertex names visible from the parent
scope. Vertex names introduced at the current level are added automatically.
declared is the schema's classes: the ones an unbounded router reaches.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_vertex_names_in_pipeline(pipeline, mapping, *, declared=None)
¶
Rewrite all steps in a resource pipeline (see :func:rewrite_vertex_names_in_step).
Source code in graflo/architecture/evolution/rewrite.py
rewrite_vertex_names_in_step(step, mapping, *, declared=None)
¶
Return a deep-copied step with vertex names rewritten per mapping.
declared is the schema's classes before the rewrite; a router is evolved
by :func:evolve_router against it.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the rewrite splits a router into several steps; use
:func: |
Source code in graflo/architecture/evolution/rewrite.py
rewrite_vertex_names_in_value(obj, mapping)
¶
Deep-rewrite obj (pipelines, infer specs, extra_weights, nested dicts).
Source code in graflo/architecture/evolution/rewrite.py
rewrite_vertex_weight_names(payload, vertex_name)
¶
Rewrite vertex_weights[].name in place.
Weight.name on an edge step is a vertex name — it selects which endpoint's
observation columns the weight reads — and collect_vertex_names_from_pipeline
counts it as a vertex reference. Missing it leaves a pipeline pointing at a type
the schema no longer has.
Source code in graflo/architecture/evolution/rewrite.py
rewrite_vertex_weights_vertex_field_names(weights, renames_by_vertex)
¶
Rewrite :class:~graflo.architecture.graph_types.Weight references to vertex fields.
Each weight's name selects the logical vertex whose renames_by_vertex[name]
map applies (old field name -> new field name). filter and map keys
name vertex fields and follow the rename.
The edge attribute a weight writes does not follow it: that name belongs
to the edge, and renaming it is rename_edge_properties' job. A renamed
entry of fields -- whose attribute name is the vertex field's name -- is
therefore moved to map as {new_field: old_attribute} -- unless map
already uses that key, in which case it cannot name a second attribute and the
fields entry is renamed instead (with a warning).
Source code in graflo/architecture/evolution/rewrite.py
router_payload(step)
¶
The dict holding step's router fields, or None for another step.
Nested under vertex_router in the shorthand spelling, the step itself
in the flat one; editing it keeps the authored spelling.