Skip to content
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

avoid iterator materialization in column index lookup #703

Merged
merged 1 commit into from
Jul 12, 2021
Merged
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
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