Skip to content
Snippets Groups Projects
Commit ea6de10e authored by Maaz Ahmed's avatar Maaz Ahmed
Browse files

feat: MetricsQL alias fn

parent cb059cdc
No related branches found
No related tags found
1 merge request!26Resolve "MetricsQL's alias fn"
Pipeline #14927 passed with stages
in 1 minute and 41 seconds
......@@ -7,6 +7,15 @@ use crate::query::{
ops::Operable,
};
/// MetricsQL's alias label manipulation query function
#[inline]
pub fn mql_alias<'a>(
qry_expr: impl Operable + 'a,
name: &'a str,
) -> QryFunc<impl Fn(&mut fmt::Formatter) -> fmt::Result + 'a> {
qry_fn!(alias, "{qry_expr}, \"{name}\"")
}
/// MetricsQL's label_set label manipulation query function
#[inline]
pub fn mql_label_set<'a>(
......@@ -126,4 +135,10 @@ mod tests {
let qry = mql_label_set(Metric::new("metric"), &["label", "value"]).to_string();
assert_eq!(qry, r#"label_set(metric,"label","value")"#);
}
#[test]
fn label_alias() {
let qry = mql_alias(Metric::new("metric"), "alias").to_string();
assert_eq!(qry, "alias(metric, \"alias\")");
}
}
......@@ -107,6 +107,13 @@ async fn mql_label_map() {
utils::send_query(query).await.unwrap();
}
#[cfg(feature = "metricsql")]
#[tokio::test]
async fn mql_alias() {
let query = label::mql_alias(Metric::new("metric"), "alias");
utils::send_query(query).await.unwrap();
}
#[cfg(feature = "metricsql")]
label_tests!(
mql_label_set,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment