H-2963, H-3292: Allow storing of data type conversion definitions
🌟 What is the purpose of this PR?
Conversions are supposed to be stored in the database. A conversion currently is always required to be a canonical version. The format is similar to the syntax introduced in #4828:
type ConversionValue = Variable | { const: number; type: "number" } | ConversionExpression;
type Operator = "+" | "-" | "*" | "/";
type ConversionExpression = [Operator, ConversionValue, ConversionValue];
interface ConversionDefinition {
expression: ConversionExpression;
}
interface Conversions {
from: ConversionDefinition;
to: ConversionDefinition;
}
e.g.
{
from: {
expression: ["/", "self", { const: 1000, type: "number" }]
},
to: {
expression: ["*", "self", { const: 1000, type: "number" }]
},
}
🔍 What does this change?
- Define conversion format
- Add conversions to database when creating/inserting data types
- dump/restore conversions to/from snapshots
- It does not implement any logic around conversions when dealing with data types, this PR only stores the conversions.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
- [x] does not modify any publishable blocks or libraries, or modifications do not need publishing
📜 Does this require a change to the docs?
The changes in this PR:
- [x] are internal and do not require a docs change
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
- [x] do not affect the execution graph
Codecov Report
Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
Project coverage is 17.73%. Comparing base (
458cf6f) to head (69acfd9). Report is 13 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ...hash-api/src/graph/ontology/primitive/data-type.ts | 0.00% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #4927 +/- ##
==========================================
- Coverage 17.84% 17.73% -0.11%
==========================================
Files 491 503 +12
Lines 16409 16507 +98
Branches 2516 2538 +22
==========================================
Hits 2928 2928
- Misses 13443 13541 +98
Partials 38 38
| Flag | Coverage Δ | |
|---|---|---|
| apps.hash-ai-worker-ts | 1.40% <ø> (-0.03%) |
:arrow_down: |
| apps.hash-api | 1.18% <0.00%> (-0.01%) |
:arrow_down: |
| local.hash-backend-utils | 8.79% <ø> (ø) |
|
| local.hash-isomorphic-utils | 1.06% <ø> (ø) |
|
| local.hash-subgraph | 25.96% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Benchmark results
@rust/graph-benches – Integrations
representative_read_multiple_entities
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$50.4 \mathrm{ms} \pm 306 \mathrm{μs}\left({\color{lightgreen}-6.173 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$54.5 \mathrm{ms} \pm 297 \mathrm{μs}\left({\color{gray}-4.763 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$39.5 \mathrm{ms} \pm 199 \mathrm{μs}\left({\color{lightgreen}-6.355 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$46.3 \mathrm{ms} \pm 288 \mathrm{μs}\left({\color{lightgreen}-6.598 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$62.6 \mathrm{ms} \pm 293 \mathrm{μs}\left({\color{gray}-3.067 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$35.5 \mathrm{ms} \pm 173 \mathrm{μs}\left({\color{lightgreen}-6.155 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$89.0 \mathrm{ms} \pm 419 \mathrm{μs}\left({\color{gray}-2.027 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$93.5 \mathrm{ms} \pm 563 \mathrm{μs}\left({\color{gray}-2.896 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$74.5 \mathrm{ms} \pm 378 \mathrm{μs}\left({\color{gray}-3.993 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$84.9 \mathrm{ms} \pm 590 \mathrm{μs}\left({\color{gray}-4.640 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$101 \mathrm{ms} \pm 624 \mathrm{μs}\left({\color{gray}-4.210 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$38.0 \mathrm{ms} \pm 270 \mathrm{μs}\left({\color{gray}-3.377 \mathrm{\%}}\right) $$ | Flame Graph |
representative_read_entity
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 |
$$15.9 \mathrm{ms} \pm 167 \mathrm{μs}\left({\color{lightgreen}-38.392 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 |
$$16.2 \mathrm{ms} \pm 162 \mathrm{μs}\left({\color{lightgreen}-33.279 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 |
$$15.3 \mathrm{ms} \pm 199 \mathrm{μs}\left({\color{lightgreen}-40.620 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 |
$$16.4 \mathrm{ms} \pm 174 \mathrm{μs}\left({\color{lightgreen}-36.535 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 |
$$16.1 \mathrm{ms} \pm 194 \mathrm{μs}\left({\color{lightgreen}-37.461 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 |
$$15.6 \mathrm{ms} \pm 156 \mathrm{μs}\left({\color{lightgreen}-12.065 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 |
$$16.4 \mathrm{ms} \pm 185 \mathrm{μs}\left({\color{lightgreen}-6.863 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 |
$$16.0 \mathrm{ms} \pm 180 \mathrm{μs}\left({\color{gray}-2.878 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 |
$$15.0 \mathrm{ms} \pm 183 \mathrm{μs}\left({\color{lightgreen}-7.948 \mathrm{\%}}\right) $$ | Flame Graph |
scaling_read_entity_complete_one_depth
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 10 entities | $$31.2 \mathrm{ms} \pm 148 \mathrm{μs}\left({\color{lightgreen}-24.953 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 25 entities | $$70.3 \mathrm{ms} \pm 406 \mathrm{μs}\left({\color{gray}-1.393 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 50 entities | $$1.54 \mathrm{s} \pm 3.26 \mathrm{ms}\left({\color{red}464 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 5 entities | $$24.9 \mathrm{ms} \pm 87.4 \mathrm{μs}\left({\color{gray}2.10 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1 entities | $$19.9 \mathrm{ms} \pm 124 \mathrm{μs}\left({\color{gray}1.18 \mathrm{\%}}\right) $$ | Flame Graph |
scaling_read_entity_complete_zero_depth
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 10 entities | $$2.08 \mathrm{ms} \pm 8.93 \mathrm{μs}\left({\color{gray}0.079 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 25 entities | $$2.71 \mathrm{ms} \pm 88.6 \mathrm{μs}\left({\color{lightgreen}-13.601 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 50 entities | $$3.88 \mathrm{ms} \pm 20.4 \mathrm{μs}\left({\color{lightgreen}-6.119 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 5 entities | $$1.92 \mathrm{ms} \pm 9.80 \mathrm{μs}\left({\color{gray}-0.373 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1 entities | $$1.85 \mathrm{ms} \pm 11.0 \mathrm{μs}\left({\color{gray}-1.054 \mathrm{\%}}\right) $$ | Flame Graph |
representative_read_entity_type
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| get_entity_type_by_id | Account ID: d4e16033-c281-4cde-aa35-9085bf2e7579 |
$$1.40 \mathrm{ms} \pm 3.74 \mathrm{μs}\left({\color{gray}-2.573 \mathrm{\%}}\right) $$ | Flame Graph |
scaling_read_entity_linkless
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 10 entities | $$1.84 \mathrm{ms} \pm 5.34 \mathrm{μs}\left({\color{gray}-0.310 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 100 entities | $$1.99 \mathrm{ms} \pm 6.94 \mathrm{μs}\left({\color{gray}-0.604 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1000 entities | $$3.52 \mathrm{ms} \pm 14.8 \mathrm{μs}\left({\color{red}28.9 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 10000 entities | $$12.6 \mathrm{ms} \pm 145 \mathrm{μs}\left({\color{lightgreen}-5.018 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1 entities | $$1.81 \mathrm{ms} \pm 6.17 \mathrm{μs}\left({\color{gray}-1.885 \mathrm{\%}}\right) $$ | Flame Graph |