Skip to main content

nodedb_sql/visitor/plan_visitor/
args.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Parameter structs for [`super::trait_def::PlanVisitor`] methods whose
4//! `SqlPlan` variant carries enough fields to exceed clippy's
5//! `too_many_arguments` threshold. Each struct bundles one method's
6//! parameters (minus `&mut self`) so the trait method itself stays under
7//! the arg-count cap while still exposing every field to implementors.
8
9use crate::temporal::TemporalScope;
10use crate::types::SqlPlan;
11use crate::types::filter::Filter;
12use crate::types::plan::{ArrayPrefilter, MergePlanClause, VectorAnnOptions};
13use crate::types::query::{
14    AggregateExpr, EngineType, JoinType, Projection, SortKey, SpatialPredicate, WindowSpec,
15};
16use crate::types_array::{ArrayAttrAst, ArrayCellOrderAst, ArrayDimAst, ArrayTileOrderAst};
17use crate::types_expr::{SqlExpr, SqlPayloadAtom, SqlValue};
18use nodedb_types::vector_distance::DistanceMetric;
19
20/// Parameters for [`super::trait_def::PlanVisitor::scan`].
21pub struct ScanVisitArgs<'a> {
22    pub collection: &'a str,
23    pub alias: Option<&'a str>,
24    pub engine: EngineType,
25    pub filters: &'a [Filter],
26    pub projection: &'a [Projection],
27    pub sort_keys: &'a [SortKey],
28    pub limit: Option<usize>,
29    pub offset: usize,
30    pub distinct: bool,
31    pub window_functions: &'a [WindowSpec],
32    pub temporal: &'a TemporalScope,
33}
34
35/// Parameters for [`super::trait_def::PlanVisitor::document_index_lookup`].
36pub struct DocumentIndexLookupVisitArgs<'a> {
37    pub collection: &'a str,
38    pub alias: Option<&'a str>,
39    pub engine: EngineType,
40    pub field: &'a str,
41    pub value: &'a SqlValue,
42    pub filters: &'a [Filter],
43    pub projection: &'a [Projection],
44    pub sort_keys: &'a [SortKey],
45    pub limit: Option<usize>,
46    pub offset: usize,
47    pub distinct: bool,
48    pub window_functions: &'a [WindowSpec],
49    pub case_insensitive: bool,
50    pub temporal: &'a TemporalScope,
51}
52
53/// Parameters for [`super::trait_def::PlanVisitor::insert`].
54pub struct InsertVisitArgs<'a> {
55    pub collection: &'a str,
56    pub engine: EngineType,
57    pub rows: &'a [Vec<(String, SqlValue)>],
58    pub column_defaults: &'a [(String, String)],
59    pub if_absent: bool,
60    pub column_schema: &'a [(String, String)],
61    pub primary_key: Option<&'a str>,
62}
63
64/// Parameters for [`super::trait_def::PlanVisitor::upsert`].
65pub struct UpsertVisitArgs<'a> {
66    pub collection: &'a str,
67    pub engine: EngineType,
68    pub rows: &'a [Vec<(String, SqlValue)>],
69    pub column_defaults: &'a [(String, String)],
70    pub on_conflict_updates: &'a [(String, SqlExpr)],
71    pub column_schema: &'a [(String, String)],
72    pub primary_key: Option<&'a str>,
73}
74
75/// Parameters for [`super::trait_def::PlanVisitor::update_from`].
76pub struct UpdateFromVisitArgs<'a> {
77    pub collection: &'a str,
78    pub engine: EngineType,
79    pub source: &'a SqlPlan,
80    pub target_join_col: &'a str,
81    pub source_join_col: &'a str,
82    pub assignments: &'a [(String, SqlExpr)],
83    pub target_filters: &'a [Filter],
84    pub returning: bool,
85}
86
87/// Parameters for [`super::trait_def::PlanVisitor::join`].
88pub struct JoinVisitArgs<'a> {
89    pub left: &'a SqlPlan,
90    pub right: &'a SqlPlan,
91    pub on: &'a [(String, String)],
92    pub join_type: JoinType,
93    pub condition: Option<&'a SqlExpr>,
94    pub limit: Option<usize>,
95    pub projection: &'a [Projection],
96    pub filters: &'a [Filter],
97}
98
99/// Parameters for [`super::trait_def::PlanVisitor::aggregate`].
100pub struct AggregateVisitArgs<'a> {
101    pub input: &'a SqlPlan,
102    pub group_by: &'a [SqlExpr],
103    pub aggregates: &'a [AggregateExpr],
104    pub having: &'a [Filter],
105    pub limit: usize,
106    pub grouping_sets: Option<&'a [Vec<usize>]>,
107    pub sort_keys: &'a [SortKey],
108}
109
110/// Parameters for [`super::trait_def::PlanVisitor::timeseries_scan`].
111pub struct TimeseriesScanVisitArgs<'a> {
112    pub collection: &'a str,
113    pub time_range: (i64, i64),
114    pub bucket_interval_ms: i64,
115    pub group_by: &'a [String],
116    pub aggregates: &'a [AggregateExpr],
117    pub filters: &'a [Filter],
118    pub projection: &'a [Projection],
119    pub gap_fill: &'a str,
120    pub limit: usize,
121    pub tiered: bool,
122    pub temporal: &'a TemporalScope,
123}
124
125/// Parameters for [`super::trait_def::PlanVisitor::vector_search`].
126pub struct VectorSearchVisitArgs<'a> {
127    pub collection: &'a str,
128    pub field: &'a str,
129    pub query_vector: &'a [f32],
130    pub top_k: usize,
131    pub ef_search: usize,
132    pub metric: DistanceMetric,
133    pub filters: &'a [Filter],
134    pub array_prefilter: Option<&'a ArrayPrefilter>,
135    pub ann_options: &'a VectorAnnOptions,
136    pub skip_payload_fetch: bool,
137    pub payload_filters: &'a [SqlPayloadAtom],
138}
139
140/// Parameters for [`super::trait_def::PlanVisitor::hybrid_search`].
141pub struct HybridSearchVisitArgs<'a> {
142    pub collection: &'a str,
143    pub query_vector: &'a [f32],
144    pub query_text: &'a str,
145    pub top_k: usize,
146    pub ef_search: usize,
147    pub vector_weight: f32,
148    pub fuzzy: bool,
149    pub score_alias: Option<&'a str>,
150}
151
152/// Parameters for [`super::trait_def::PlanVisitor::hybrid_search_triple`].
153pub struct HybridSearchTripleVisitArgs<'a> {
154    pub collection: &'a str,
155    pub query_vector: &'a [f32],
156    pub query_text: &'a str,
157    pub graph_seed_id: &'a str,
158    pub graph_depth: usize,
159    pub graph_edge_label: Option<&'a str>,
160    pub top_k: usize,
161    pub ef_search: usize,
162    pub fuzzy: bool,
163    pub rrf_k: (f64, f64, f64),
164    pub score_alias: Option<&'a str>,
165}
166
167/// Parameters for [`super::trait_def::PlanVisitor::spatial_scan`].
168pub struct SpatialScanVisitArgs<'a> {
169    pub collection: &'a str,
170    pub field: &'a str,
171    pub predicate: &'a SpatialPredicate,
172    pub query_geometry: &'a nodedb_types::geometry::Geometry,
173    pub distance_meters: f64,
174    pub attribute_filters: &'a [Filter],
175    pub limit: usize,
176    pub projection: &'a [Projection],
177}
178
179/// Parameters for [`super::trait_def::PlanVisitor::recursive_scan`].
180pub struct RecursiveScanVisitArgs<'a> {
181    pub collection: &'a str,
182    pub base_filters: &'a [Filter],
183    pub recursive_filters: &'a [Filter],
184    pub join_link: Option<&'a (String, String)>,
185    pub max_iterations: usize,
186    pub distinct: bool,
187    pub limit: usize,
188}
189
190/// Parameters for [`super::trait_def::PlanVisitor::recursive_value`].
191pub struct RecursiveValueVisitArgs<'a> {
192    pub cte_name: &'a str,
193    pub columns: &'a [String],
194    pub init_exprs: &'a [String],
195    pub step_exprs: &'a [String],
196    pub condition: Option<&'a str>,
197    pub max_depth: usize,
198    pub distinct: bool,
199}
200
201/// Parameters for [`super::trait_def::PlanVisitor::create_array`].
202pub struct CreateArrayVisitArgs<'a> {
203    pub name: &'a str,
204    pub dims: &'a [ArrayDimAst],
205    pub attrs: &'a [ArrayAttrAst],
206    pub tile_extents: &'a [i64],
207    pub cell_order: ArrayCellOrderAst,
208    pub tile_order: ArrayTileOrderAst,
209    pub prefix_bits: u8,
210    pub audit_retain_ms: Option<u64>,
211    pub minimum_audit_retain_ms: Option<u64>,
212}
213
214/// Parameters for [`super::trait_def::PlanVisitor::merge`].
215pub struct MergeVisitArgs<'a> {
216    pub target: &'a str,
217    pub engine: EngineType,
218    pub source: &'a SqlPlan,
219    pub target_join_col: &'a str,
220    pub source_join_col: &'a str,
221    pub source_alias: &'a str,
222    pub clauses: &'a [MergePlanClause],
223    pub returning: bool,
224}
225
226/// Parameters for [`super::trait_def::PlanVisitor::lateral_top_k`].
227pub struct LateralTopKVisitArgs<'a> {
228    pub outer: &'a SqlPlan,
229    pub outer_alias: Option<&'a str>,
230    pub inner_collection: &'a str,
231    pub inner_filters: &'a [Filter],
232    pub inner_order_by: &'a [SortKey],
233    pub inner_limit: usize,
234    pub correlation_keys: &'a [(String, String)],
235    pub lateral_alias: &'a str,
236    pub projection: &'a [Projection],
237    pub left_join: bool,
238}
239
240/// Parameters for [`super::trait_def::PlanVisitor::lateral_loop`].
241pub struct LateralLoopVisitArgs<'a> {
242    pub outer: &'a SqlPlan,
243    pub outer_alias: Option<&'a str>,
244    pub inner: &'a SqlPlan,
245    pub correlation_predicates: &'a [(String, String)],
246    pub lateral_alias: &'a str,
247    pub projection: &'a [Projection],
248    pub outer_row_cap: usize,
249    pub left_join: bool,
250}