Skip to content

Commit

Permalink
bugfix: fix tpcds_logical_q8 ambiguous name.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener committed Feb 19, 2023
1 parent 6ec2544 commit 76e3537
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 23 additions & 6 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,29 @@ impl DFSchema {
match matches.len() {
0 => Err(field_not_found(None, name, self)),
1 => Ok(matches[0]),
_ => Err(DataFusionError::SchemaError(
SchemaError::AmbiguousReference {
qualifier: None,
name: name.to_string(),
},
)),
_ => {
// When `matches` size>1, it does not necessarily mean an `ambiguous name` problem.
// Because name may generate from Alias/... . It means that it don't own qualifier.
// For example:
// Join on id = b.id
// Project a.id as id TableScan b id
// In this case, there isn't `ambiguous name` problem. When `matches` just contains
// one field without qualifier, we should return it.
let fields_without_qualifier = matches
.iter()
.filter(|f| f.qualifier.is_none())
.collect::<Vec<_>>();
if fields_without_qualifier.len() == 1 {
Ok(fields_without_qualifier[0])
} else {
Err(DataFusionError::SchemaError(
SchemaError::AmbiguousReference {
qualifier: None,
name: name.to_string(),
},
))
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub fn only_or_err<T>(slice: &[T]) -> Result<&T> {
/// Rewrites `expr` using `rewriter`, ensuring that the output has the
/// same name as `expr` prior to rewrite, adding an alias if necessary.
///
/// This is important when optimzing plans to ensure the the output
/// This is important when optimizing plans to ensure the the output
/// schema of plan nodes don't change after optimization
pub fn rewrite_preserving_name<R>(expr: Expr, rewriter: &mut R) -> Result<Expr>
where
Expand Down

0 comments on commit 76e3537

Please sign in to comment.