Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/frontend-metricsql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,30 @@ fn require_arity(name: &str, actual: usize, expected: usize) -> Result<(), Metri
fn unsupported(message: impl Into<String>) -> MetricsqlError {
MetricsqlError::UnsupportedFeature(message.into())
}

/// Lower one MetricsQL query whose metrics are all sampled every
/// `sample_interval`, to an operator root; a scalar query is an error (use
/// [`lower_metricsql_query`]).
pub fn lower_metricsql(
query: &str,
accuracy: AccuracyTarget,
sample_interval: Duration,
) -> Result<Rc<asap_types::ir::OperatorNode>, MetricsqlError> {
match lower_metricsql_query(query, accuracy, sample_interval)? {
asap_types::ir::QueryRoot::Operator(node) => Ok(node),
_ => Err(MetricsqlError::UnsupportedFeature(
"scalar root: use lower_metricsql_query".into(),
)),
}
}

/// Lower scalar constants without fabricating a relational operator. Every
/// metric is sampled every `sample_interval`: a bare instant selector looks
/// back that long for its latest sample.
pub fn lower_metricsql_query(
query: &str,
accuracy: AccuracyTarget,
sample_interval: Duration,
) -> Result<asap_types::ir::QueryRoot, MetricsqlError> {
lower_with_sample_intervals(query, accuracy, &|_| Some(sample_interval))
}
40 changes: 5 additions & 35 deletions crates/frontend-metricsql/src/test_support.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
//! Entry points only tests use, exposed under the `test-support` feature:
//! parsing and printing a query, and lowering one query whose metrics share
//! one sample interval. Production lowers whole workloads with
//! [`lower_metricsql_query_workload`](crate::lower_metricsql_query_workload).
use std::rc::Rc;
use std::time::Duration;

use asap_types::ir::properties::AccuracyTarget;
use asap_types::ir::{OperatorNode, QueryRoot};

//! parsing and printing a query. `lower_metricsql` and `lower_metricsql_query`
//! are public API (a stable external dependency, checked by
//! `tools/verify_metricsql_external_consumer.sh`) and re-exported here for
//! existing test paths.
use crate::{MetricsqlError, MetricsqlExpr};

/// Parse one MetricsQL query.
Expand All @@ -20,29 +15,4 @@ pub fn canonical_metricsql(query: &str) -> Result<String, MetricsqlError> {
Ok(crate::parse_metricsql(query)?.to_string())
}

/// Lower one MetricsQL query whose metrics are all sampled every
/// `sample_interval`, to an operator root; a scalar query is an error (use
/// [`lower_metricsql_query`]).
pub fn lower_metricsql(
query: &str,
accuracy: AccuracyTarget,
sample_interval: Duration,
) -> Result<Rc<OperatorNode>, MetricsqlError> {
match lower_metricsql_query(query, accuracy, sample_interval)? {
QueryRoot::Operator(node) => Ok(node),
_ => Err(MetricsqlError::UnsupportedFeature(
"scalar root: use lower_metricsql_query".into(),
)),
}
}

/// Lower scalar constants without fabricating a relational operator. Every
/// metric is sampled every `sample_interval`: a bare instant selector looks
/// back that long for its latest sample.
pub fn lower_metricsql_query(
query: &str,
accuracy: AccuracyTarget,
sample_interval: Duration,
) -> Result<QueryRoot, MetricsqlError> {
crate::lower_with_sample_intervals(query, accuracy, &|_| Some(sample_interval))
}
pub use crate::{lower_metricsql, lower_metricsql_query};
Loading