@@ -497,28 +497,35 @@ impl Stream {
497497 // check if there is already a schema file in staging pertaining to this stream
498498 // if yes, then merge them and save
499499
500- if let Some ( mut schema) = schema {
500+ if let Some ( schema) = schema {
501501 let static_schema_flag = self . get_static_schema_flag ( ) ;
502502 if !static_schema_flag {
503- // schema is dynamic, read from staging and merge if present
503+ self . stage_schema_file ( schema) ?;
504+ }
505+ }
506+
507+ Ok ( ( ) )
508+ }
504509
505- // need to add something before . schema to make the file have an extension of type `schema`
506- let path = RelativePathBuf :: from_iter ( [ format ! ( "{}.schema" , self . stream_name ) ] )
507- . to_path ( & self . data_path ) ;
510+ pub fn stage_schema_file ( & self , mut schema : Schema ) -> Result < ( ) , StagingError > {
511+ // schema is dynamic, read from staging and merge if present
512+ fs :: create_dir_all ( & self . data_path ) ? ;
508513
509- let staging_schemas = self . get_schemas_if_present ( ) ;
510- if let Some ( mut staging_schemas) = staging_schemas {
511- staging_schemas. push ( schema) ;
512- schema = Schema :: try_merge ( staging_schemas) ?;
513- }
514+ // need to add something before .schema to make the file have an extension of type `schema`
515+ let path = RelativePathBuf :: from_iter ( [ format ! ( "{}.schema" , self . stream_name) ] )
516+ . to_path ( & self . data_path ) ;
514517
515- // save the merged schema on staging disk
516- // the path should be stream/.ingestor.{id}.schema
517- info ! ( "writing schema to path - {path:?}" ) ;
518- write ( path, to_bytes ( & schema) ) ?;
519- }
518+ let staging_schemas = self . get_schemas_if_present ( ) ;
519+ if let Some ( mut staging_schemas) = staging_schemas {
520+ staging_schemas. push ( schema) ;
521+ schema = Schema :: try_merge ( staging_schemas) ?;
520522 }
521523
524+ // save the merged schema on staging disk
525+ // the path should be stream/.ingestor.{id}.schema
526+ info ! ( "writing schema to path - {path:?}" ) ;
527+ write ( path, to_bytes ( & schema) ) ?;
528+
522529 Ok ( ( ) )
523530 }
524531
0 commit comments