MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / execute_query_recursive

Method execute_query_recursive

graphlite/src/exec/executor.rs:6962–7073  ·  view source on GitHub ↗

Execute query recursively (handles basic queries, set operations, and limited queries)

(
        &self,
        query: &crate::ast::Query,
        context: &mut ExecutionContext,
    )

Source from the content-addressed store, hash-verified

6960
6961 /// Execute query recursively (handles basic queries, set operations, and limited queries)
6962 fn execute_query_recursive(
6963 &self,
6964 query: &crate::ast::Query,
6965 context: &mut ExecutionContext,
6966 ) -> Result<QueryResult, ExecutionError> {
6967 log::debug!("=== EXECUTE_QUERY_RECURSIVE");
6968 log::debug!("Query type: {:?}", std::mem::discriminant(query));
6969 match query {
6970 crate::ast::Query::Basic(basic_query) => {
6971 // Convert basic query to document and plan it
6972 let document = crate::ast::Document {
6973 statement: crate::ast::Statement::Query(crate::ast::Query::Basic(
6974 basic_query.clone(),
6975 )),
6976 location: crate::ast::Location::default(),
6977 };
6978
6979 // Use the planner to create a physical plan
6980 let mut planner = crate::plan::optimizer::QueryPlanner::new();
6981 let plan = planner.plan_query(&document).map_err(|e| {
6982 ExecutionError::PlanningError(format!("Failed to plan query: {}", e))
6983 })?;
6984
6985 // Execute the plan - get default graph if needed
6986 let graph_names = self.storage.get_graph_names().map_err(|e| {
6987 ExecutionError::RuntimeError(format!("Failed to get graph names: {}", e))
6988 })?;
6989 let first_graph_name = graph_names.first().ok_or_else(|| {
6990 ExecutionError::RuntimeError(
6991 "No graphs available for query execution".to_string(),
6992 )
6993 })?;
6994 let graph = self
6995 .storage
6996 .get_graph(first_graph_name)
6997 .map_err(|e| {
6998 ExecutionError::RuntimeError(format!("Failed to get graph: {}", e))
6999 })?
7000 .ok_or_else(|| ExecutionError::RuntimeError("Graph not found".to_string()))?;
7001 let graph_arc = Arc::new(graph);
7002 self.execute_with_graph(&plan, &graph_arc, context)
7003 }
7004 crate::ast::Query::SetOperation(set_op) => self.execute_set_operation(set_op, context),
7005 crate::ast::Query::Limited {
7006 query,
7007 order_clause,
7008 limit_clause,
7009 } => {
7010 // Execute the inner query first
7011 let mut result = self.execute_query_recursive(query, context)?;
7012
7013 // Apply ORDER BY if present
7014 if let Some(order) = order_clause {
7015 result = self.apply_order_by(result, order, context)?;
7016 }
7017
7018 // Apply LIMIT if present
7019 if let Some(limit) = limit_clause {

Callers 2

execute_statementMethod · 0.80
execute_set_operationMethod · 0.80

Calls 15

QueryEnum · 0.85
cloneMethod · 0.80
plan_queryMethod · 0.80
execute_with_graphMethod · 0.80
execute_set_operationMethod · 0.80
apply_order_byMethod · 0.80
execute_let_statementMethod · 0.80
execute_for_statementMethod · 0.80
execute_return_queryMethod · 0.80
PlanningErrorEnum · 0.50

Tested by

no test coverage detected