graflo.architecture.schema.key_contract¶
A vertex type's key contract, in terms any schema language can state.
A producer that only knows some properties of an entity -- an extractor reading
text, a partial record -- needs to know whether what it holds identifies the
entity. :func:key_contract states that for a :class:Vertex:
source |
graflo declaration | Primary key comes from |
|---|---|---|
stated |
identity |
the identity fields themselves |
derived |
hash_identity_properties, identity_funnel |
a digest of source fields |
minted |
assigned, blank |
the writer; never from the data |
keys are the field sets that make a complete primary key (one, or one per
funnel branch); alternates are the secondary identities, which find a
vertex but never create one. :func:key_status says which a set of values
completes.
Attributes¶
KeySource = Literal['stated', 'derived', 'minted']
module-attribute
¶
KeyState = Literal['primary', 'alternate', 'partial', 'none', 'keyless']
module-attribute
¶
Classes¶
KeyContract
¶
Bases: ConfigBaseModel
How a vertex type is identified.
Source code in graflo/architecture/schema/key_contract.py
Attributes¶
alternates = Field(default=(), description='Secondary identities: lookup keys, never upserted on.')
class-attribute
instance-attribute
¶
identity_fields = Field(description='Stored primary identity fields (``id`` for a derived key).')
class-attribute
instance-attribute
¶
key_fields
property
¶
Every field that takes part in a primary or alternate key.
keys = Field(default=(), description='Field sets that complete the primary key; empty when minted.')
class-attribute
instance-attribute
¶
source
instance-attribute
¶
vertex
instance-attribute
¶
KeySet
¶
Bases: ConfigBaseModel
Fields that identify a vertex when all of them hold a value.
Source code in graflo/architecture/schema/key_contract.py
KeyStatus
¶
Bases: ConfigBaseModel
What a set of values completes under a :class:KeyContract.
Source code in graflo/architecture/schema/key_contract.py
Attributes¶
alternates = Field(default=(), description='Complete secondary identities, in declaration order.')
class-attribute
instance-attribute
¶
key = Field(default=None, description='The complete primary key set.')
class-attribute
instance-attribute
¶
missing = Field(default=(), description='Fields still needed for the nearest primary key set.')
class-attribute
instance-attribute
¶
state = Field(description='``primary``: a key set is complete. ``alternate``: only a secondary identity is. ``partial``: some key fields hold values, no set is complete. ``none``: no key field holds a value. ``keyless``: the type takes no key from the data.')
class-attribute
instance-attribute
¶
Functions:¶
key_contract(vertex)
¶
The key contract of vertex.
Source code in graflo/architecture/schema/key_contract.py
key_status(contract, values)
¶
Which key of contract the non-empty values complete.
Source code in graflo/architecture/schema/key_contract.py
primary_identity(vertex, contract, values)
¶
The primary identity values complete, or None.
A derived key is digested only once a key set is complete: graflo's flat digest accepts some source fields missing, which would give a different key for the same entity.