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 <killme2008@gmail.com>

* chore: style

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
dennis zhuang
2025-08-22 17:22:55 +08:00
committed by GitHub
parent 6839b5aef4
commit 3014972202
3 changed files with 14 additions and 4 deletions

1
Cargo.lock generated
View File

@@ -12376,6 +12376,7 @@ dependencies = [
"derive_builder 0.20.2",
"futures",
"humantime",
"itertools 0.14.0",
"lazy_static",
"num_enum 0.7.4",
"prometheus",

View File

@@ -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

View File

@@ -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::<Vec<_>>();
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(", ")
),
}
);