Skip to content

[wip] attach diagnostic to duplicate table name error #14767

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 9 additions & 2 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use std::sync::Arc;

use crate::error::{DataFusionError, Result, _plan_err, _schema_err};
use crate::{
field_not_found, unqualified_field_not_found, Column, FunctionalDependencies,
SchemaError, TableReference,
field_not_found, unqualified_field_not_found, Column, Diagnostic,
FunctionalDependencies, SchemaError, TableReference,
};

use arrow::compute::can_cast_types;
Expand Down Expand Up @@ -230,6 +230,13 @@ impl DFSchema {
return _schema_err!(SchemaError::DuplicateQualifiedField {
qualifier: Box::new(qualifier.clone()),
name: field.name().to_string(),
})
.map_err(|err| {
let diagnostic = Diagnostic::new_error(
format!("duplicate qualified field name '{}'", field.name()),
None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @eliaperantoni, I have some doubts in the implementation process and hope to get some help.

When constructing Diagnostic error, how should I get the location where the error occurred, that is, how to construct Span here? 🤔

);
err.with_diagnostic(diagnostic)
});
}
} else if !unqualified_names.insert(field.name()) {
Expand Down
8 changes: 8 additions & 0 deletions datafusion/sql/tests/cases/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ fn get_spans(query: &'static str) -> HashMap<String, Span> {
spans
}

#[test]
fn test_table_duplicate_name() -> Result<()> {
let query = "SELECT /*a*/id/*a*/ FROM person a, person a";
let diag = do_query(query);
assert_eq!(diag.message, "duplicate qualified field name 'id'");
Ok(())
}

#[test]
fn test_table_not_found() -> Result<()> {
let query = "SELECT * FROM /*a*/personx/*a*/";
Expand Down
Loading