Skip to content

Commit 7429f7e

Browse files
committed
refactor: return an explicit error for unrecognized data types in static schema conversion
1 parent dc04eb3 commit 7429f7e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/static_schema.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ pub fn convert_static_schema_to_arrow_schema(
124124
"boolean_list" => {
125125
DataType::List(Arc::new(Field::new("item", DataType::Boolean, true)))
126126
}
127-
_ => DataType::Null,
127+
_ => {
128+
return Err(StaticSchemaError::UnrecognizedDataType(
129+
field.data_type.clone(),
130+
));
131+
}
128132
}
129133
},
130134
nullable: default_nullable(),
@@ -216,6 +220,9 @@ pub enum StaticSchemaError {
216220

217221
#[error("duplicate field name: {0}")]
218222
DuplicateField(String),
223+
224+
#[error("unrecognized data type: {0}")]
225+
UnrecognizedDataType(String),
219226
}
220227

221228
#[cfg(test)]
@@ -233,4 +240,24 @@ mod tests {
233240
let _ = validate_field_names("test_field", &mut existing_field_names);
234241
assert!(validate_field_names("test_field", &mut existing_field_names).is_err());
235242
}
243+
244+
#[test]
245+
fn unrecognized_data_type() {
246+
let static_schema = StaticSchema {
247+
fields: vec![SchemaFields {
248+
name: "test_field".to_string(),
249+
data_type: "unknown_type".to_string(),
250+
}],
251+
};
252+
253+
let result = convert_static_schema_to_arrow_schema(static_schema, "", None);
254+
255+
assert!(result.is_err());
256+
match result.unwrap_err() {
257+
StaticSchemaError::UnrecognizedDataType(data_type) => {
258+
assert_eq!(data_type, "unknown_type");
259+
}
260+
_ => panic!("Expected UnrecognizedDataType error"),
261+
}
262+
}
236263
}

0 commit comments

Comments
 (0)