andygrove commented on code in PR #2711:
URL: https://github.com/apache/arrow-rs/pull/2711#discussion_r968693023
##########
arrow-schema/src/schema.rs:
##########
@@ -205,13 +211,13 @@ impl Schema {
}
/// Find the index of the column with the given name.
- pub fn index_of(&self, name: &str) -> Result<usize> {
+ pub fn index_of(&self, name: &str) -> Result<usize, ArrowSchemaError> {
(0..self.fields.len())
.find(|idx| self.fields[*idx].name() == name)
.ok_or_else(|| {
let valid_fields: Vec<String> =
self.fields.iter().map(|f| f.name().clone()).collect();
- ArrowError::InvalidArgumentError(format!(
+ ArrowSchemaError::Field(format!(
Review Comment:
Given that we are refactoring the error type here, perhaps we could take
this opportunity to also improve it similar to work that has happened in
DataFusion and use an enum for schema errors that allows for better testing and
error reporting. I would be happy to take on this work.
```
/// Schema-related errors
#[derive(Debug)]
pub enum SchemaError {
/// Schema contains a (possibly) qualified and unqualified field with
same unqualified name
AmbiguousReference {
qualifier: Option<String>,
name: String,
},
/// Schema contains duplicate qualified field name
DuplicateQualifiedField { qualifier: String, name: String },
/// Schema contains duplicate unqualified field name
DuplicateUnqualifiedField { name: String },
/// No field with this name
FieldNotFound {
qualifier: Option<String>,
name: String,
valid_fields: Option<Vec<String>>,
},
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]