From bd4a3fbbb83ed6e1ac351f411a6782b9394e279d Mon Sep 17 00:00:00 2001 From: Dom Dwyer Date: Mon, 28 Aug 2023 12:20:07 +0200 Subject: [PATCH] refactor: impl Hash for NamespaceSchema Allow the NamespaceSchema to be hashed (including the underlying proto types it contains). --- data_types/src/columns.rs | 4 ++-- data_types/src/lib.rs | 4 ++-- data_types/src/partition_template.rs | 6 +++--- generated_types/build.rs | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/data_types/src/columns.rs b/data_types/src/columns.rs index 30005b6906..a56d70b47d 100644 --- a/data_types/src/columns.rs +++ b/data_types/src/columns.rs @@ -26,7 +26,7 @@ impl ColumnId { } /// Column definitions for a table indexed by their name -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub struct ColumnsByName(BTreeMap); impl From> for ColumnsByName { @@ -178,7 +178,7 @@ impl Column { } /// The column id and its type for a column -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct ColumnSchema { /// the column id pub id: ColumnId, diff --git a/data_types/src/lib.rs b/data_types/src/lib.rs index e002581ac7..79f7932742 100644 --- a/data_types/src/lib.rs +++ b/data_types/src/lib.rs @@ -318,7 +318,7 @@ impl From for NamespaceServiceProtecti /// Schema collection for a namespace. This is an in-memory object useful for a schema /// cache. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Hash)] pub struct NamespaceSchema { /// the namespace id pub id: NamespaceId, @@ -386,7 +386,7 @@ pub struct Table { } /// Column definitions for a table -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableSchema { /// the table id pub id: TableId, diff --git a/data_types/src/partition_template.rs b/data_types/src/partition_template.rs index cb786a7b15..e076d1388c 100644 --- a/data_types/src/partition_template.rs +++ b/data_types/src/partition_template.rs @@ -265,7 +265,7 @@ pub static PARTITION_BY_DAY_PROTO: Lazy> = Lazy::n /// /// Internally this type is [`None`] when no namespace-level override is /// specified, resulting in the default being used. -#[derive(Debug, PartialEq, Clone, Default, sqlx::Type)] +#[derive(Debug, PartialEq, Clone, Default, sqlx::Type, Hash)] #[sqlx(transparent, no_pg_array)] pub struct NamespacePartitionTemplateOverride(Option); @@ -292,7 +292,7 @@ impl TryFrom for NamespacePartitionTemplateOverride { } /// A partition template specified by a table record. -#[derive(Debug, PartialEq, Eq, Clone, Default, sqlx::Type)] +#[derive(Debug, PartialEq, Eq, Clone, Default, sqlx::Type, Hash)] #[sqlx(transparent, no_pg_array)] pub struct TablePartitionTemplateOverride(Option); @@ -389,7 +389,7 @@ mod serialization { use generated_types::influxdata::iox::partition_template::v1 as proto; use std::{fmt::Write, sync::Arc}; - #[derive(Debug, Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq, Hash)] pub struct Wrapper(Arc); impl Wrapper { diff --git a/generated_types/build.rs b/generated_types/build.rs index c82c35fae8..d3780b107e 100644 --- a/generated_types/build.rs +++ b/generated_types/build.rs @@ -96,7 +96,8 @@ fn generate_grpc_types(root: &Path) -> Result<()> { .extern_path(".google.protobuf", "::pbjson_types") .btree_map([ ".influxdata.iox.ingester.v1.IngesterQueryResponseMetadata.unpersisted_partitions", - ]); + ]) + .type_attribute(".influxdata.iox.partition_template", "#[derive(Hash)]"); let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin"); tonic_build::configure()