@@ -22,10 +22,8 @@ use std::{
2222use crate :: {
2323 graph_catalog:: { graph_schema:: GraphSchema , pattern_schema:: PatternSchemaContext } ,
2424 query_planner:: {
25- analyzer:: property_requirements:: PropertyRequirements ,
26- join_context:: VlpEndpointInfo ,
27- logical_plan:: ProjectionItem ,
28- typed_variable:: VariableRegistry ,
25+ analyzer:: property_requirements:: PropertyRequirements , join_context:: VlpEndpointInfo ,
26+ logical_plan:: ProjectionItem , typed_variable:: VariableRegistry ,
2927 } ,
3028} ;
3129
@@ -37,14 +35,14 @@ use super::{PlanCtx, TableCtx};
3735pub struct PlanCtxBuilder {
3836 // Required
3937 schema : Arc < GraphSchema > ,
40-
38+
4139 // Optional with defaults
4240 tenant_id : Option < String > ,
4341 view_parameter_values : Option < HashMap < String , String > > ,
4442 max_inferred_types : usize ,
4543 parent_scope : Option < Box < PlanCtx > > ,
4644 is_with_scope : bool ,
47-
45+
4846 // Internal state (typically defaults)
4947 alias_table_ctx_map : HashMap < String , TableCtx > ,
5048 optional_aliases : HashSet < String > ,
@@ -80,7 +78,7 @@ impl PlanCtxBuilder {
8078 cte_alias_sources : HashMap :: new ( ) ,
8179 }
8280 }
83-
81+
8482 /// Create a builder from a parent scope (for WITH clause scoping).
8583 /// Inherits schema, tenant_id, view_parameters, and vlp_endpoints.
8684 pub fn from_parent ( parent : & PlanCtx , is_with_scope : bool ) -> Self {
@@ -103,85 +101,85 @@ impl PlanCtxBuilder {
103101 cte_alias_sources : HashMap :: new ( ) ,
104102 }
105103 }
106-
104+
107105 /// Set the tenant ID for multi-tenant deployments.
108106 pub fn tenant_id ( mut self , tenant_id : impl Into < String > ) -> Self {
109107 self . tenant_id = Some ( tenant_id. into ( ) ) ;
110108 self
111109 }
112-
110+
113111 /// Set the tenant ID optionally.
114112 pub fn tenant_id_opt ( mut self , tenant_id : Option < String > ) -> Self {
115113 self . tenant_id = tenant_id;
116114 self
117115 }
118-
116+
119117 /// Set view parameter values for parameterized views.
120118 pub fn view_parameters ( mut self , params : HashMap < String , String > ) -> Self {
121119 self . view_parameter_values = Some ( params) ;
122120 self
123121 }
124-
122+
125123 /// Set view parameter values optionally.
126124 pub fn view_parameters_opt ( mut self , params : Option < HashMap < String , String > > ) -> Self {
127125 self . view_parameter_values = params;
128126 self
129127 }
130-
128+
131129 /// Set maximum number of inferred edge types.
132130 pub fn max_inferred_types ( mut self , max : usize ) -> Self {
133131 self . max_inferred_types = max;
134132 self
135133 }
136-
134+
137135 /// Mark this scope as a WITH scope (barrier for variable lookup).
138136 pub fn as_with_scope ( mut self ) -> Self {
139137 self . is_with_scope = true ;
140138 self
141139 }
142-
140+
143141 /// Set the parent scope explicitly.
144142 pub fn parent_scope ( mut self , parent : PlanCtx ) -> Self {
145143 self . parent_scope = Some ( Box :: new ( parent) ) ;
146144 self
147145 }
148-
146+
149147 /// Initialize with existing table contexts.
150148 pub fn with_table_contexts ( mut self , contexts : HashMap < String , TableCtx > ) -> Self {
151149 self . alias_table_ctx_map = contexts;
152150 self
153151 }
154-
152+
155153 /// Initialize with existing optional aliases.
156154 pub fn with_optional_aliases ( mut self , aliases : HashSet < String > ) -> Self {
157155 self . optional_aliases = aliases;
158156 self
159157 }
160-
158+
161159 /// Set the CTE counter (for generating unique CTE names).
162160 pub fn cte_counter ( mut self , counter : usize ) -> Self {
163161 self . cte_counter = counter;
164162 self
165163 }
166-
164+
167165 /// Set property requirements.
168166 pub fn property_requirements ( mut self , requirements : PropertyRequirements ) -> Self {
169167 self . property_requirements = Some ( requirements) ;
170168 self
171169 }
172-
170+
173171 /// Set VLP endpoints.
174172 pub fn vlp_endpoints ( mut self , endpoints : HashMap < String , VlpEndpointInfo > ) -> Self {
175173 self . vlp_endpoints = endpoints;
176174 self
177175 }
178-
176+
179177 /// Set the variable registry.
180178 pub fn variables ( mut self , registry : VariableRegistry ) -> Self {
181179 self . variables = registry;
182180 self
183181 }
184-
182+
185183 /// Build the PlanCtx instance.
186184 pub fn build ( self ) -> PlanCtx {
187185 PlanCtx {
@@ -211,7 +209,7 @@ impl PlanCtxBuilder {
211209#[ cfg( test) ]
212210mod tests {
213211 use super :: * ;
214-
212+
215213 fn make_test_schema ( ) -> Arc < GraphSchema > {
216214 Arc :: new ( GraphSchema :: build (
217215 1 ,
@@ -220,67 +218,63 @@ mod tests {
220218 HashMap :: new ( ) ,
221219 ) )
222220 }
223-
221+
224222 #[ test]
225223 fn test_builder_minimal ( ) {
226224 let schema = make_test_schema ( ) ;
227225 let ctx = PlanCtxBuilder :: new ( schema. clone ( ) ) . build ( ) ;
228-
226+
229227 assert_eq ! ( ctx. schema( ) . database( ) , "test" ) ;
230228 assert ! ( ctx. tenant_id. is_none( ) ) ;
231229 assert_eq ! ( ctx. max_inferred_types, 5 ) ;
232230 }
233-
231+
234232 #[ test]
235233 fn test_builder_with_tenant ( ) {
236234 let schema = make_test_schema ( ) ;
237- let ctx = PlanCtxBuilder :: new ( schema)
238- . tenant_id ( "tenant-123" )
239- . build ( ) ;
240-
235+ let ctx = PlanCtxBuilder :: new ( schema) . tenant_id ( "tenant-123" ) . build ( ) ;
236+
241237 assert_eq ! ( ctx. tenant_id, Some ( "tenant-123" . to_string( ) ) ) ;
242238 }
243-
239+
244240 #[ test]
245241 fn test_builder_with_all_params ( ) {
246242 let schema = make_test_schema ( ) ;
247243 let mut params = HashMap :: new ( ) ;
248244 params. insert ( "region" . to_string ( ) , "US" . to_string ( ) ) ;
249-
245+
250246 let ctx = PlanCtxBuilder :: new ( schema)
251247 . tenant_id ( "tenant-123" )
252248 . view_parameters ( params. clone ( ) )
253249 . max_inferred_types ( 10 )
254250 . build ( ) ;
255-
251+
256252 assert_eq ! ( ctx. tenant_id, Some ( "tenant-123" . to_string( ) ) ) ;
257253 assert_eq ! ( ctx. view_parameter_values, Some ( params) ) ;
258254 assert_eq ! ( ctx. max_inferred_types, 10 ) ;
259255 }
260-
256+
261257 #[ test]
262258 fn test_builder_from_parent ( ) {
263259 let schema = make_test_schema ( ) ;
264260 let parent = PlanCtxBuilder :: new ( schema. clone ( ) )
265261 . tenant_id ( "parent-tenant" )
266262 . max_inferred_types ( 15 )
267263 . build ( ) ;
268-
264+
269265 let child = PlanCtxBuilder :: from_parent ( & parent, true ) . build ( ) ;
270-
266+
271267 assert_eq ! ( child. tenant_id, Some ( "parent-tenant" . to_string( ) ) ) ;
272268 assert_eq ! ( child. max_inferred_types, 15 ) ;
273269 assert ! ( child. is_with_scope) ;
274270 assert ! ( child. parent_scope. is_some( ) ) ;
275271 }
276-
272+
277273 #[ test]
278274 fn test_builder_as_with_scope ( ) {
279275 let schema = make_test_schema ( ) ;
280- let ctx = PlanCtxBuilder :: new ( schema)
281- . as_with_scope ( )
282- . build ( ) ;
283-
276+ let ctx = PlanCtxBuilder :: new ( schema) . as_with_scope ( ) . build ( ) ;
277+
284278 assert ! ( ctx. is_with_scope) ;
285279 }
286280}
0 commit comments