Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordworms committed Jul 24, 2024
1 parent cb46d65 commit 5a9123f
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions datafusion/sql/src/expr/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let normalize_ident = self.normalizer.normalize(id);

// Check for qualified field with unqualified name
if let Ok((Some(qualifier), _)) =
if let Ok((qualifier, _)) =
schema.qualified_field_with_unqualified_name(normalize_ident.as_str())
{
let is_unnamed_table = match &qualifier {
TableReference::Bare { table } => table.as_ref() == UNNAMED_TABLE,
TableReference::Partial { table, .. } => {
table.as_ref() == UNNAMED_TABLE
}
TableReference::Full { table, .. } => table.as_ref() == UNNAMED_TABLE,
};

if !is_unnamed_table {
// Found a match with a qualified name, return it with the qualifier
return Ok(Expr::Column(Column {
relation: Some(qualifier.clone()),
name: normalize_ident,
}));
}
}

// Check for unqualified field
if schema
.field_with_unqualified_name(normalize_ident.as_str())
.is_ok()
{
// Found a match without a qualified name, this is an inner table column
return Ok(Expr::Column(Column {
relation: None,
relation: qualifier.filter(|q| q.table() != UNNAMED_TABLE).cloned(),
name: normalize_ident,
}));
}
Expand Down

0 comments on commit 5a9123f

Please sign in to comment.