Skip to content

refactor: return an explicit error for unrecognized data types in static schema #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/static_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ pub fn convert_static_schema_to_arrow_schema(
"boolean_list" => {
DataType::List(Arc::new(Field::new("item", DataType::Boolean, true)))
}
_ => DataType::Null,
_ => {
return Err(StaticSchemaError::UnrecognizedDataType(
field.data_type.clone(),
));
}
}
},
nullable: default_nullable(),
Expand Down Expand Up @@ -216,6 +220,9 @@ pub enum StaticSchemaError {

#[error("duplicate field name: {0}")]
DuplicateField(String),

#[error("unrecognized data type: {0}")]
UnrecognizedDataType(String),
}

#[cfg(test)]
Expand All @@ -233,4 +240,24 @@ mod tests {
let _ = validate_field_names("test_field", &mut existing_field_names);
assert!(validate_field_names("test_field", &mut existing_field_names).is_err());
}

#[test]
fn unrecognized_data_type() {
let static_schema = StaticSchema {
fields: vec![SchemaFields {
name: "test_field".to_string(),
data_type: "unknown_type".to_string(),
}],
};

let result = convert_static_schema_to_arrow_schema(static_schema, "", None);

assert!(result.is_err());
match result.unwrap_err() {
StaticSchemaError::UnrecognizedDataType(data_type) => {
assert_eq!(data_type, "unknown_type");
}
_ => panic!("Expected UnrecognizedDataType error"),
}
}
}
Loading