Skip to main content

nodedb_sql/visitor/plan_visitor/
dispatch_rest.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Second half of the exhaustive [`SqlPlan`] → [`PlanVisitor`] dispatcher.
3//!
4//! Handles set-ops, array DDL/DML/TVF, merge, lateral, and index-DDL
5//! variants. Called only from [`super::dispatch::dispatch`]'s trailing
6//! `other => dispatch_rest(visitor, other)` arm; the variants handled there
7//! reach the trailing `unreachable!()` arm here, which exists solely to
8//! satisfy the compiler that this match is exhaustive over the full
9//! `SqlPlan` enum without repeating their field lists.
10use super::args::{
11    CreateArrayVisitArgs, LateralLoopVisitArgs, LateralTopKVisitArgs, MergeVisitArgs,
12};
13use super::trait_def::PlanVisitor;
14use crate::types::SqlPlan;
15
16pub(super) fn dispatch_rest<V: PlanVisitor>(
17    visitor: &mut V,
18    plan: &SqlPlan,
19) -> Result<V::Output, V::Error> {
20    match plan {
21        SqlPlan::Union { inputs, distinct } => visitor.union(inputs, *distinct),
22        SqlPlan::Intersect { left, right, all } => visitor.intersect(left, right, *all),
23        SqlPlan::Except { left, right, all } => visitor.except(left, right, *all),
24        SqlPlan::Cte { definitions, outer } => visitor.cte(definitions, outer),
25        SqlPlan::CreateArray {
26            name,
27            dims,
28            attrs,
29            tile_extents,
30            cell_order,
31            tile_order,
32            prefix_bits,
33            audit_retain_ms,
34            minimum_audit_retain_ms,
35        } => visitor.create_array(CreateArrayVisitArgs {
36            name,
37            dims,
38            attrs,
39            tile_extents,
40            cell_order: *cell_order,
41            tile_order: *tile_order,
42            prefix_bits: *prefix_bits,
43            audit_retain_ms: *audit_retain_ms,
44            minimum_audit_retain_ms: *minimum_audit_retain_ms,
45        }),
46        SqlPlan::DropArray { name, if_exists } => visitor.drop_array(name, *if_exists),
47        SqlPlan::AlterArray {
48            name,
49            audit_retain_ms,
50            minimum_audit_retain_ms,
51        } => visitor.alter_array(name, *audit_retain_ms, *minimum_audit_retain_ms),
52        SqlPlan::InsertArray { name, rows } => visitor.insert_array(name, rows),
53        SqlPlan::DeleteArray { name, coords } => visitor.delete_array(name, coords),
54        SqlPlan::ArraySlice {
55            name,
56            slice,
57            attr_projection,
58            limit,
59            temporal,
60        } => visitor.array_slice(name, slice, attr_projection, *limit, temporal),
61        SqlPlan::ArrayProject {
62            name,
63            attr_projection,
64        } => visitor.array_project(name, attr_projection),
65        SqlPlan::ArrayAgg {
66            name,
67            attr,
68            reducer,
69            group_by_dim,
70            temporal,
71        } => visitor.array_agg(name, attr, reducer, group_by_dim.as_deref(), temporal),
72        SqlPlan::ArrayElementwise {
73            left,
74            right,
75            op,
76            attr,
77        } => visitor.array_elementwise(left, right, *op, attr),
78        SqlPlan::ArrayFlush { name } => visitor.array_flush(name),
79        SqlPlan::ArrayCompact { name } => visitor.array_compact(name),
80        SqlPlan::Merge {
81            target,
82            engine,
83            source,
84            target_join_col,
85            source_join_col,
86            source_alias,
87            clauses,
88            returning,
89        } => visitor.merge(MergeVisitArgs {
90            target,
91            engine: *engine,
92            source,
93            target_join_col,
94            source_join_col,
95            source_alias,
96            clauses,
97            returning: *returning,
98        }),
99        SqlPlan::LateralTopK {
100            outer,
101            outer_alias,
102            inner_collection,
103            inner_filters,
104            inner_order_by,
105            inner_limit,
106            correlation_keys,
107            lateral_alias,
108            projection,
109            left_join,
110        } => visitor.lateral_top_k(LateralTopKVisitArgs {
111            outer,
112            outer_alias: outer_alias.as_deref(),
113            inner_collection,
114            inner_filters,
115            inner_order_by,
116            inner_limit: *inner_limit,
117            correlation_keys,
118            lateral_alias,
119            projection,
120            left_join: *left_join,
121        }),
122        SqlPlan::LateralLoop {
123            outer,
124            outer_alias,
125            inner,
126            correlation_predicates,
127            lateral_alias,
128            projection,
129            outer_row_cap,
130            left_join,
131        } => visitor.lateral_loop(LateralLoopVisitArgs {
132            outer,
133            outer_alias: outer_alias.as_deref(),
134            inner,
135            correlation_predicates,
136            lateral_alias,
137            projection,
138            outer_row_cap: *outer_row_cap,
139            left_join: *left_join,
140        }),
141        SqlPlan::VectorPrimaryInsert {
142            collection,
143            field,
144            quantization,
145            storage_dtype,
146            payload_indexes,
147            rows,
148        } => visitor.vector_primary_insert(
149            collection,
150            field,
151            quantization,
152            storage_dtype,
153            payload_indexes,
154            rows,
155        ),
156        SqlPlan::CreateIndex {
157            index_name,
158            collection,
159            field,
160            unique,
161            if_not_exists,
162            case_insensitive,
163        } => visitor.create_index(
164            index_name.as_deref(),
165            collection,
166            field,
167            *unique,
168            *if_not_exists,
169            *case_insensitive,
170        ),
171        SqlPlan::DropIndex {
172            index_name,
173            collection,
174            if_exists,
175        } => visitor.drop_index(index_name, collection.as_deref(), *if_exists),
176        _ => unreachable!(
177            "dispatch() already handles every remaining SqlPlan variant before forwarding here"
178        ),
179    }
180}