graflo.link.resolve¶
Resolve partial records to entities, then write what is resolved.
:func:resolve_records identifies each record of a batch of
:class:~graflo.link.records.RecordGraph by keys only, without a model. Every
keyed decision is :func:~graflo.hq.identify.identify; this module adds the
batch around it:
- A complete primary key identifies the record. For a connector-owned type
(see :func:
~graflo.architecture.contract.ownership.connector_owned_types) the entity must already be in the graph; it is never created from a record. - A complete secondary identity looks the entity up: first among the batch's
identified records, repeated until nothing new resolves, then in the graph.
Exactly one entity resolves the record; several stage it as
ambiguous. - A type that takes no key from the data is minted when the record may create its entity and no secondary identity found it.
Every other record is staged with its reason, and a relation waits for its
staged endpoints. A partial key never identifies anything: nothing merges two
vertices later, so a guess would stay a duplicate. A relation between two
records whose identities turn out to be one entity is dropped, never written as
a self-loop (:func:dropped_relations).
:func:promote turns the resolution into a :class:GraphContainer, and
:func:write_record_graphs resolves against the target and writes it.
Attributes¶
Classes¶
Functions:¶
dropped_relations(resolution)
¶
The relations of resolution that are never written, in graph order.
A relation between two records states two entities; one whose records
resolved to the same entity (type and identity) is dropped as
same_entity. A relation from a record to itself is kept. Call it again
after changing resolution.resolved (a pick fixed by hand):
:func:promote drops such relations whatever resolution.dropped says.
Source code in graflo/link/resolve.py
promote(schema, resolution)
¶
The vertices and edges resolution identified, ready to write.
A resolved record becomes its stated properties plus its identity, fused
with other records of the same entity in order, later values winning. A
connector-owned or link-only entity is only an edge endpoint: a record
never writes onto it. A relation between two records resolved to one
entity is not emitted (:func:dropped_relations).
Source code in graflo/link/resolve.py
resolve_records(schema, graphs, *, db=None, owned=frozenset(), guard=None, writable=None)
¶
Identify the records of graphs by their keys, against db when given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Schema the graphs were read against. |
required |
graphs
|
Sequence[RecordGraph]
|
Record graphs, resolved together: a record may be found by another graph's record. |
required |
db
|
Any | None
|
An open connection to look secondary identities and connector-owned keys up in. Without one, only the batch is searched. |
None
|
owned
|
frozenset[str]
|
Connector-owned vertex types: linked, never created or written. |
frozenset()
|
guard
|
FilterExpression | None
|
A trusted read guard every lookup in db must pass, so a record
is never resolved to an entity the guard hides; refused by a backend
without read guards. A stated key of a type that is not
connector-owned is then checked against the graph as well: an entity
that exists but the guard hides stages the record as |
None
|
writable
|
Mapping[str, FilterExpression] | None
|
With a guard, the entities a write may change, one filter
per vertex type: an entity found in the graph that the guard shows
but its type's filter does not is resolved |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
A record names an unknown vertex type. |
Source code in graflo/link/resolve.py
191 192 193 194 195 196 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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
write_record_graphs(schema, graphs, conn_conf, *, owned=frozenset(), recreate_schema=False, stamp=None, guard=None, writable=None)
async
¶
Resolve graphs against the target, then write what resolved.
The schema is defined first, so lookups never meet a missing collection.
Staged records, held and dropped relations are returned, not written. stamp sets
the schema's reserved fields on what is written (write_container);
guard limits the lookups and writable what they may write onto
(:func:resolve_records).