Skip to content

Commit

Permalink
H-3082(I): Allow querying inheritance data from database (#5300)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Oct 7, 2024
1 parent ecbda58 commit c8242cd
Show file tree
Hide file tree
Showing 34 changed files with 369 additions and 292 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/hash-graph/libs/api/src/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use graph::{
};
use graph_types::{
ontology::{
DataTypeId, DataTypeMetadata, DataTypeWithMetadata, OntologyTemporalMetadata,
DataTypeMetadata, DataTypeWithMetadata, OntologyTemporalMetadata,
OntologyTypeClassificationMetadata, OntologyTypeMetadata, OntologyTypeReference,
ProvidedOntologyEditionProvenance,
},
Expand All @@ -50,7 +50,7 @@ use time::OffsetDateTime;
use type_system::{
schema::{
ConversionDefinition, ConversionExpression, ConversionValue, Conversions, DataType,
Operator, Variable,
DataTypeId, Operator, Variable,
},
url::{BaseUrl, OntologyTypeVersion, VersionedUrl},
};
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tarpc = { workspace = true, features = ["serde-transport", "serde-transport-json
time = { workspace = true }
tracing = { workspace = true }
utoipa = { workspace = true, features = ["uuid"], optional = true }
uuid = { workspace = true, features = ["v4", "v5", "serde"] }
uuid = { workspace = true, features = ["v4", "serde"] }

[dev-dependencies]
tokio = { workspace = true, features = ["macros"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE VIEW data_type_inherits_from_aggregation AS
SELECT
source_data_type_ontology_id,
array_agg(target_data_type_ontology_id) AS target_data_type_ontology_ids,
array_agg(depth) AS depths
FROM data_type_inherits_from
GROUP BY source_data_type_ontology_id;
4 changes: 2 additions & 2 deletions apps/hash-graph/libs/graph/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use graph_types::{
account::{AccountGroupId, AccountId},
knowledge::entity::{Entity, EntityId, EntityUuid},
ontology::{
DataTypeId, DataTypeWithMetadata, EntityTypeId, EntityTypeWithMetadata, PropertyTypeId,
DataTypeWithMetadata, EntityTypeId, EntityTypeWithMetadata, PropertyTypeId,
PropertyTypeWithMetadata,
},
owned_by_id::OwnedById,
Expand All @@ -51,7 +51,7 @@ use hash_status::StatusCode;
use postgres_types::ToSql;
use serde::{Deserialize, Serialize};
use tokio_postgres::error::SqlState;
use type_system::url::VersionedUrl;
use type_system::{schema::DataTypeId, url::VersionedUrl};

use crate::{
snapshot::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use authorization::{
AuthorizationApi, backend::ZanzibarBackend, schema::DataTypeRelationAndSubject,
};
use error_stack::{Result, ResultExt};
use graph_types::ontology::DataTypeId;
use tokio_postgres::GenericClient;
use type_system::schema::DataTypeId;

use crate::{
snapshot::WriteBatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use futures::{
channel::mpsc::{self, Receiver, Sender},
stream::{BoxStream, SelectAll, select_all},
};
use graph_types::ontology::DataTypeId;
use type_system::Valid;
use type_system::{Valid, schema::DataTypeId};

use crate::{
snapshot::{
Expand Down Expand Up @@ -61,7 +60,7 @@ impl Sink<DataTypeSnapshotRecord> for DataTypeSender {
mut self: Pin<&mut Self>,
data_type: DataTypeSnapshotRecord,
) -> Result<(), Self::Error> {
let ontology_id = DataTypeId::from_record_id(&data_type.metadata.record_id);
let ontology_id = DataTypeId::from_url(&data_type.schema.id);

self.metadata
.start_send_unpin(OntologyTypeMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use futures::{
channel::mpsc::{self, Receiver, Sender},
stream::{BoxStream, SelectAll, select_all},
};
use graph_types::ontology::{DataTypeId, PropertyTypeId};
use type_system::Valid;
use graph_types::ontology::PropertyTypeId;
use type_system::{Valid, schema::DataTypeId};

use crate::{
snapshot::{
Expand Down
3 changes: 2 additions & 1 deletion apps/hash-graph/libs/graph/src/snapshot/restore/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use futures::{
};
use graph_types::{
knowledge::entity::EntityUuid,
ontology::{DataTypeId, EntityTypeId, PropertyTypeId},
ontology::{EntityTypeId, PropertyTypeId},
};
use type_system::schema::DataTypeId;

use crate::{
snapshot::{
Expand Down
16 changes: 6 additions & 10 deletions apps/hash-graph/libs/graph/src/store/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use error_stack::{Report, Result, ResultExt};
use graph_types::{
account::{AccountGroupId, AccountId, EditionArchivedById},
ontology::{
DataTypeId, OntologyEditionProvenance, OntologyProvenance, OntologyTemporalMetadata,
OntologyEditionProvenance, OntologyProvenance, OntologyTemporalMetadata,
OntologyTypeClassificationMetadata, OntologyTypeRecordId,
},
owned_by_id::OwnedById,
Expand All @@ -44,8 +44,8 @@ use tokio_postgres::{GenericClient, error::SqlState};
use type_system::{
Valid,
schema::{
ClosedDataTypeMetadata, ClosedEntityType, Conversions, DataType, DataTypeReference,
EntityType, EntityTypeReference, PropertyType, PropertyTypeReference,
ClosedEntityType, Conversions, DataType, DataTypeId, DataTypeInheritanceData,
DataTypeReference, EntityType, EntityTypeReference, PropertyType, PropertyTypeReference,
},
url::{BaseUrl, OntologyTypeVersion, VersionedUrl},
};
Expand Down Expand Up @@ -459,9 +459,9 @@ where
pub async fn insert_data_type_references(
&self,
ontology_id: DataTypeId,
metadata: &ClosedDataTypeMetadata,
metadata: &DataTypeInheritanceData,
) -> Result<(), InsertionError> {
for (target, &depth) in &metadata.inheritance_depths {
for (target, depth) in &metadata.inheritance_depths {
self.as_client()
.query(
"
Expand All @@ -475,11 +475,7 @@ where
$3
);
",
&[
&ontology_id,
&DataTypeId::from_url(target),
&i32::try_from(depth).change_context(InsertionError)?,
],
&[&ontology_id, target, depth],
)
.await
.change_context(InsertionError)?;
Expand Down
Loading

0 comments on commit c8242cd

Please sign in to comment.