Skip to content

Commit

Permalink
Expose ontology transaction time to the graph (#2256)
Browse files Browse the repository at this point in the history
* Expose ontology transaction time to the graph

* Apply suggestions from code review

Co-authored-by: Alfred Mountfield <am@hash.ai>

---------

Co-authored-by: Alfred Mountfield <am@hash.ai>
  • Loading branch information
TimDiekmann and Alfred Mountfield authored Mar 22, 2023
1 parent 2b33c7e commit 57d3933
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/hash-graph/lib/graph/src/ontology/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ pub enum DataTypeQueryPath<'p> {
/// [`VersionedUrl`]: type_system::url::VersionedUrl
/// [`DataType`]: type_system::DataType
VersionedUrl,
/// The transaction time of the [`DataType`].
///
/// It's not possible to query for the temporal axis directly, this has to be done via the
/// `temporalAxes` parameter on [`StructuralQuery`]. The transaction time is currently not part
/// of the [`OntologyElementMetadata`].
///
/// [`DataType`]: type_system::DataType
/// [`OntologyElementMetadata`]: crate::ontology::OntologyElementMetadata
/// [`StructuralQuery`]: crate::subgraph::query::StructuralQuery
TransactionTime,
/// The [`OwnedById`] of the [`OntologyElementMetadata`] belonging to the [`DataType`].
///
/// ```rust
Expand Down Expand Up @@ -189,6 +199,10 @@ impl OntologyQueryPath for DataTypeQueryPath<'_> {
Self::Version
}

fn transaction_time() -> Self {
Self::TransactionTime
}

fn updated_by_id() -> Self {
Self::UpdatedById
}
Expand All @@ -209,6 +223,7 @@ impl QueryPath for DataTypeQueryPath<'_> {
Self::Schema(_) | Self::AdditionalMetadata(_) => ParameterType::Any,
Self::BaseUrl => ParameterType::BaseUrl,
Self::VersionedUrl => ParameterType::VersionedUrl,
Self::TransactionTime => ParameterType::TimeInterval,
Self::Version => ParameterType::OntologyTypeVersion,
Self::Description | Self::Title | Self::Type => ParameterType::Text,
Self::PropertyTypeEdge { path, .. } => path.expected_type(),
Expand All @@ -223,6 +238,7 @@ impl fmt::Display for DataTypeQueryPath<'_> {
Self::BaseUrl => fmt.write_str("baseUrl"),
Self::Version => fmt.write_str("version"),
Self::VersionedUrl => fmt.write_str("versionedUrl"),
Self::TransactionTime => fmt.write_str("transactionTime"),
Self::OwnedById => fmt.write_str("ownedById"),
Self::UpdatedById => fmt.write_str("updatedById"),
Self::Schema(Some(path)) => write!(fmt, "schema.{path}"),
Expand Down
16 changes: 16 additions & 0 deletions apps/hash-graph/lib/graph/src/ontology/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ pub enum EntityTypeQueryPath<'p> {
/// [`EntityType`]: type_system::EntityType
/// [`VersionedUrl`]: type_system::url::VersionedUrl
VersionedUrl,
/// The transaction time of the [`EntityType`].
///
/// It's not possible to query for the temporal axis directly, this has to be done via the
/// `temporalAxes` parameter on [`StructuralQuery`]. The transaction time is currently not part
/// of the [`OntologyElementMetadata`].
///
/// [`EntityType`]: type_system::EntityType
/// [`OntologyElementMetadata`]: crate::ontology::OntologyElementMetadata
/// [`StructuralQuery`]: crate::subgraph::query::StructuralQuery
TransactionTime,
/// The [`OwnedById`] of the [`OntologyElementMetadata`] belonging to the [`EntityType`].
///
/// ```rust
Expand Down Expand Up @@ -306,6 +316,10 @@ impl OntologyQueryPath for EntityTypeQueryPath<'_> {
Self::Version
}

fn transaction_time() -> Self {
Self::TransactionTime
}

fn updated_by_id() -> Self {
Self::UpdatedById
}
Expand All @@ -329,6 +343,7 @@ impl QueryPath for EntityTypeQueryPath<'_> {
Self::BaseUrl => ParameterType::BaseUrl,
Self::VersionedUrl => ParameterType::VersionedUrl,
Self::Version => ParameterType::OntologyTypeVersion,
Self::TransactionTime => ParameterType::TimeInterval,
Self::Title | Self::Description => ParameterType::Text,
Self::PropertyTypeEdge { path, .. } => path.expected_type(),
Self::EntityTypeEdge { path, .. } => path.expected_type(),
Expand All @@ -344,6 +359,7 @@ impl fmt::Display for EntityTypeQueryPath<'_> {
Self::BaseUrl => fmt.write_str("baseUrl"),
Self::Version => fmt.write_str("version"),
Self::VersionedUrl => fmt.write_str("versionedUrl"),
Self::TransactionTime => fmt.write_str("transactionTime"),
Self::OwnedById => fmt.write_str("ownedById"),
Self::UpdatedById => fmt.write_str("updatedById"),
Self::Schema(Some(path)) => write!(fmt, "schema.{path}"),
Expand Down
16 changes: 16 additions & 0 deletions apps/hash-graph/lib/graph/src/ontology/property_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ pub enum PropertyTypeQueryPath<'p> {
/// [`PropertyType`]: type_system::PropertyType
/// [`VersionedUrl`]: type_system::url::VersionedUrl
VersionedUrl,
/// The transaction time of the [`PropertyType`].
///
/// It's not possible to query for the temporal axis directly, this has to be done via the
/// `temporalAxes` parameter on [`StructuralQuery`]. The transaction time is currently not part
/// of the [`OntologyElementMetadata`].
///
/// [`PropertyType`]: type_system::PropertyType
/// [`OntologyElementMetadata`]: crate::ontology::OntologyElementMetadata
/// [`StructuralQuery`]: crate::subgraph::query::StructuralQuery
TransactionTime,
/// The [`OwnedById`] of the [`OntologyElementMetadata`] belonging to the [`PropertyType`].
///
/// ```rust
Expand Down Expand Up @@ -228,6 +238,10 @@ impl OntologyQueryPath for PropertyTypeQueryPath<'_> {
Self::Version
}

fn transaction_time() -> Self {
Self::TransactionTime
}

fn updated_by_id() -> Self {
Self::UpdatedById
}
Expand All @@ -249,6 +263,7 @@ impl QueryPath for PropertyTypeQueryPath<'_> {
Self::BaseUrl => ParameterType::BaseUrl,
Self::VersionedUrl => ParameterType::VersionedUrl,
Self::Version => ParameterType::OntologyTypeVersion,
Self::TransactionTime => ParameterType::TimeInterval,
Self::Title | Self::Description => ParameterType::Text,
Self::DataTypeEdge { path, .. } => path.expected_type(),
Self::PropertyTypeEdge { path, .. } => path.expected_type(),
Expand All @@ -264,6 +279,7 @@ impl fmt::Display for PropertyTypeQueryPath<'_> {
Self::BaseUrl => fmt.write_str("baseUrl"),
Self::Version => fmt.write_str("version"),
Self::VersionedUrl => fmt.write_str("versionedUrl"),
Self::TransactionTime => fmt.write_str("transactionTime"),
Self::OwnedById => fmt.write_str("ownedById"),
Self::UpdatedById => fmt.write_str("updatedById"),
Self::Schema(Some(path)) => write!(fmt, "schema.{path}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl PostgresQueryPath for DataTypeQueryPath<'_> {
| Self::Schema(_) => vec![],
Self::BaseUrl
| Self::Version
| Self::TransactionTime
| Self::UpdatedById
| Self::OwnedById
| Self::AdditionalMetadata(_) => {
Expand All @@ -48,6 +49,7 @@ impl PostgresQueryPath for DataTypeQueryPath<'_> {
match self {
Self::BaseUrl => Column::OntologyIds(OntologyIds::BaseUrl),
Self::Version => Column::OntologyIds(OntologyIds::Version),
Self::TransactionTime => Column::OntologyIds(OntologyIds::TransactionTime),
Self::OwnedById => Column::OntologyIds(OntologyIds::AdditionalMetadata(Some(
JsonField::StaticText("owned_by_id"),
))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl PostgresQueryPath for EntityTypeQueryPath<'_> {
match self {
Self::BaseUrl => Column::OntologyIds(OntologyIds::BaseUrl),
Self::Version => Column::OntologyIds(OntologyIds::Version),
Self::TransactionTime => Column::OntologyIds(OntologyIds::TransactionTime),
Self::OwnedById => Column::OntologyIds(OntologyIds::AdditionalMetadata(Some(
JsonField::StaticText("owned_by_id"),
))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl PostgresQueryPath for PropertyTypeQueryPath<'_> {
match self {
Self::BaseUrl => Column::OntologyIds(OntologyIds::BaseUrl),
Self::Version => Column::OntologyIds(OntologyIds::Version),
Self::TransactionTime => Column::OntologyIds(OntologyIds::TransactionTime),
Self::OwnedById => Column::OntologyIds(OntologyIds::AdditionalMetadata(Some(
JsonField::StaticText("owned_by_id"),
))),
Expand Down
2 changes: 2 additions & 0 deletions apps/hash-graph/lib/graph/src/store/postgres/query/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub enum OntologyIds<'p> {
Version,
UpdatedById,
LatestVersion,
TransactionTime,
AdditionalMetadata(Option<JsonField<'p>>),
}

Expand Down Expand Up @@ -268,6 +269,7 @@ impl OntologyIds<'_> {
let column = match self {
Self::OntologyId => "ontology_id",
Self::BaseUrl => "base_url",
Self::TransactionTime => "transaction_time",
Self::Version => "version",
Self::LatestVersion => "latest_version",
Self::UpdatedById => "record_created_by_id",
Expand Down
3 changes: 3 additions & 0 deletions apps/hash-graph/lib/graph/src/store/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub trait OntologyQueryPath {
/// [`OntologyTypeVersion`]: crate::identifier::ontology::OntologyTypeVersion
fn version() -> Self;

/// Returns the path identifying the transaction time.
fn transaction_time() -> Self;

/// Returns the path identifying the [`UpdatedById`].
///
/// [`UpdatedById`]: crate::provenance::UpdatedById
Expand Down

0 comments on commit 57d3933

Please sign in to comment.