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

fix: Ignore equal expression names in projection #11

Open
wants to merge 1 commit into
base: cubesql-27-10-2021
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion datafusion/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,6 @@ pub fn project_with_alias(
.push(columnize_expr(normalize_col(e, &plan)?, input_schema)),
}
}
validate_unique_names("Projections", projected_expr.iter(), input_schema)?;
let input_schema = DFSchema::new(exprlist_to_fields(&projected_expr, input_schema)?)?;
let schema = match alias {
Some(ref alias) => input_schema.replace_qualifier(alias.as_str()),
Expand Down
41 changes: 0 additions & 41 deletions datafusion/src/logical_plan/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! DFSchema is an extended schema struct that DataFusion uses to provide support for
//! fields with optional relation names.

use std::collections::HashSet;
use std::convert::TryFrom;
use std::sync::Arc;

Expand Down Expand Up @@ -46,46 +45,6 @@ impl DFSchema {

/// Create a new `DFSchema`
pub fn new(fields: Vec<DFField>) -> Result<Self> {
let mut qualified_names = HashSet::new();
let mut unqualified_names = HashSet::new();

for field in &fields {
if let Some(qualifier) = field.qualifier() {
if !qualified_names.insert((qualifier, field.name())) {
return Err(DataFusionError::Plan(format!(
"Schema contains duplicate qualified field name '{}'",
field.qualified_name()
)));
}
} else if !unqualified_names.insert(field.name()) {
return Err(DataFusionError::Plan(format!(
"Schema contains duplicate unqualified field name '{}'",
field.name()
)));
}
}

// check for mix of qualified and unqualified field with same unqualified name
// note that we need to sort the contents of the HashSet first so that errors are
// deterministic
let mut qualified_names = qualified_names
.iter()
.map(|(l, r)| (l.to_owned(), r.to_owned()))
.collect::<Vec<(&String, &String)>>();
qualified_names.sort_by(|a, b| {
let a = format!("{}.{}", a.0, a.1);
let b = format!("{}.{}", b.0, b.1);
a.cmp(&b)
});
for (qualifier, name) in &qualified_names {
if unqualified_names.contains(name) {
return Err(DataFusionError::Plan(format!(
"Schema contains qualified field name '{}.{}' \
and unqualified field name '{}' which would be ambiguous",
qualifier, name, name
)));
}
}
Ok(Self { fields })
}

Expand Down