mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-09-11 16:02:19 +00:00
@@ -34,7 +34,8 @@ use datatypes::data_type::{ConcreteDataType, DataType};
|
||||
use datatypes::types::{StructField, StructType};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub const NATIVE_HISTOGRAM_FIELD: &str = "greptime_native_histogram";
|
||||
use crate::prelude::greptime_native_histogram;
|
||||
|
||||
pub const SCHEMA_FIELD: &str = "schema";
|
||||
pub const ZERO_THRESHOLD_FIELD: &str = "zero_threshold";
|
||||
pub const SUM_FIELD: &str = "sum";
|
||||
@@ -122,7 +123,7 @@ pub fn is_native_histogram_value_type(data_type: &ConcreteDataType) -> bool {
|
||||
}
|
||||
|
||||
pub fn is_native_histogram_value_schema(name: &str, data_type: &ConcreteDataType) -> bool {
|
||||
name == NATIVE_HISTOGRAM_FIELD && is_native_histogram_value_type(data_type)
|
||||
name == greptime_native_histogram() && is_native_histogram_value_type(data_type)
|
||||
}
|
||||
|
||||
pub const CUSTOM_BUCKETS_SCHEMA: i32 = -53;
|
||||
|
||||
@@ -26,6 +26,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 +44,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(|| GREPTIME_NATIVE_HISTOGRAM.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 +59,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,10 +77,18 @@ 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.
|
||||
pub fn greptime_native_histogram() -> &'static str {
|
||||
GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| GREPTIME_NATIVE_HISTOGRAM.to_string())
|
||||
}
|
||||
|
||||
/// Default timestamp column name constant for backward compatibility.
|
||||
const GREPTIME_TIMESTAMP: &str = "greptime_timestamp";
|
||||
/// Default value column name constant for backward compatibility.
|
||||
const GREPTIME_VALUE: &str = "greptime_value";
|
||||
/// Default native histogram column name.
|
||||
const GREPTIME_NATIVE_HISTOGRAM: &str = "greptime_native_histogram";
|
||||
/// Default counter column name for OTLP metrics (legacy mode).
|
||||
pub const GREPTIME_COUNT: &str = "greptime_count";
|
||||
/// Default physical table name
|
||||
@@ -92,6 +106,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 +114,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 +123,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 +131,11 @@ 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");
|
||||
assert!(crate::native_histogram::is_native_histogram_value_schema(
|
||||
greptime_native_histogram(),
|
||||
crate::native_histogram::native_histogram_value_type(),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -660,8 +660,8 @@ pub(crate) fn region_options_for_metadata_region(
|
||||
mod test {
|
||||
use common_meta::ddl::test_util::assert_column_name_and_id;
|
||||
use common_meta::ddl::utils::{parse_column_metadatas, parse_manifest_infos_from_extensions};
|
||||
use common_query::native_histogram::{NATIVE_HISTOGRAM_FIELD, native_histogram_value_type};
|
||||
use common_query::prelude::{greptime_timestamp, greptime_value};
|
||||
use common_query::native_histogram::native_histogram_value_type;
|
||||
use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value};
|
||||
use store_api::metric_engine_consts::{METRIC_ENGINE_NAME, PHYSICAL_TABLE_METADATA_KEY};
|
||||
use store_api::region_request::{BatchRegionDdlRequest, RegionRequirements};
|
||||
|
||||
@@ -874,7 +874,7 @@ mod test {
|
||||
column_id: 2,
|
||||
semantic_type: SemanticType::Field,
|
||||
column_schema: ColumnSchema::new(
|
||||
NATIVE_HISTOGRAM_FIELD,
|
||||
greptime_native_histogram(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
|
||||
@@ -767,8 +767,7 @@ mod tests {
|
||||
use common_error::ext::ErrorExt;
|
||||
use common_error::status_code::StatusCode;
|
||||
use common_function::utils::partition_expr_version;
|
||||
use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD;
|
||||
use common_query::prelude::{greptime_timestamp, greptime_value};
|
||||
use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value};
|
||||
use common_recordbatch::RecordBatches;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema};
|
||||
@@ -1014,7 +1013,7 @@ mod tests {
|
||||
options: None,
|
||||
};
|
||||
let histogram = PbColumnSchema {
|
||||
column_name: NATIVE_HISTOGRAM_FIELD.to_string(),
|
||||
column_name: greptime_native_histogram().to_string(),
|
||||
datatype: ColumnDataType::Struct as i32,
|
||||
semantic_type: SemanticType::Field as _,
|
||||
datatype_extension: None,
|
||||
@@ -1066,7 +1065,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let value_idx = column_index(&merged_request, greptime_value());
|
||||
let histogram_idx = column_index(&merged_request, NATIVE_HISTOGRAM_FIELD);
|
||||
let histogram_idx = column_index(&merged_request, greptime_native_histogram());
|
||||
assert!(matches!(
|
||||
merged_request.rows[0].values[value_idx].value_data,
|
||||
Some(ValueData::F64Value(_))
|
||||
|
||||
@@ -38,9 +38,9 @@ use common_meta::node_manager::{AffectedRows, NodeManagerRef};
|
||||
use common_meta::peer::Peer;
|
||||
use common_query::Output;
|
||||
use common_query::native_histogram::{
|
||||
NATIVE_HISTOGRAM_FIELD, is_native_histogram_value_schema, native_histogram_value_type,
|
||||
is_native_histogram_value_schema, native_histogram_value_type,
|
||||
};
|
||||
use common_query::prelude::{greptime_timestamp, greptime_value};
|
||||
use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value};
|
||||
use common_telemetry::tracing_context::TracingContext;
|
||||
use common_telemetry::{error, info, warn};
|
||||
use datatypes::schema::SkippingIndexOptions;
|
||||
@@ -1143,7 +1143,7 @@ fn request_is_native_histogram(request_schema: &[ColumnSchema]) -> bool {
|
||||
};
|
||||
|
||||
fields.next().is_none()
|
||||
&& col.column_name == NATIVE_HISTOGRAM_FIELD
|
||||
&& col.column_name == greptime_native_histogram()
|
||||
&& api::helper::is_column_type_value_eq(
|
||||
col.datatype,
|
||||
col.datatype_extension.clone(),
|
||||
|
||||
@@ -5591,8 +5591,7 @@ mod test {
|
||||
use catalog::memory::{MemoryCatalogManager, new_memory_catalog_manager};
|
||||
use common_base::Plugins;
|
||||
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
|
||||
use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD;
|
||||
use common_query::prelude::greptime_timestamp;
|
||||
use common_query::prelude::{greptime_native_histogram, greptime_timestamp};
|
||||
use common_query::test_util::DummyDecoder;
|
||||
use datafusion::arrow::array::{
|
||||
Array, Float64Array, Int64Array, StringArray, TimestampMillisecondArray,
|
||||
@@ -6081,7 +6080,7 @@ mod test {
|
||||
)
|
||||
.with_time_index(true),
|
||||
ColumnSchema::new(
|
||||
NATIVE_HISTOGRAM_FIELD.to_string(),
|
||||
greptime_native_histogram().to_string(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
|
||||
@@ -2286,6 +2286,7 @@ mod tests {
|
||||
use catalog::{RegisterSchemaRequest, RegisterTableRequest};
|
||||
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
|
||||
use common_query::native_histogram::native_histogram_value_type;
|
||||
use common_query::prelude::greptime_native_histogram;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::schema::{ColumnSchema, Schema};
|
||||
use promql_parser::parser::value::ValueType;
|
||||
@@ -3268,7 +3269,7 @@ mod tests {
|
||||
let schema = Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("host", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new(
|
||||
"greptime_native_histogram",
|
||||
greptime_native_histogram(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
|
||||
@@ -456,9 +456,9 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
|
||||
use common_query::native_histogram::{
|
||||
NATIVE_HISTOGRAM_FIELD, NativeHistogram, Span, build_histogram_array,
|
||||
native_histogram_value_type,
|
||||
NativeHistogram, Span, build_histogram_array, native_histogram_value_type,
|
||||
};
|
||||
use common_query::prelude::greptime_native_histogram;
|
||||
use common_query::{Output, OutputData, OutputMeta};
|
||||
use common_recordbatch::{RecordBatch, RecordBatches};
|
||||
use datatypes::data_type::ConcreteDataType;
|
||||
@@ -636,7 +636,7 @@ mod tests {
|
||||
ColumnSchema::new("job", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("value", ConcreteDataType::float64_datatype(), true),
|
||||
ColumnSchema::new(
|
||||
NATIVE_HISTOGRAM_FIELD,
|
||||
greptime_native_histogram(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
@@ -682,7 +682,7 @@ mod tests {
|
||||
ColumnSchema::new("job", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("value", ConcreteDataType::float64_datatype(), true),
|
||||
ColumnSchema::new(
|
||||
NATIVE_HISTOGRAM_FIELD,
|
||||
greptime_native_histogram(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
@@ -728,7 +728,7 @@ mod tests {
|
||||
.with_time_index(true),
|
||||
ColumnSchema::new("job", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new(
|
||||
NATIVE_HISTOGRAM_FIELD,
|
||||
greptime_native_histogram(),
|
||||
native_histogram_value_type().clone(),
|
||||
true,
|
||||
),
|
||||
|
||||
@@ -27,7 +27,7 @@ use api::v1::{ColumnSchema, ListValue, RowInsertRequest, Rows, SemanticType, Val
|
||||
use bytes::Bytes;
|
||||
use common_grpc::precision::Precision;
|
||||
use common_query::native_histogram::*;
|
||||
use common_query::prelude::{greptime_timestamp, greptime_value};
|
||||
use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value};
|
||||
use pipeline::{ContextOpt, ContextReq};
|
||||
use prost::Message;
|
||||
use snafu::{OptionExt, ResultExt, ensure};
|
||||
@@ -275,7 +275,7 @@ fn native_histogram_column_schema() -> ColumnSchema {
|
||||
.into_parts();
|
||||
|
||||
ColumnSchema {
|
||||
column_name: NATIVE_HISTOGRAM_FIELD.to_string(),
|
||||
column_name: greptime_native_histogram().to_string(),
|
||||
datatype: datatype as i32,
|
||||
semantic_type: SemanticType::Field as i32,
|
||||
datatype_extension,
|
||||
@@ -631,7 +631,7 @@ fn ensure_no_internal_histogram_labels(tags: &PromTags) -> Result<()> {
|
||||
// The histogram field column is generated from the protobuf payload.
|
||||
for (name, _) in tags {
|
||||
ensure!(
|
||||
name != NATIVE_HISTOGRAM_FIELD,
|
||||
name != greptime_native_histogram(),
|
||||
error::InvalidPromRemoteRequestSnafu {
|
||||
msg: format!(
|
||||
"remote write v2 label `{name}` conflicts with an internal native histogram label"
|
||||
@@ -1085,7 +1085,7 @@ mod tests {
|
||||
"internal histogram label on samples",
|
||||
request_with_sample(vec![
|
||||
(METRIC_NAME_LABEL, "metric"),
|
||||
(NATIVE_HISTOGRAM_FIELD, "user_value"),
|
||||
(greptime_native_histogram(), "user_value"),
|
||||
]),
|
||||
"conflicts with an internal native histogram label",
|
||||
));
|
||||
@@ -1313,7 +1313,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|col| col.column_name.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec![greptime_timestamp(), NATIVE_HISTOGRAM_FIELD]
|
||||
vec![greptime_timestamp(), greptime_native_histogram()]
|
||||
);
|
||||
assert_eq!(
|
||||
rows.rows[0].values[0].value_data,
|
||||
@@ -1356,7 +1356,7 @@ mod tests {
|
||||
let mut request = test_util::request_with_labels_and_samples(
|
||||
vec![
|
||||
(METRIC_NAME_LABEL, "metric"),
|
||||
(NATIVE_HISTOGRAM_FIELD, "user_value"),
|
||||
(greptime_native_histogram(), "user_value"),
|
||||
],
|
||||
vec![],
|
||||
);
|
||||
@@ -1421,7 +1421,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|col| col.column_name.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec![greptime_timestamp(), NATIVE_HISTOGRAM_FIELD]
|
||||
vec![greptime_timestamp(), greptime_native_histogram()]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -1496,7 +1496,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn histogram_field_value(rows: &Rows, row_idx: usize, field_name: &str) -> Option<ValueData> {
|
||||
let histogram_idx = column_index(&rows.schema, NATIVE_HISTOGRAM_FIELD);
|
||||
let histogram_idx = column_index(&rows.schema, greptime_native_histogram());
|
||||
let Some(ValueData::StructValue(histogram)) =
|
||||
&rows.rows[row_idx].values[histogram_idx].value_data
|
||||
else {
|
||||
|
||||
@@ -28,8 +28,9 @@ use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use axum::http::HeaderMap;
|
||||
use common_query::Output;
|
||||
use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD;
|
||||
use common_query::prelude::{GREPTIME_PHYSICAL_TABLE, greptime_timestamp, greptime_value};
|
||||
use common_query::prelude::{
|
||||
GREPTIME_PHYSICAL_TABLE, greptime_native_histogram, greptime_timestamp, greptime_value,
|
||||
};
|
||||
use common_test_util::ports;
|
||||
use datafusion_expr::LogicalPlan;
|
||||
use prost::Message;
|
||||
@@ -675,7 +676,7 @@ async fn test_prometheus_remote_write_v2_writes_histogram_only_series() {
|
||||
assert!(
|
||||
rows.schema
|
||||
.iter()
|
||||
.any(|column| column.column_name == NATIVE_HISTOGRAM_FIELD
|
||||
.any(|column| column.column_name == greptime_native_histogram()
|
||||
&& column.datatype == ColumnDataType::Struct as i32)
|
||||
);
|
||||
assert!(write_rx.try_recv().is_err());
|
||||
|
||||
@@ -18,10 +18,10 @@ use api::v1::value::ValueData;
|
||||
use api::v1::{ColumnSchema, Rows};
|
||||
use bytes::Bytes;
|
||||
use common_query::native_histogram::{
|
||||
COUNT_U64_FIELD, NATIVE_HISTOGRAM_FIELD, NATIVE_HISTOGRAM_FIELD_NAMES,
|
||||
POSITIVE_BUCKETS_F64_FIELD, POSITIVE_BUCKETS_I64_FIELD, POSITIVE_SPAN_OFFSETS_FIELD,
|
||||
SCHEMA_FIELD,
|
||||
COUNT_U64_FIELD, NATIVE_HISTOGRAM_FIELD_NAMES, POSITIVE_BUCKETS_F64_FIELD,
|
||||
POSITIVE_BUCKETS_I64_FIELD, POSITIVE_SPAN_OFFSETS_FIELD, SCHEMA_FIELD,
|
||||
};
|
||||
use common_query::prelude::greptime_native_histogram;
|
||||
use servers::prom_remote_write::v2::test_util as remote_write_v2;
|
||||
|
||||
#[test]
|
||||
@@ -126,7 +126,7 @@ fn column_index(schema: &[ColumnSchema], column_name: &str) -> usize {
|
||||
}
|
||||
|
||||
fn histogram_field_value(rows: &Rows, row_idx: usize, field_name: &str) -> Option<ValueData> {
|
||||
let histogram_idx = column_index(&rows.schema, NATIVE_HISTOGRAM_FIELD);
|
||||
let histogram_idx = column_index(&rows.schema, greptime_native_histogram());
|
||||
let Some(ValueData::StructValue(histogram)) =
|
||||
&rows.rows[row_idx].values[histogram_idx].value_data
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user