Skip to content

Commit 5798b7b

Browse files
author
Devdutt Shenoi
committed
refactor: remove is_schema_matching
1 parent d04ba90 commit 5798b7b

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/event/format/mod.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,18 @@ pub trait EventFormat: Sized {
137137
)),
138138
);
139139

140-
// prepare the record batch and new fields to be added
141-
let mut new_schema = Arc::new(Schema::new(schema));
142-
if !Self::is_schema_matching(new_schema.clone(), storage_schema, static_schema_flag) {
140+
if static_schema_flag
141+
&& schema.iter().any(|field| {
142+
storage_schema
143+
.get(field.name())
144+
.is_none_or(|storage_field| storage_field != field)
145+
})
146+
{
143147
return Err(anyhow!("Schema mismatch"));
144148
}
149+
150+
// prepare the record batch and new fields to be added
151+
let mut new_schema = Arc::new(Schema::new(schema));
145152
new_schema =
146153
update_field_type_in_schema(new_schema, None, time_partition, None, schema_version);
147154

@@ -156,28 +163,6 @@ pub trait EventFormat: Sized {
156163
Ok((rb, is_first))
157164
}
158165

159-
fn is_schema_matching(
160-
new_schema: Arc<Schema>,
161-
storage_schema: &HashMap<String, Arc<Field>>,
162-
static_schema_flag: bool,
163-
) -> bool {
164-
if !static_schema_flag {
165-
return true;
166-
}
167-
for field in new_schema.fields() {
168-
let Some(storage_field) = storage_schema.get(field.name()) else {
169-
return false;
170-
};
171-
if field.name() != storage_field.name() {
172-
return false;
173-
}
174-
if field.data_type() != storage_field.data_type() {
175-
return false;
176-
}
177-
}
178-
true
179-
}
180-
181166
#[allow(clippy::too_many_arguments)]
182167
fn into_event(
183168
self,

0 commit comments

Comments
 (0)