graflo.hq.identify¶
Which entity a set of property values identifies, by the key contract alone.
:func:identify is the executable form of a vertex type's key contract
(:func:~graflo.architecture.schema.key_contract.key_contract). Given the values
a producer holds for one entity, it answers:
- A complete primary key identifies the entity, without a lookup. A derived key is digested only once every source field of a key set holds a value: graflo's flat digest accepts missing fields and would give the same entity a different key.
- Otherwise a complete secondary identity is looked up in the graph, in declaration order: exactly one entity identifies it, several make it ambiguous, none leaves it unmatched.
- Otherwise the values are incomplete, with the fields still missing.
It is stateless: it never writes, never mints a key, and knows nothing of
batches or of who owns a type. :func:identify_many answers the same for many
value sets of one type with one lookup per secondary identity.
Attributes¶
IdentifyOutcome = Literal['identified', 'ambiguous', 'unmatched', 'incomplete']
module-attribute
¶
Classes¶
Identity
¶
Bases: ConfigBaseModel
What a set of values identifies under a vertex type's key contract.
Source code in graflo/hq/identify.py
Attributes¶
alternate = Field(default=None, description='Secondary identity that identified it, or found several.')
class-attribute
instance-attribute
¶
alternates = Field(default=(), description='Names of the secondary identities the values complete.')
class-attribute
instance-attribute
¶
by = Field(default=None, description='``key``: a complete primary key. ``alternate``: a secondary identity found exactly one entity.')
class-attribute
instance-attribute
¶
found = Field(default=None, description='Whether the graph holds the entity, as far as the guard shows; ``None`` when nothing was read.')
class-attribute
instance-attribute
¶
identities = Field(default_factory=list, description='``ambiguous``: the entities the secondary identity found.')
class-attribute
instance-attribute
¶
identity = Field(default=None, description='Identity fields and values of the entity.')
class-attribute
instance-attribute
¶
missing = Field(default=(), description='Fields still needed for the nearest primary key.')
class-attribute
instance-attribute
¶
outcome = Field(description='``identified``: one entity, in ``identity``. ``ambiguous``: a secondary identity found several, in ``identities``. ``unmatched``: the secondary identities found nothing. ``incomplete``: no primary key is complete and nothing could be looked up; ``missing`` says what is needed.')
class-attribute
instance-attribute
¶
state = Field(description='What the values complete (``key_status``).')
class-attribute
instance-attribute
¶
vertex_type
instance-attribute
¶
Functions:¶
identify(schema, vertex_type, values, *, db=None, guard=None)
¶
Which entity of vertex_type the property values identify.
A complete primary key identifies without a lookup; with db, found
then says whether the graph holds the entity. Otherwise, with db, the
complete secondary identities are looked up in declaration order: the first
to find exactly one entity identifies it; failing that, several make it
ambiguous and none unmatched. Without db, values that complete
only a secondary identity are incomplete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Schema whose key contract decides. |
required |
vertex_type
|
str
|
Vertex type of the entity. |
required |
values
|
Mapping[str, Any]
|
Property values held for it; |
required |
db
|
Any | None
|
An open connection to read the graph through. |
None
|
guard
|
FilterExpression | None
|
A trusted read guard every read passes, so the entity is never one the guard hides. It applies only when vertex_type declares every field it names; other types are read unguarded. Refused by a backend without read guards. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
vertex_type is not in the schema. |
Source code in graflo/hq/identify.py
identify_many(schema, vertex_type, values, *, db=None, guard=None)
¶
:func:identify for each of values, all of type vertex_type.
The graph is read once for the primary keys and once per secondary identity, not once per value set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Schema whose key contract decides. |
required |
vertex_type
|
str
|
Vertex type of every value set. |
required |
values
|
Sequence[Mapping[str, Any]]
|
Property values, one mapping per entity. |
required |
db
|
Any | None
|
An open connection, as for :func: |
None
|
guard
|
FilterExpression | None
|
A trusted read guard, as for :func: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[Identity]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
vertex_type is not in the schema. |
Source code in graflo/hq/identify.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 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 | |