Skip to content

Commit bdf5e17

Browse files
committed
fix: commit schema bug
1 parent cefe210 commit bdf5e17

2 files changed

Lines changed: 34 additions & 24 deletions

File tree

src/event/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,22 @@ impl Event {
8686
}
8787
}
8888

89+
let stream = PARSEABLE.get_or_create_stream(&self.stream_name, &self.tenant_id);
90+
8991
if self.is_first_event {
9092
commit_schema(&self.stream_name, self.rb.schema(), &self.tenant_id)?;
93+
if !stream.get_static_schema_flag() {
94+
stream.stage_schema_file(stream.get_schema().as_ref().clone())?;
95+
}
9196
}
9297

93-
PARSEABLE
94-
.get_or_create_stream(&self.stream_name, &self.tenant_id)
95-
.push(
96-
&key,
97-
&self.rb,
98-
self.parsed_timestamp,
99-
&self.custom_partition_values,
100-
self.stream_type,
101-
)?;
98+
stream.push(
99+
&key,
100+
&self.rb,
101+
self.parsed_timestamp,
102+
&self.custom_partition_values,
103+
self.stream_type,
104+
)?;
102105

103106
let tenant = self.tenant_id.as_deref().unwrap_or(DEFAULT_TENANT);
104107
update_stats(

src/parseable/streams.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)