@@ -139,6 +139,31 @@ impl TableRegistry {
139139 }
140140 }
141141
142+ /// Load compile-only table placeholders into the registry.
143+ ///
144+ /// These placeholders are useful when compiling VRL in contexts that must
145+ /// not load external enrichment table data. Compilation only needs table
146+ /// names and index registration; runtime lookups still fail against these
147+ /// placeholders.
148+ pub fn load_compile_time_table_ids < I , S > ( & self , table_ids : I )
149+ where
150+ I : IntoIterator < Item = S > ,
151+ S : Into < String > ,
152+ {
153+ let tables = table_ids
154+ . into_iter ( )
155+ . map ( |table_id| {
156+ let table_id = table_id. into ( ) ;
157+ (
158+ table_id. clone ( ) ,
159+ Box :: new ( CompileTimeTable :: new ( table_id) ) as Box < dyn Table + Send + Sync > ,
160+ )
161+ } )
162+ . collect ( ) ;
163+
164+ self . load ( tables) ;
165+ }
166+
142167 /// Adds an index to the given Enrichment Table.
143168 ///
144169 /// If we are in the reading stage, this function will error.
@@ -204,6 +229,68 @@ impl std::fmt::Debug for TableRegistry {
204229 }
205230}
206231
232+ #[ derive( Clone , Debug ) ]
233+ struct CompileTimeTable {
234+ name : String ,
235+ indexes : Vec < ( Case , Vec < String > ) > ,
236+ }
237+
238+ impl CompileTimeTable {
239+ fn new ( name : String ) -> Self {
240+ Self {
241+ name,
242+ indexes : Vec :: new ( ) ,
243+ }
244+ }
245+
246+ fn lookup_error ( & self ) -> Error {
247+ Error :: TableNotLoaded {
248+ table : self . name . clone ( ) ,
249+ }
250+ }
251+ }
252+
253+ impl Table for CompileTimeTable {
254+ fn find_table_row < ' a > (
255+ & self ,
256+ _case : Case ,
257+ _condition : & ' a [ Condition < ' a > ] ,
258+ _select : Option < & [ String ] > ,
259+ _wildcard : Option < & Value > ,
260+ _index : Option < IndexHandle > ,
261+ ) -> Result < ObjectMap , Error > {
262+ Err ( self . lookup_error ( ) )
263+ }
264+
265+ fn find_table_rows < ' a > (
266+ & self ,
267+ _case : Case ,
268+ _condition : & ' a [ Condition < ' a > ] ,
269+ _select : Option < & [ String ] > ,
270+ _wildcard : Option < & Value > ,
271+ _index : Option < IndexHandle > ,
272+ ) -> Result < Vec < ObjectMap > , Error > {
273+ Err ( self . lookup_error ( ) )
274+ }
275+
276+ fn add_index ( & mut self , case : Case , fields : & [ & str ] ) -> Result < IndexHandle , Error > {
277+ let handle = IndexHandle ( self . indexes . len ( ) ) ;
278+ self . indexes . push ( (
279+ case,
280+ fields. iter ( ) . map ( |field| ( * field) . to_owned ( ) ) . collect ( ) ,
281+ ) ) ;
282+ Ok ( handle)
283+ }
284+
285+ fn index_fields ( & self ) -> Vec < ( Case , Vec < String > ) > {
286+ self . indexes . clone ( )
287+ }
288+
289+ fn needs_reload ( & self ) -> bool {
290+ false
291+ }
292+ }
293+
207294/// Provides read only access to the enrichment tables via the
208295/// `vrl::EnrichmentTableSearch` trait. Cloning this object is designed to be
209296/// cheap. The underlying data will be shared by all clones.
0 commit comments