MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / query_plan

Function query_plan

atomic-cli/src/commands/rpc.rs:6929–7007  ·  view source on GitHub ↗

`atomic query plan` over QueryGraph (Plan) — the structured plan executes handler-side; the CLI renders the domain PlanResult JSON byte-for-byte (--json) or the human summary.

(args: &super::query::PlanExec)

Source from the content-addressed store, hash-verified

6927/// executes handler-side; the CLI renders the domain PlanResult JSON
6928/// byte-for-byte (--json) or the human summary.
6929pub fn query_plan(args: &super::query::PlanExec) -> CliResult<bool> {
6930 // Read plan from stdin — client-side (interactive/file-only).
6931 use std::io::Read;
6932 let mut plan_json = String::new();
6933 std::io::stdin()
6934 .read_to_string(&mut plan_json)
6935 .map_err(CliError::Io)?;
6936 let Some(session) = Service::open()? else {
6937 return Ok(false);
6938 };
6939 let request = pb::QueryGraphRequest {
6940 repository: Some(session.reference.clone()),
6941 limit: 0,
6942 query: Some(pb::query_graph_request::Query::Plan(
6943 pb::PlanExecutionQuery {
6944 plan_json: plan_json.into_bytes(),
6945 },
6946 )),
6947 view: None,
6948 };
6949 let response = session.query_graph(request)?;
6950 let Some(payload) = response.plan_result else {
6951 return Err(CliError::Internal(anyhow::anyhow!(
6952 "the service returned no plan result"
6953 )));
6954 };
6955 let result: atomic_repository::PlanResult = serde_json::from_slice(&payload)
6956 .map_err(|error| CliError::Internal(anyhow::anyhow!("plan result: {error}")))?;
6957 if args.json {
6958 println!("{}", serde_json::to_string_pretty(&result).unwrap());
6959 } else {
6960 println!(
6961 "Plan executed in {}ms ({} steps)\n",
6962 result.elapsed_ms,
6963 result.step_stats.len()
6964 );
6965 for (index, stat) in result.step_stats.iter().enumerate() {
6966 println!(
6967 " Step {}: {} → {} results ({}ms)",
6968 index + 1,
6969 stat.step_type,
6970 stat.result_count,
6971 stat.elapsed_ms
6972 );
6973 }
6974 if !result.nodes.is_empty() {
6975 println!("\nNodes ({}):", result.nodes.len());
6976 for node in &result.nodes {
6977 print!(
6978 " [{}] {}",
6979 atomic_core::kg::ontology::compact(node.primary_type()),
6980 node.label
6981 );
6982 if let Some(summary) = &node.summary {
6983 let short: String = summary.chars().take(60).collect();
6984 print!(": {}", short);
6985 }
6986 println!();

Callers 1

runMethod · 0.85

Calls 7

openFunction · 0.50
cloneMethod · 0.45
query_graphMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected