Skip to main content

Analytics

Struct Analytics 

Source
pub struct Analytics { /* private fields */ }
Expand description

DuckDB analytics engine for code intelligence.

Implementations§

Source§

impl Analytics

Source

pub fn open(root: &Path) -> Result<Self>

Open DuckDB and attach the SQLite database.

Source

pub fn call_graph( &self, start_name: &str, max_depth: i32, ) -> Result<Vec<CallGraphNode>>

Get the full call graph starting from a symbol (forward traversal).

The start_name can be:

  • A simple name like “new” (matches first symbol with that name)
  • A qualified name like “LocalProvider::new”
  • A full ID like “src/embeddings/local.rs::LocalProvider::new@20”
Source

pub fn impact_analysis( &self, target_name: &str, max_depth: i32, ) -> Result<Vec<ImpactNode>>

Impact analysis: find all symbols that would be affected by changing the target.

The target_name can be:

  • A simple name like “new” (matches first symbol with that name)
  • A qualified name like “LocalProvider::new”
  • A full ID like “src/embeddings/local.rs::LocalProvider::new@20”
Source

pub fn file_statistics(&self) -> Result<Vec<FileStats>>

Get file statistics for all indexed files.

Source

pub fn symbol_summary(&self) -> Result<Vec<(String, i64, i64)>>

Get symbol counts by kind.

Source

pub fn has_path( &self, from_name: &str, to_name: &str, max_depth: i32, ) -> Result<bool>

Find if a path exists between two symbols (simplified version).

Both from_name and to_name can be symbol IDs, qualified names, or simple names.

Source

pub fn most_connected( &self, limit: i32, ) -> Result<Vec<(String, String, i64, i64)>>

Get the most connected symbols (highest in/out degree).

This correctly counts incoming edges per symbol ID, not by name, avoiding over-counting for common names like “new”.

Source

pub fn find_recursive_functions(&self) -> Result<Vec<(String, String)>>

Check if there are any self-recursive functions.

Uses target_id when available for accurate recursion detection.

Source

pub fn file_dependencies(&self) -> Result<Vec<(String, String, i64)>>

Get dependency graph between files (module-level).

Uses target_id when available for accurate file resolution.

Source

pub fn complexity_analysis( &self, threshold: i64, ) -> Result<Vec<ComplexityResult>>

Analyze code complexity based on fan-out (outgoing calls) and fan-in (incoming calls).

This correctly counts incoming edges per symbol ID, not by name, avoiding over-counting for common names like “new”.

Source

pub fn full_call_graph( &self, _max_depth: i32, ) -> Result<Vec<(String, String, String, String)>>

Get the full call graph (all edges with resolved symbols).

Uses target_id when available for accurate symbol resolution.

Source

pub fn open_sql_sandbox(root: &Path, snapshots: Option<&Path>) -> Result<Self>

Open DuckDB for the ctx sql command: attach the SQLite index read-only, build the public v1 view layer, optionally materialize snapshot partitions as snap.* tables, then lock the engine down so untrusted user SQL cannot touch the filesystem, load extensions, or re-enable any of that. Safety is enforced entirely by engine configuration — never by inspecting the SQL text.

snapshots, when set, is a directory of sha=<sha>/ Parquet partitions written by ctx snapshot; each partition’s four files are loaded into in-memory tables snap.files, snap.symbols, snap.dup_pairs, and snap.meta.

Source

pub fn open_export(root: &Path) -> Result<Self>

Open DuckDB for snapshot export (ctx snapshot): attach the SQLite index read-only and build the same public v1 view layer as Analytics::open_sql_sandbox, but with no engine hardening (enable_external_access stays on so COPY ... TO ... (FORMAT PARQUET) can write partition files).

This is a trusted internal path: it only ever executes SQL composed by ctx itself and is never fed user SQL. Anything user-facing must go through the hardened Analytics::open_sql_sandbox instead.

Source

pub fn interrupt_handle(&self) -> Arc<InterruptHandle>

A handle that can interrupt an in-flight query from another thread (used to enforce --timeout). InterruptHandle is Send + Sync.

Source

pub fn exec_non_final_statement(&self, sql: &str) -> Result<bool>

Execute a non-final statement in a multi-statement submission.

Returns Ok(true) if the statement produces a result set — the caller rejects that (only the final statement may return rows, per the one result-set rule). Statements that produce no result set (e.g. CREATE TEMP TABLE …, SET …) are executed for their side effects and return Ok(false).

(DuckDB only knows a statement’s column count after execution, so the statement is always run — harmless here, since the index is read-only and the in-memory DuckDB is throwaway.)

Source

pub fn run_final_statement( &self, sql: &str, max_rows: usize, ) -> Result<SqlResult>

Run the final (result-producing) statement, streaming rows and stopping once max_rows is reached (0 = unlimited). One extra row is fetched to detect truncation, so the full result is never materialized in Rust.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more