diff --git a/src/datatypes/src/error.rs b/src/datatypes/src/error.rs index 745268f6e35..9c29853ddcd 100644 --- a/src/datatypes/src/error.rs +++ b/src/datatypes/src/error.rs @@ -335,6 +335,13 @@ pub enum Error { location: Location, }, + #[snafu(display("Invalid series: {reason}"))] + InvalidSeries { + reason: String, + #[snafu(implicit)] + location: Location, + }, + #[snafu(display("unexpected: {reason}"))] Unexpected { reason: String, @@ -368,7 +375,8 @@ impl ErrorExt for Error { | InvalidVector { .. } | InvalidFulltextOption { .. } | InvalidSkippingIndexOption { .. } - | InvalidCompressionOption { .. } => StatusCode::InvalidArguments, + | InvalidCompressionOption { .. } + | InvalidSeries { .. } => StatusCode::InvalidArguments, ValueExceedsPrecision { .. } | CastType { .. } diff --git a/src/datatypes/src/lib.rs b/src/datatypes/src/lib.rs index 0dcce168571..fee2ab7f819 100644 --- a/src/datatypes/src/lib.rs +++ b/src/datatypes/src/lib.rs @@ -24,6 +24,7 @@ pub mod prelude; pub mod scalars; pub mod schema; pub mod serialize; +pub mod series; pub mod time; pub mod timestamp; pub mod type_id; diff --git a/src/datatypes/src/series.rs b/src/datatypes/src/series.rs new file mode 100644 index 00000000000..24152366d47 --- /dev/null +++ b/src/datatypes/src/series.rs @@ -0,0 +1,162 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod histogram; +pub mod time; + +#[cfg(test)] +#[path = "series/tests.rs"] +mod tests; + +use std::sync::Arc; + +use crate::error::{InvalidSeriesSnafu, Result}; + +/// A label with shared UTF-8 name and value strings. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Label { + /// Label name. + pub name: Arc, + /// Label value. + pub value: Arc, +} + +/// A metric name and its name-sorted ordinary labels. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct MetricName { + name: Option>, + tags: Arc<[Label]>, +} + +impl MetricName { + /// Creates a metric name, sorting labels and rejecting duplicates or `__name__` tags. + pub fn try_new(name: Option>, mut tags: Vec