Skip to content
Snippets Groups Projects

Resolve "Add support for more features in query builder API"

Merged Maaz Ahmed requested to merge 39-add-support-for-more-features-in-query-builder-api into main
Files
3
+ 43
0
use std::fmt::Display;
use crate::{query::IntoQuery, seal::Sealed};
use super::Operable;
#[derive(Debug, Clone, Default)]
pub(crate) struct Mod<'a, M> {
mod_type: M,
@@ -114,3 +118,42 @@ impl Display for Mod<'_, AggrType> {
Ok(())
}
}
/// MetricsQL's `keep_metric_names` modifier
///
/// This modifier can only be applied using the `keep_metric_names` method made available by the [`QueryExt`](crate::query::QueryExt) trait.
#[cfg(feature = "metricsql")]
#[derive(Debug, Clone)]
pub struct KeepNames<E: Operable>(pub(crate) E);
#[cfg(feature = "metricsql")]
impl<E: Operable> Display for KeepNames<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{exp} keep_metric_names", exp = self.0)
}
}
#[cfg(feature = "metricsql")]
impl<E: Operable> Sealed for KeepNames<E> {}
#[cfg(feature = "metricsql")]
impl<E: Operable> Operable for KeepNames<E> {}
#[cfg(feature = "metricsql")]
impl<E: Operable> IntoQuery for KeepNames<E> {
type Target = String;
fn into_query(self) -> Self::Target {
self.to_string()
}
}
#[cfg(test)]
mod tests {
use crate::query::{Metric, QueryExt};
#[cfg(feature = "metricsql")]
#[test]
fn keep_names() {
let qry = Metric::new("metric").keep_metric_names();
assert_eq!(qry.to_string(), "metric keep_metric_names");
}
}
Loading