refactor: impl Hash for NamespaceSchema

Allow the NamespaceSchema to be hashed (including the underlying proto
types it contains).
pull/24376/head
Dom Dwyer 2023-08-28 12:20:07 +02:00
parent fc694effda
commit bd4a3fbbb8
No known key found for this signature in database
GPG Key ID: E4C40DBD9157879A
4 changed files with 9 additions and 8 deletions

View File

@ -26,7 +26,7 @@ impl ColumnId {
} }
/// Column definitions for a table indexed by their name /// Column definitions for a table indexed by their name
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ColumnsByName(BTreeMap<String, ColumnSchema>); pub struct ColumnsByName(BTreeMap<String, ColumnSchema>);
impl From<BTreeMap<String, ColumnSchema>> for ColumnsByName { impl From<BTreeMap<String, ColumnSchema>> for ColumnsByName {
@ -178,7 +178,7 @@ impl Column {
} }
/// The column id and its type for a 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 { pub struct ColumnSchema {
/// the column id /// the column id
pub id: ColumnId, pub id: ColumnId,

View File

@ -318,7 +318,7 @@ impl From<namespace_proto::ServiceProtectionLimits> for NamespaceServiceProtecti
/// Schema collection for a namespace. This is an in-memory object useful for a schema /// Schema collection for a namespace. This is an in-memory object useful for a schema
/// cache. /// cache.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Hash)]
pub struct NamespaceSchema { pub struct NamespaceSchema {
/// the namespace id /// the namespace id
pub id: NamespaceId, pub id: NamespaceId,
@ -386,7 +386,7 @@ pub struct Table {
} }
/// Column definitions for a table /// Column definitions for a table
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TableSchema { pub struct TableSchema {
/// the table id /// the table id
pub id: TableId, pub id: TableId,

View File

@ -265,7 +265,7 @@ pub static PARTITION_BY_DAY_PROTO: Lazy<Arc<proto::PartitionTemplate>> = Lazy::n
/// ///
/// Internally this type is [`None`] when no namespace-level override is /// Internally this type is [`None`] when no namespace-level override is
/// specified, resulting in the default being used. /// 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)] #[sqlx(transparent, no_pg_array)]
pub struct NamespacePartitionTemplateOverride(Option<serialization::Wrapper>); pub struct NamespacePartitionTemplateOverride(Option<serialization::Wrapper>);
@ -292,7 +292,7 @@ impl TryFrom<proto::PartitionTemplate> for NamespacePartitionTemplateOverride {
} }
/// A partition template specified by a table record. /// 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)] #[sqlx(transparent, no_pg_array)]
pub struct TablePartitionTemplateOverride(Option<serialization::Wrapper>); pub struct TablePartitionTemplateOverride(Option<serialization::Wrapper>);
@ -389,7 +389,7 @@ mod serialization {
use generated_types::influxdata::iox::partition_template::v1 as proto; use generated_types::influxdata::iox::partition_template::v1 as proto;
use std::{fmt::Write, sync::Arc}; use std::{fmt::Write, sync::Arc};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Hash)]
pub struct Wrapper(Arc<proto::PartitionTemplate>); pub struct Wrapper(Arc<proto::PartitionTemplate>);
impl Wrapper { impl Wrapper {

View File

@ -96,7 +96,8 @@ fn generate_grpc_types(root: &Path) -> Result<()> {
.extern_path(".google.protobuf", "::pbjson_types") .extern_path(".google.protobuf", "::pbjson_types")
.btree_map([ .btree_map([
".influxdata.iox.ingester.v1.IngesterQueryResponseMetadata.unpersisted_partitions", ".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"); let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");
tonic_build::configure() tonic_build::configure()