From 410759ed5ac38725ab441e34c907923c75026264 Mon Sep 17 00:00:00 2001 From: discord9 <55937128+discord9@users.noreply.github.com> Date: Sat, 17 Oct 2026 10:35:06 +0800 Subject: [PATCH 01/57] feat(mito-codec): decode scan-bound primary key labels Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --- src/mito-codec/src/labels.rs | 264 ++++++++ src/mito-codec/src/labels/tests.rs | 603 ++++++++++++++++++ src/mito-codec/src/lib.rs | 1 + .../src/row_converter/sparse/checked.rs | 191 +++++- 4 files changed, 1046 insertions(+), 13 deletions(-) create mode 100644 src/mito-codec/src/labels.rs create mode 100644 src/mito-codec/src/labels/tests.rs diff --git a/src/mito-codec/src/labels.rs b/src/mito-codec/src/labels.rs new file mode 100644 index 00000000000..fe4e3bfbde0 --- /dev/null +++ b/src/mito-codec/src/labels.rs @@ -0,0 +1,264 @@ +// 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. + +use std::collections::HashSet; +use std::sync::Arc; + +use api::v1::SemanticType; +use common_telemetry::debug; +use datatypes::series::{Label, MetricName}; +use datatypes::value::Value; +use snafu::OptionExt; +use store_api::codec::PrimaryKeyEncoding; +use store_api::metadata::RegionMetadataRef; +use store_api::metric_engine_consts::is_metric_engine_internal_column; +use store_api::region_engine::RawLabelSource; +use store_api::storage::{ + ColumnId, + consts::{ReservedColumnId, is_internal_column}, +}; + +use crate::error::{ + InvalidDensePrimaryKeySnafu, InvalidSparsePrimaryKeySnafu, Result, UnsupportedOperationSnafu, +}; +use crate::row_converter::dense::DensePrimaryKeyCodec; +use crate::row_converter::sparse::{SparseOffsetsCache, SparsePrimaryKeyView}; + +/// Selects labels materialized from a primary key. +/// +/// `All` produces a complete metric name and label set. `Only` produces a projected +/// label vector, including `__name__` only when explicitly requested. Unexplained sparse +/// column IDs are errors with `All`; `Only` skips them after checking their framing. +#[derive(Clone, Debug, Default)] +pub enum LabelProjection { + #[default] + All, + Only(Arc<[Arc]>), +} + +/// Decoded labels: either a complete metric name or a possibly partial label vector. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum DecodedLabels { + Complete(MetricName), + Projected(Vec