graflo.db.cypher.rel_merge¶
Relationship MERGE map fragments for parallel edges (property-graph backends).
Functions:¶
partition_by_absent_merge_props(rows, prop_names, *, props_of, ends_of, union=())
¶
Group edge rows by the identity properties each one lacks.
prop_names are the properties the edge's identity names beside its
endpoints. Cypher refuses MERGE on a null property, so a row missing
one (absent or None) cannot use the property MERGE. As on
PostgreSQL (NULLS NOT DISTINCT), absence is part of the key: such a row
matches an existing edge lacking the same properties. Rows lacking some are
deduplicated on their endpoints and present merge values, later properties
winning, because :func:rel_absent_upsert_clause cannot see edges created
earlier in its own batch.
With union fields the complete group is deduplicated as well: one row per
edge carries the union of its rows' members, so no MERGE has to see a row
written earlier in its own batch.
Returns:
| Type | Description |
|---|---|
list[tuple[tuple[str, ...], list[Any]]]
|
|
Source code in graflo/db/cypher/rel_merge.py
rel_absent_upsert_clause(relation_name, prop_names, absent, *, props_expr, source='source', target='target', union=(), union_expr='row[3]')
¶
Upsert a relationship whose identity properties absent are missing.
Matches an existing relation_name edge between source and target
whose present identity properties equal the row's and whose absent ones are
unset, and updates it; creates one when none matches. Follows a MATCH
binding source, target and row. union fields are read from
union_expr and unioned with what the edge holds.
Source code in graflo/db/cypher/rel_merge.py
rel_merge_props_map_from_row_index(prop_names, *, row_index=2)
¶
Build `k`: row[n]['k'], ... for MERGE relationship properties.
Matches batches shaped as row = [source_doc, target_doc, props] (Neo4j,
FalkorDB-style row[2]).
Source code in graflo/db/cypher/rel_merge.py
rel_merge_props_map_from_row_props(prop_names, *, props_expr='row.props')
¶
Build `k`: row.props['k'], ... (Memgraph-style batch rows).
Source code in graflo/db/cypher/rel_merge.py
rel_union_rows(rows, union)
¶
[source, target, props] rows as [source, target, replaced, unioned].
The union fields move out of row[2] into row[3], so r += row[2]
can never overwrite a stored list (:func:rel_upsert_clause).
Source code in graflo/db/cypher/rel_merge.py
rel_upsert_clause(relation_name, prop_names, absent, *, union=(), props_expr='row[2]', union_expr='row[3]')
¶
Upsert one group of :func:partition_by_absent_merge_props rows.
MERGE on the endpoints (and prop_names when the group has them all),
or :func:rel_absent_upsert_clause when it lacks some. Follows a MATCH
binding source, target and row. union fields are read from
union_expr (:func:rel_union_rows) and written as the union of the
stored list and the row's.