Skip to content

Commit

Permalink
avoid iterator materialization in column index lookup (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
QP Hou authored Jul 12, 2021
1 parent f7dff76 commit 0a05acf
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions datafusion/src/logical_plan/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl DFSchema {
qualifier: Option<&str>,
name: &str,
) -> Result<usize> {
let matches: Vec<usize> = self
let mut matches = self
.fields
.iter()
.enumerate()
Expand All @@ -164,24 +164,26 @@ impl DFSchema {
// field to lookup is qualified but current field is unqualified.
(Some(_), None) => false,
// field to lookup is unqualified, no need to compare qualifier
_ => field.name() == name,
(None, Some(_)) | (None, None) => field.name() == name,
})
.map(|(idx, _)| idx)
.collect();
.map(|(idx, _)| idx);

match matches.len() {
0 => Err(DataFusionError::Plan(format!(
match matches.next() {
None => Err(DataFusionError::Plan(format!(
"No field named '{}.{}'. Valid fields are {}.",
qualifier.unwrap_or(""),
name,
self.get_field_names()
))),
1 => Ok(matches[0]),
_ => Err(DataFusionError::Internal(format!(
"Ambiguous reference to qualified field named '{}.{}'",
qualifier.unwrap_or(""),
name
))),
Some(idx) => match matches.next() {
None => Ok(idx),
// found more than one matches
Some(_) => Err(DataFusionError::Internal(format!(
"Ambiguous reference to qualified field named '{}.{}'",
qualifier.unwrap_or(""),
name
))),
},
}
}

Expand Down

0 comments on commit 0a05acf

Please sign in to comment.