Deciding What Makes Records Equal

Record identity and attribute equality are domain choices. Two records can represent one entity while containing different versions of its fields.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
2 min
In this article4 chapters
  1. Separate key and snapshot
  2. Test deduplication rules
  3. Compare a stable entity with two observations of it
  4. Make equality agree with how the data will be used

Separate key and snapshot

A contact with ID 42 can change its displayed name. Comparing the two IDs answers whether the snapshots refer to the same contact. Comparing all recorded fields answers whether the snapshots are equal as values. See identity and equality for a related distinction at the object level.

Test deduplication rules

If two incoming contacts share a display name and have IDs 42 and 78, deduplicating by name merges distinct entities. A map keyed by the stable ID preserves each entry. A hashable key should encode exactly the fields that define identity for this operation.[1][2]

Compare a stable entity with two observations of it

An inventory record with ID 10 is initially named Blue Chair and later named Workshop Chair. Comparing ID answers whether both records describe the same item. Comparing ID, name, and count answers whether the snapshots have the same values. A deduplication procedure keyed by name might accidentally merge two different items called Workshop Chair. Stable collection identifiers let renaming occur while relationships continue to follow the original item.

Make equality agree with how the data will be used

A coordinate can be a value object with equality depending on its components. In contrast, an account's display fields can change without creating a new account. Before defining comparison and hashing, state which fields belong to the relationship being tested. See hashable values for why matching map keys must have compatible hashes.

In a test, use one item observed at two times and two different items observed with the same display fields. Predict which pairs should be treated as equal by identity, by snapshot, and by a chosen search grouping. Those cases give independent evidence if the record representation is changed later.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩
  2. Python Software Foundation, Python Language Reference: Expressions ↩