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
14 changes: 12 additions & 2 deletions control_plane/src/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,14 @@ pub async fn compile_automatic_clickhouse_workload(
let config = materialize_selected_sql(node, family, query)
.map_err(crate::query_plan::QueryPlanError::Invalid)?;
let binding = MaterializationBinding {
full_window_slide_ms: matches!(
config.window_layout,
asap_types::WindowMaterializationLayout::FullWindow
)
.then_some(config.slide_interval.saturating_mul(1_000)),
materialization: config.policy_fingerprint().into(),
output_grouping: PhysicalGrouping::Reduce(config.grouping_labels.names()),
window_ms: config.slide_interval * 1000,
window_ms: config.stored_window_ms(),
pane_origin_ms: config.pane_origin_ms,
readout_lookback_ms: Some(query.end_ms - query.start_ms),
item_labels: config.aggregated_labels.labels.clone(),
Expand Down Expand Up @@ -600,9 +605,14 @@ fn bind_selected_node(
));
}
Ok(MaterializationBinding {
full_window_slide_ms: matches!(
selected.window_layout,
asap_types::WindowMaterializationLayout::FullWindow
)
.then_some(selected.slide_interval.saturating_mul(1_000)),
materialization: selected.policy_fingerprint().into(),
output_grouping: PhysicalGrouping::Reduce(selected.grouping_labels.names()),
window_ms: selected.slide_interval.saturating_mul(1000),
window_ms: selected.stored_window_ms(),
pane_origin_ms: selected.pane_origin_ms,
readout_lookback_ms: source_window.map(|seconds| seconds.saturating_mul(1000)),
item_labels: selected.aggregated_labels.labels.clone(),
Expand Down
50 changes: 42 additions & 8 deletions control_plane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ struct PhysicalPlanQueryRequest {
group_by: Vec<String>,
accuracy: types::AccuracyTarget,
lifecycle: physical::compiler::LifecyclePlanningInput,
window_implementations: Vec<physical::compiler::WindowImplementationCandidate>,
window_cost_model: physical::compiler::WindowCostModel,
evaluation_phase_ms: u64,
#[serde(default)]
runtime_policy: physical::compiler::RuntimeRulePolicy,
}
Expand Down Expand Up @@ -870,6 +871,8 @@ fn compile_physical_plan_request(
.as_millis() as u64;
let mut queries = Vec::with_capacity(request.queries.len());
let mut canonical_roots = Vec::with_capacity(request.queries.len());
let mut window_models = Vec::new();
let mut workload_entries = Vec::new();
for query in request.queries {
if query.query_id.trim().is_empty()
|| query.metric.trim().is_empty()
Expand All @@ -891,6 +894,29 @@ fn compile_physical_plan_request(
Err(error) => return Err((StatusCode::UNPROCESSABLE_ENTITY, error.to_string().into())),
};
canonical_roots.push(std::rc::Rc::new(expr));
window_models.push(query.window_cost_model);
workload_entries.push(planner_types::workload::RepeatingEntry {
query: planner_types::workload::Query(query.query_string.clone()),
demand: planner_types::workload::RepeatedDemand::FixedIntervalAt {
interval: planner_types::workload::RepetitionInterval(
query.lifecycle.evaluation_interval_ms,
),
evaluation_phase: planner_types::workload::TimestampMs(query.evaluation_phase_ms),
},
requirements: planner_types::workload::QueryRequirements {
accuracy: planner_types::workload::AccuracyRequirement::Explicit(
query.accuracy.clone(),
),
..Default::default()
},
predictability: planner_types::workload::Predictability::Predictable { known_at: None },
time_selection: planner_types::workload::TimeSelection {
lookback: Some(planner_types::workload::DurationMs(
query.window_secs.saturating_mul(1_000),
)),
..Default::default()
},
});
queries.push(physical::compiler::PlanningQuery {
query_id: query.query_id,
query_string: query.query_string,
Expand All @@ -902,7 +928,7 @@ fn compile_physical_plan_request(
group_by: query.group_by,
accuracy: query.accuracy,
lifecycle: query.lifecycle,
window_implementations: query.window_implementations,
window_implementations: Vec::new(),
runtime_policy: query.runtime_policy,
});
}
Expand All @@ -918,10 +944,18 @@ fn compile_physical_plan_request(
Err(error) => return Err((StatusCode::UNPROCESSABLE_ENTITY, error.to_string().into())),
};

for (query, model) in queries.iter_mut().zip(window_models) {
physical::compiler::prepare_window_implementations(query, &model, request.target, 0)
.map_err(|error| (StatusCode::UNPROCESSABLE_ENTITY, error.to_string().into()))?;
}
let planning_request = physical::compiler::PlanningRequest {
synthesized_window_queries: Default::default(),
logical_selection,
query_workload: None,
query_workload: Some(planner_types::workload::QueryWorkload {
language: planner_types::workload::QueryLanguage::PromQL,
query_batch: None,
repeating_queries: Some(workload_entries),
data_workload: None,
}),
queries,
hybrid_execution: request.target
== physical::compiler::PhysicalDeploymentTarget::BackendLocalRemoteWrite,
Expand Down Expand Up @@ -2209,7 +2243,7 @@ mod api_tests {
include_str!("../../docs/examples/asapquery-planning-snapshot.json"),
)
.unwrap();
let (planning, _) = snapshot.planning_request().unwrap();
let (planning, _) = snapshot.clone().planning_request().unwrap();
let query = &planning.queries[0];
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand All @@ -2219,7 +2253,7 @@ mod api_tests {
"queries": [{
"query_id": query.query_id, "query_string": query.query_string,
"metric": "m", "window_secs": 60, "accuracy": query.accuracy,
"lifecycle": query.lifecycle, "window_implementations": []
"lifecycle": query.lifecycle, "evaluation_phase_ms": 0, "window_cost_model": snapshot.implementation.window_cost_model
}],
"collector_ids": ["test"], "capability_snapshot_id": "test",
"planner_revision": physical::compiler::PLANNER_REVISION,
Expand Down Expand Up @@ -2273,7 +2307,7 @@ mod api_tests {
include_str!("../../docs/examples/asapquery-compatibility-demo-snapshot.json"),
)
.unwrap();
let (planning, _) = snapshot.planning_request().unwrap();
let (planning, _) = snapshot.clone().planning_request().unwrap();
let mut query = planning.queries[0].clone();
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand All @@ -2291,7 +2325,7 @@ mod api_tests {
"queries": [{
"query_id": query.query_id, "query_string": query.query_string,
"metric": metric, "window_secs": query.window_secs, "accuracy": query.accuracy,
"lifecycle": query.lifecycle, "window_implementations": query.window_implementations
"lifecycle": query.lifecycle, "evaluation_phase_ms": 0, "window_cost_model": { "implementation_id": "test", "cost": query.window_implementations[0].cost }
}],
"collector_ids": [], "capability_snapshot_id": "test",
"planner_revision": physical::compiler::PLANNER_REVISION,
Expand Down
Loading
Loading