velesdb_core/collection/graph_collection_query.rs
1//! VelesQL query execution for [`GraphCollection`].
2
3use std::collections::HashMap;
4
5use crate::collection::search::query::match_exec::MatchResult;
6use crate::error::Result;
7use crate::point::SearchResult;
8
9use super::graph_collection::GraphCollection;
10
11impl GraphCollection {
12 /// Executes a parsed `VelesQL` query.
13 ///
14 /// # Errors
15 ///
16 /// Returns an error if the query is invalid or execution fails.
17 pub fn execute_query(
18 &self,
19 query: &crate::velesql::Query,
20 params: &HashMap<String, serde_json::Value>,
21 ) -> Result<Vec<SearchResult>> {
22 self.inner.execute_query(query, params)
23 }
24
25 /// Executes a query with instrumentation and returns plan + actual stats.
26 ///
27 /// Delegates to [`crate::Database::explain_analyze_query`].
28 ///
29 /// # Errors
30 ///
31 /// Returns an error if the query is invalid or execution fails.
32 pub fn explain_analyze_query(
33 &self,
34 query: &crate::velesql::Query,
35 params: &HashMap<String, serde_json::Value>,
36 ) -> Result<crate::velesql::ExplainOutput> {
37 self.inner.explain_analyze_query(query, params)
38 }
39
40 /// Executes a raw VelesQL string, parsing it before execution.
41 ///
42 /// # Errors
43 ///
44 /// - Returns an error if the SQL string cannot be parsed.
45 /// - Returns an error if query execution fails.
46 pub fn execute_query_str(
47 &self,
48 sql: &str,
49 params: &HashMap<String, serde_json::Value>,
50 ) -> Result<Vec<SearchResult>> {
51 self.inner.execute_query_str(sql, params)
52 }
53
54 /// Executes a MATCH graph pattern query.
55 ///
56 /// # Errors
57 ///
58 /// Returns an error if the query cannot be executed.
59 pub fn execute_match(
60 &self,
61 match_clause: &crate::velesql::MatchClause,
62 params: &HashMap<String, serde_json::Value>,
63 ) -> Result<Vec<MatchResult>> {
64 self.inner.execute_match(match_clause, params)
65 }
66
67 /// Executes a MATCH query with vector similarity scoring.
68 ///
69 /// # Errors
70 ///
71 /// Returns an error on dimension mismatch or execution failure.
72 pub fn execute_match_with_similarity(
73 &self,
74 match_clause: &crate::velesql::MatchClause,
75 query_vector: &[f32],
76 similarity_threshold: f32,
77 params: &HashMap<String, serde_json::Value>,
78 ) -> Result<Vec<MatchResult>> {
79 self.inner.execute_match_with_similarity(
80 match_clause,
81 query_vector,
82 similarity_threshold,
83 params,
84 )
85 }
86
87 /// Executes a MATCH query through the cost-based planner, returning ordered
88 /// [`MatchResult`]s with RETURN `ORDER BY`, deterministic tie-break, and
89 /// post-sort LIMIT applied — identical to the SQL `/query` path (backlog #1).
90 ///
91 /// This is the single ordered-MATCH entry point non-SQL surfaces should
92 /// route through so every surface ranks identically.
93 ///
94 /// # Errors
95 ///
96 /// Returns an error if a guard-rail pre-check fails, or if traversal,
97 /// ordering, or execution fails.
98 pub fn match_query_ordered(
99 &self,
100 match_clause: &crate::velesql::MatchClause,
101 params: &HashMap<String, serde_json::Value>,
102 ) -> Result<Vec<MatchResult>> {
103 self.inner.match_query_ordered(match_clause, params)
104 }
105}