fix: honor default prefix for all metric columns (#8640)

* fix: honor default prefix for metric columns

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* fix: cr issue

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

---------

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
shuiyisong
2026-07-27 07:35:28 +00:00
committed by GitHub
parent f5f5d468bb
commit b462d5d19e
19 changed files with 189 additions and 136 deletions
+2 -2
View File
@@ -106,8 +106,8 @@ pub fn native_histogram_value_type() -> &'static ConcreteDataType {
&NATIVE_HISTOGRAM_VALUE_TYPE
}
pub fn is_native_histogram_value_schema(name: &str, data_type: &ConcreteDataType) -> bool {
name == NATIVE_HISTOGRAM_FIELD && data_type == native_histogram_value_type()
pub fn is_native_histogram_value_type(data_type: &ConcreteDataType) -> bool {
data_type == native_histogram_value_type()
}
// ---------------------------------------------------------------------------
+20
View File
@@ -19,6 +19,7 @@ use snafu::ensure;
pub use crate::columnar_value::ColumnarValue;
use crate::error::{InvalidColumnPrefixSnafu, Result};
use crate::native_histogram::NATIVE_HISTOGRAM_FIELD;
/// Default time index column name.
static GREPTIME_TIMESTAMP_CELL: OnceCell<String> = OnceCell::new();
@@ -26,6 +27,9 @@ static GREPTIME_TIMESTAMP_CELL: OnceCell<String> = OnceCell::new();
/// Default value column name.
static GREPTIME_VALUE_CELL: OnceCell<String> = OnceCell::new();
/// Default native histogram column name.
static GREPTIME_NATIVE_HISTOGRAM_CELL: OnceCell<String> = OnceCell::new();
pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> {
// Strip surrounding double quotes as a defensive measure against upstream
// sources (scripts, CI, template engines, incorrect shell escaping) that may
@@ -41,11 +45,13 @@ pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> {
// use default greptime prefix
GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string());
GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string());
GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| NATIVE_HISTOGRAM_FIELD.to_string());
}
Some(s) if s.trim().is_empty() => {
// use "" to disable prefix
GREPTIME_TIMESTAMP_CELL.get_or_init(|| "timestamp".to_string());
GREPTIME_VALUE_CELL.get_or_init(|| "value".to_string());
GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| "native_histogram".to_string());
}
Some(x) => {
ensure!(
@@ -54,6 +60,7 @@ pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> {
);
GREPTIME_TIMESTAMP_CELL.get_or_init(|| format!("{}_timestamp", x));
GREPTIME_VALUE_CELL.get_or_init(|| format!("{}_value", x));
GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| format!("{}_native_histogram", x));
}
}
Ok(())
@@ -71,6 +78,15 @@ pub fn greptime_value() -> &'static str {
GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string())
}
/// Get the default native histogram column name.
/// Returns the configured value, or `greptime_native_histogram` if not set.
#[inline]
pub fn greptime_native_histogram() -> &'static str {
GREPTIME_NATIVE_HISTOGRAM_CELL
.get()
.map_or(NATIVE_HISTOGRAM_FIELD, String::as_str)
}
/// Default timestamp column name constant for backward compatibility.
const GREPTIME_TIMESTAMP: &str = "greptime_timestamp";
/// Default value column name constant for backward compatibility.
@@ -92,6 +108,7 @@ mod tests {
set_default_prefix(None).unwrap();
assert_eq!(greptime_timestamp(), "greptime_timestamp");
assert_eq!(greptime_value(), "greptime_value");
assert_eq!(greptime_native_histogram(), "greptime_native_histogram");
}
#[test]
@@ -99,6 +116,7 @@ mod tests {
set_default_prefix(Some("")).unwrap();
assert_eq!(greptime_timestamp(), "timestamp");
assert_eq!(greptime_value(), "value");
assert_eq!(greptime_native_histogram(), "native_histogram");
}
#[test]
@@ -107,6 +125,7 @@ mod tests {
set_default_prefix(Some("\"\"")).unwrap();
assert_eq!(greptime_timestamp(), "timestamp");
assert_eq!(greptime_value(), "value");
assert_eq!(greptime_native_histogram(), "native_histogram");
}
#[test]
@@ -114,6 +133,7 @@ mod tests {
set_default_prefix(Some("mydb")).unwrap();
assert_eq!(greptime_timestamp(), "mydb_timestamp");
assert_eq!(greptime_value(), "mydb_value");
assert_eq!(greptime_native_histogram(), "mydb_native_histogram");
}
#[test]