From 3014972202fc7652d49bd9c1dc0f23d32c4a750a Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Fri, 22 Aug 2025 17:22:55 +0800 Subject: [PATCH] chore: improve error message when there are more than one time index (#6796) * chore: improve error message when there are more than one time index Signed-off-by: Dennis Zhuang * chore: style Signed-off-by: Dennis Zhuang --------- Signed-off-by: Dennis Zhuang --- Cargo.lock | 1 + src/store-api/Cargo.toml | 1 + src/store-api/src/metadata.rs | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3df10fd42e..d363238d11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12376,6 +12376,7 @@ dependencies = [ "derive_builder 0.20.2", "futures", "humantime", + "itertools 0.14.0", "lazy_static", "num_enum 0.7.4", "prometheus", diff --git a/src/store-api/Cargo.toml b/src/store-api/Cargo.toml index 92ef698c15..748a36460d 100644 --- a/src/store-api/Cargo.toml +++ b/src/store-api/Cargo.toml @@ -25,6 +25,7 @@ datatypes.workspace = true derive_builder.workspace = true futures.workspace = true humantime.workspace = true +itertools.workspace = true lazy_static.workspace = true num_enum = "0.7" prometheus.workspace = true diff --git a/src/store-api/src/metadata.rs b/src/store-api/src/metadata.rs index bb842f0735..4f3f877bec 100644 --- a/src/store-api/src/metadata.rs +++ b/src/store-api/src/metadata.rs @@ -31,6 +31,7 @@ use datatypes::arrow; use datatypes::arrow::datatypes::FieldRef; use datatypes::schema::{ColumnSchema, FulltextOptions, Schema, SchemaRef}; use datatypes::types::TimestampType; +use itertools::Itertools; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize}; use snafu::{ensure, Location, OptionExt, ResultExt, Snafu}; @@ -406,15 +407,22 @@ impl RegionMetadata { } // Checks there is only one time index. - let num_time_index = self + let time_indexes = self .column_metadatas .iter() .filter(|col| col.semantic_type == SemanticType::Timestamp) - .count(); + .collect::>(); ensure!( - num_time_index == 1, + time_indexes.len() == 1, InvalidMetaSnafu { - reason: format!("expect only one time index, found {}", num_time_index), + reason: format!( + "expect only one time index, found {}: {}", + time_indexes.len(), + time_indexes + .iter() + .map(|c| &c.column_schema.name) + .join(", ") + ), } );