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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions control_plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ asap_types.workspace = true
# scaffolding, unaware that `data_plane`'s `summary_executor.rs` in *this*
# repo is a real one. Vendored locally instead of chased upstream -- see
# `data_plane/src/query_engines/asap_query_engine/summary_exec.rs`.
planner-types = { package = "asap-types", git = "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/ProjectASAP/ASAPPlanner", rev = "b2b05628dd9a58db555ba309bf7201e10513f4d2" }
asap-aware-mapping = { git = "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/ProjectASAP/ASAPPlanner", rev = "b2b05628dd9a58db555ba309bf7201e10513f4d2" }
planner-types = { package = "asap-types", git = "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/ProjectASAP/ASAPPlanner", rev = "0402384e589df6e087d6d2d22b463ddc2eea0774" }
asap-aware-mapping = { git = "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/ProjectASAP/ASAPPlanner", rev = "0402384e589df6e087d6d2d22b463ddc2eea0774" }

# L1 adoption (design-target-architecture.md Part B): the PromQL front
# end itself, replacing control_plane's own query_parser/promql.rs.
# Pinned via `rev`, not a floating branch reference. Same rev as
# `planner-types`/`asap-aware-mapping` above -- these three MUST move
# together (two revs of the same upstream repo's types in one workspace
# resolve to distinct Rust types that won't unify).
asap-frontend-promql = { git = "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/ProjectASAP/ASAPPlanner", rev = "b2b05628dd9a58db555ba309bf7201e10513f4d2" }
asap-frontend-sql = { git = "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/ProjectASAP/ASAPPlanner", rev = "b2b05628dd9a58db555ba309bf7201e10513f4d2" }
asap-frontend-promql = { git = "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/ProjectASAP/ASAPPlanner", rev = "0402384e589df6e087d6d2d22b463ddc2eea0774" }
asap-frontend-sql = { git = "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/ProjectASAP/ASAPPlanner", rev = "0402384e589df6e087d6d2d22b463ddc2eea0774" }

[dev-dependencies]
tokio = { version = "1", features = ["full", "test-util"] }
Expand Down
62 changes: 23 additions & 39 deletions control_plane/src/query_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! node IDs. Serving executes this graph without reconstructing Planner IR or
//! searching for compatible materializations.

mod clickhouse_exact;
pub mod logical;

use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -990,6 +991,9 @@ where
| planner_types::post_asap::ValueOperation::Filter { .. }
| planner_types::post_asap::ValueOperation::Sort { .. }
| planner_types::post_asap::ValueOperation::Limit { .. }
| planner_types::post_asap::ValueOperation::Exact(
planner_types::post_asap::ExactOperation::Aggregate { .. }
)
) =>
{
QueryPlanNode::Relational {
Expand Down Expand Up @@ -1324,48 +1328,28 @@ where
}
}
SummaryExpr::KeepPreAsap(expr) if self.preserve_relational => {
let planner_types::pre_asap::QueryExpr::Scan {
source: planner_types::pre_asap::Source::Table { table_ref },
predicates,
schema,
let mut expression =
clickhouse_exact::render(expr).map_err(QueryPlanError::UnsupportedNode)?;
let mut bounded = false;
if let planner_types::pre_asap::QueryExpr::Scan {
predicates, schema, ..
} = expr.as_ref()
else {
return Err(QueryPlanError::UnsupportedNode(
"SQL exact cut is not a direct table scan".into(),
));
};
if !predicates.is_empty() {
return Err(QueryPlanError::UnsupportedNode(
"SQL exact table cut contains unrendered predicates".into(),
));
}
fn quoted(identifier: &str) -> String {
identifier
.split('.')
.map(|part| format!("`{}`", part.replace('`', "``")))
.collect::<Vec<_>>()
.join(".")
{
if predicates.is_empty() {
if let Some(column) = schema.time_index.and_then(|i| schema.columns.get(i))
{
let name = format!("`{}`", column.name.replace('`', "``"));
expression.push_str(&format!(
" WHERE {name} >= {{from:UInt64}} AND {name} <= {{to:UInt64}}"
));
bounded = true;
}
}
}
let columns = schema
.columns
.iter()
.map(|column| quoted(&column.name))
.collect::<Vec<_>>()
.join(", ");
let time_filter = schema.time_index.and_then(|index| {
schema.columns.get(index).map(|source_column| {
let column = quoted(&source_column.name);
format!(" WHERE {column} >= {{from:UInt64}} AND {column} <= {{to:UInt64}}")
})
});
QueryPlanNode::ExternalExact {
request: ExternalExactRequest {
language: QueryLanguage::ClickHouseSql,
expression: format!(
"SELECT {columns} FROM {}{}",
quoted(table_ref),
time_filter.unwrap_or_default()
),
expression,
output: ExternalExactOutput::Relation {
schema: serde_json::to_value(&node.schema).map_err(|error| {
QueryPlanError::Invalid(format!(
Expand All @@ -1374,8 +1358,8 @@ where
})?,
},
parameters: BTreeMap::new(),
start_parameter: Some("from".into()),
end_parameter: Some("to".into()),
start_parameter: bounded.then(|| "from".into()),
end_parameter: bounded.then(|| "to".into()),
input_contracts: Vec::new(),
},
inputs: Vec::new(),
Expand Down
Loading
Loading