graflo.hq.write_prepare¶
What a batch becomes before a backend sees it, without a connection.
Every write of a cast batch runs the same steps: derived fields are set, generated identities minted, documents with no identity value dropped, and logical names translated to the names the target stores. They read the schema and the target flavor only, so the upsert writer and any other writer of the same graph run them identically.
Attributes¶
CYPHER_FLAVORS = frozenset({DBType.NEO4J, DBType.MEMGRAPH, DBType.FALKORDB})
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
StoredEdges
¶
Bases: BaseModel
One concrete edge's rows as the target stores them.
Source code in graflo/hq/write_prepare.py
Attributes¶
collection_name
instance-attribute
¶
docs
instance-attribute
¶
match_keys_source
instance-attribute
¶
match_keys_target
instance-attribute
¶
merge_properties
instance-attribute
¶
relation_name
instance-attribute
¶
source_class
instance-attribute
¶
target_class
instance-attribute
¶
union_fields
instance-attribute
¶
StoredVertices
¶
Bases: BaseModel
One vertex type's documents as the target stores them.
Source code in graflo/hq/write_prepare.py
WriteContext
¶
Bases: BaseModel
The schema resolved for one target flavor, with its stored names.
Built from the flavor alone: no connection is opened.
Source code in graflo/hq/write_prepare.py
Attributes¶
db_aware
instance-attribute
¶
flavor
instance-attribute
¶
keys
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
class-attribute
instance-attribute
¶
named_schema
instance-attribute
¶
Methods:¶
for_flavor(schema, flavor)
classmethod
¶
Resolve schema for flavor, physical names filled in as DDL declares them.
Source code in graflo/hq/write_prepare.py
Functions:¶
default_and_preferred(ctx, vcol)
¶
The flavor's default key field and vcol's first identity field.
The default is _key on Arango and id elsewhere; a vertex without
identity fields is keyed on the default itself.
Source code in graflo/hq/write_prepare.py
derive_vertex_fields(ctx, vcol, data)
¶
Set vcol's derived fields on every document, overwriting a stated value.
Source code in graflo/hq/write_prepare.py
drop_unkeyed(ctx, vcol, data)
¶
The documents of data that carry at least one identity value.
A document with no key cannot be upserted: every backend would either invent one or fold the batch onto a single keyless vertex. It usually means the resource references the vertex rather than owning it.
Source code in graflo/hq/write_prepare.py
edge_union_fields(edge)
¶
mint_identities(ctx, vcol, data)
¶
Fill vcol's generated identity on data, by its identity mode.
hash vertices get their digest and assigned vertices a uuid4, each
only where no value is set (the cast normally sets both); blank vertices
get a random id. A natural identity is never invented: UUID-typed identity
fields are validated instead.
Raises:
| Type | Description |
|---|---|
ValueError
|
A UUID-typed identity value that is not a UUID. |
Source code in graflo/hq/write_prepare.py
mirror_default_identity(ctx, vcol, data)
¶
Set the flavor's default key field from vcol's identity.
On ArangoDB, _key is derived from the whole identity
(:func:graflo.db.arango.keys.vertex_key) in every identity mode and
replaces a value already there, because edges derive it the same way from
their endpoints. Elsewhere, a generated identity's first value is copied
into id, never over a value already there.
Source code in graflo/hq/write_prepare.py
prepare_vertices(ctx, vcol, data)
¶
Set derived fields and generated identities on data; return what can be written.
data is changed in place. Documents with none of their vertex's identity fields are left out of the result.
Source code in graflo/hq/write_prepare.py
project_edge_docs(ctx, docs, relation, runtime)
¶
docs of one concrete relation, and the relation name the target stores.
Cypher targets take the relationship type the profile names for the relation. TigerGraph keeps one edge type and, when configured, stores an extracted relation as an edge attribute.
Source code in graflo/hq/write_prepare.py
project_edges(ctx, edge, relation, docs)
¶
Rows of edge under the concrete relation, with everything a target needs, as stored.
Source code in graflo/hq/write_prepare.py
project_vertices(ctx, vcol, docs)
¶
docs of vcol, with the storage name, key and union fields, as stored.
Source code in graflo/hq/write_prepare.py
union_fields(ctx, vcol)
¶
Logical names of vcol's merge: union fields.