pub struct QueryExecutor { /* private fields */ }Expand description
Executes queries against code using CodeGraph.
The executor loads a CodeGraph from disk and evaluates queries directly
against graph nodes using execute_on_graph().
Implementations§
Source§impl QueryExecutor
impl QueryExecutor
Sourcepub fn with_plugin_manager(plugin_manager: PluginManager) -> Self
pub fn with_plugin_manager(plugin_manager: PluginManager) -> Self
Create a query executor with a custom plugin manager
Sourcepub fn plugin_manager(&self) -> &PluginManager
pub fn plugin_manager(&self) -> &PluginManager
Return the plugin manager used by this executor.
Sourcepub fn with_validation_options(self, options: ValidationOptions) -> Self
pub fn with_validation_options(self, options: ValidationOptions) -> Self
Configure validation options (e.g., fuzzy field tolerance)
Sourcepub fn without_parallel(self) -> Self
pub fn without_parallel(self) -> Self
Disable parallel query execution (for A/B performance testing)
Sourcepub fn cache_stats(&self) -> (CacheStats, CacheStats)
pub fn cache_stats(&self) -> (CacheStats, CacheStats)
Get cache statistics (for monitoring/debugging)
Sourcepub fn get_query_plan(&self, query_str: &str) -> Result<QueryPlan>
pub fn get_query_plan(&self, query_str: &str) -> Result<QueryPlan>
Get query execution plan for –explain
Parses the query and returns detailed execution plan with timing, cache status, and optimization information.
§Errors
Returns anyhow::Error when query parsing, validation, or optimization fails.
Sourcepub fn parse_query_ast(&self, query_str: &str) -> Result<Arc<ParsedQuery>>
pub fn parse_query_ast(&self, query_str: &str) -> Result<Arc<ParsedQuery>>
Parse query string using boolean AST parser with caching
This method:
- Checks AST parse cache for existing
ParsedQuery - On cache miss: parses query, validates, extracts repo filter, normalizes
- Caches the
ParsedQueryfor future reuse
§Arguments
query_str- Query string to parse (boolean syntax)
§Returns
Ok(Arc<ParsedQuery>)- Cached or freshly parsed queryErr(...)- Parse error, validation error, or repo filter error
§Performance
- Cache hit: ~15-20ns (Arc clone + hash lookup)
- Cache miss: ~1.6µs (lex + parse + validate + normalize)
§Example
let executor = QueryExecutor::new();
let parsed = executor.parse_query_ast("kind:function AND name:test")?;
// parsed.ast contains the boolean expression
// parsed.repo_filter contains any repo: predicates
// parsed.normalized is the cache key (repo predicates stripped)§Errors
Returns anyhow::Error when parsing, validation, or normalization fails.
Source§impl QueryExecutor
impl QueryExecutor
Sourcepub fn execute_on_graph(&self, query: &str, path: &Path) -> Result<QueryResults>
pub fn execute_on_graph(&self, query: &str, path: &Path) -> Result<QueryResults>
Execute query using CodeGraph.
Loads the CodeGraph from disk (or cache) and evaluates the query
directly against graph nodes.
§Arguments
query- The query string to parse and executepath- Directory path containing the.sqry/graph/snapshot.sqryfile
§Returns
QueryResults containing matched NodeIds with Arc-based accessors.
§Errors
Returns an error if:
- No graph exists at the path (run
sqry indexfirst) - Query parsing fails
- Predicate evaluation fails
§Example
let executor = QueryExecutor::new();
let results = executor.execute_on_graph("kind:function", Path::new("/my/project"))?;
for m in results.iter() {
println!("{}: {}", m.kind().as_str(), m.name().unwrap_or_default());
}Sourcepub fn execute_on_graph_with_variables(
&self,
query: &str,
path: &Path,
variables: Option<&HashMap<String, String>>,
) -> Result<QueryResults>
pub fn execute_on_graph_with_variables( &self, query: &str, path: &Path, variables: Option<&HashMap<String, String>>, ) -> Result<QueryResults>
Execute query with variable substitution.
Variables in the query (e.g., $type) are replaced with values from
the provided map before evaluation.
§Errors
Returns an error if graph loading, query parsing, variable resolution, or predicate evaluation fails.
Sourcepub fn execute_join(
&self,
query: &str,
path: &Path,
variables: Option<&HashMap<String, String>>,
) -> Result<JoinResults>
pub fn execute_join( &self, query: &str, path: &Path, variables: Option<&HashMap<String, String>>, ) -> Result<JoinResults>
Execute a join query, returning matched node pairs.
The query must have a Join expression at its root level.
§Errors
Returns an error if graph loading, query parsing, or join evaluation fails.
Sourcepub fn execute_pipeline(
&self,
query: &str,
stages: &[PipelineStage],
path: &Path,
variables: Option<&HashMap<String, String>>,
) -> Result<Vec<AggregationResult>>
pub fn execute_pipeline( &self, query: &str, stages: &[PipelineStage], path: &Path, variables: Option<&HashMap<String, String>>, ) -> Result<Vec<AggregationResult>>
Execute a pipeline query (base query + aggregation stages).
§Errors
Returns an error if graph loading, query parsing, or pipeline execution fails.
Sourcepub fn execute_full(
&self,
query: &str,
path: &Path,
variables: Option<&HashMap<String, String>>,
) -> Result<QueryOutput>
pub fn execute_full( &self, query: &str, path: &Path, variables: Option<&HashMap<String, String>>, ) -> Result<QueryOutput>
Execute a full query that may be a regular query, join, or pipeline.
Detects the query type and dispatches to the appropriate executor.
§Errors
Returns an error if graph loading, query parsing, or execution fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for QueryExecutor
impl !RefUnwindSafe for QueryExecutor
impl Send for QueryExecutor
impl Sync for QueryExecutor
impl Unpin for QueryExecutor
impl UnsafeUnpin for QueryExecutor
impl !UnwindSafe for QueryExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more