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

Method analyze_query

graphlite/src/coordinator/query_coordinator.rs:660–759  ·  view source on GitHub ↗

Analyze a query and return metadata without executing it This is useful for understanding query characteristics, estimating resource usage, or implementing query analysis tools. # Arguments `query` - The GQL query string to analyze # Returns `Ok(QueryInfo)` - Query metadata `Err(String)` - Error if query cannot be parsed # Example ```no_run # use graphlite::QueryCoordinator; # let coordinator

(&self, query: &str)

Source from the content-addressed store, hash-verified

658 /// println!("Read-only: {}", info.is_read_only);
659 /// ```
660 pub fn analyze_query(&self, query: &str) -> Result<QueryInfo, String> {
661 // Parse the query
662 let document = parse_query(query).map_err(|e| format!("Parse error: {:?}", e))?;
663
664 // Analyze the statement type
665 let query_type = match &document.statement {
666 crate::ast::Statement::Query(_) => QueryType::Match,
667 crate::ast::Statement::Select(_) => QueryType::Select,
668 crate::ast::Statement::Call(_) => QueryType::Call,
669 crate::ast::Statement::CatalogStatement(cat) => {
670 use crate::ast::CatalogStatement;
671 match cat {
672 CatalogStatement::CreateSchema { .. } => QueryType::CreateSchema,
673 CatalogStatement::DropSchema { .. } => QueryType::DropSchema,
674 CatalogStatement::CreateGraph { .. } => QueryType::CreateGraph,
675 CatalogStatement::DropGraph { .. } => QueryType::DropGraph,
676 CatalogStatement::CreateGraphType { .. } => QueryType::CreateGraphType,
677 CatalogStatement::DropGraphType { .. } => QueryType::DropGraphType,
678 CatalogStatement::AlterGraphType(_) => QueryType::AlterGraphType,
679 CatalogStatement::CreateProcedure(_) => QueryType::CreateProcedure,
680 CatalogStatement::DropProcedure(_) => QueryType::DropProcedure,
681 CatalogStatement::CreateUser { .. } => QueryType::CreateUser,
682 CatalogStatement::DropUser { .. } => QueryType::DropUser,
683 CatalogStatement::CreateRole { .. } => QueryType::CreateRole,
684 CatalogStatement::DropRole { .. } => QueryType::DropRole,
685 CatalogStatement::GrantRole { .. } => QueryType::GrantRole,
686 CatalogStatement::RevokeRole { .. } => QueryType::RevokeRole,
687 CatalogStatement::ClearGraph { .. } => QueryType::ClearGraph,
688 CatalogStatement::TruncateGraph { .. } => QueryType::TruncateGraph,
689 }
690 }
691 crate::ast::Statement::DataStatement(data) => {
692 use crate::ast::DataStatement;
693 match data {
694 DataStatement::Insert { .. } => QueryType::Insert,
695 DataStatement::Set { .. } => QueryType::Set,
696 DataStatement::Remove { .. } => QueryType::Remove,
697 DataStatement::Delete { .. } => QueryType::Delete,
698 DataStatement::MatchInsert { .. } => QueryType::MatchInsert,
699 DataStatement::MatchSet { .. } => QueryType::MatchSet,
700 DataStatement::MatchRemove { .. } => QueryType::MatchRemove,
701 DataStatement::MatchDelete { .. } => QueryType::MatchDelete,
702 }
703 }
704 crate::ast::Statement::SessionStatement(session) => {
705 use crate::ast::{SessionSetClause, SessionStatement};
706 match session {
707 SessionStatement::Set(set_stmt) => match &set_stmt.clause {
708 SessionSetClause::Graph { .. } => QueryType::SessionSetGraph,
709 SessionSetClause::Schema { .. } => QueryType::SessionSetSchema,
710 _ => QueryType::SessionSet,
711 },
712 SessionStatement::Reset(_) => QueryType::SessionReset,
713 SessionStatement::Close(_) => QueryType::SessionClose,
714 }
715 }
716 crate::ast::Statement::TransactionStatement(txn) => {
717 use crate::ast::TransactionStatement;

Callers 1

mainFunction · 0.80

Calls 1

parse_queryFunction · 0.85

Tested by

no test coverage detected