diff --git a/Cargo.lock b/Cargo.lock index 50ec6bb84e..a03d3d19d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12394,6 +12394,7 @@ dependencies = [ "futures", "humantime", "lazy_static", + "num_enum 0.7.3", "prometheus", "prost 0.13.5", "serde", diff --git a/src/store-api/Cargo.toml b/src/store-api/Cargo.toml index c6fce64e8c..92ef698c15 100644 --- a/src/store-api/Cargo.toml +++ b/src/store-api/Cargo.toml @@ -26,6 +26,7 @@ derive_builder.workspace = true futures.workspace = true humantime.workspace = true lazy_static.workspace = true +num_enum = "0.7" prometheus.workspace = true prost.workspace = true serde.workspace = true diff --git a/src/store-api/src/region_request.rs b/src/store-api/src/region_request.rs index 779e8ccefa..92c3c34ec1 100644 --- a/src/store-api/src/region_request.rs +++ b/src/store-api/src/region_request.rs @@ -36,6 +36,7 @@ use common_recordbatch::DfRecordBatch; use common_time::{TimeToLive, Timestamp}; use datatypes::prelude::ConcreteDataType; use datatypes::schema::{FulltextOptions, SkippingIndexOptions}; +use num_enum::TryFromPrimitive; use serde::{Deserialize, Serialize}; use snafu::{ensure, OptionExt, ResultExt}; use strum::{AsRefStr, IntoStaticStr}; @@ -56,7 +57,8 @@ use crate::path_utils::table_dir; use crate::storage::{ColumnId, RegionId, ScanRequest}; /// The type of path to generate. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, TryFromPrimitive)] +#[repr(u8)] pub enum PathType { /// A bare path - the original path of an engine. /// @@ -1958,4 +1960,23 @@ mod tests { }; kind.validate(&metadata).unwrap(); } + + #[test] + fn test_cast_path_type_to_primitive() { + assert_eq!(PathType::Bare as u8, 0); + assert_eq!(PathType::Data as u8, 1); + assert_eq!(PathType::Metadata as u8, 2); + assert_eq!( + PathType::try_from(PathType::Bare as u8).unwrap(), + PathType::Bare + ); + assert_eq!( + PathType::try_from(PathType::Data as u8).unwrap(), + PathType::Data + ); + assert_eq!( + PathType::try_from(PathType::Metadata as u8).unwrap(), + PathType::Metadata + ); + } }