[EPIC] Attach Diagnostic to more errors · Issue #14429 · apache/datafusion (original) (raw)

In #13664 we introduced the Diagnostic type and DataFusionError::Diagnostic. They allow enriching errors with messages meant for consumption by end users of an application built on top of DataFusion, by providing rich information and context that directly references locations in the SQL query. They enable features like:

See datafusion/sql/tests/cases/diagnostic for examples on how to extract and use diagnostics:

#[test]
fn test_table_not_found() -> Result<()> {
let query = "SELECT * FROM /*a*/personx/*a*/";
let spans = get_spans(query);
let diag = do_query(query);
assert_eq!(diag.message, "table 'personx' not found");
assert_eq!(diag.span, Some(spans["a"]));
Ok(())
}

In that PR, we only implemented diagnostics for:

This issue is about using Diagnostic in more places, and adding related tests to datafusion/sql/tests/cases/diagnostic. We think we should at least implement the following, but suggestions are welcome and encouraged:

Describe the solution you'd like

The implementation should follow the steps of #13664, by calling DataFusionError.with_diagnostic to attach a Diagnostic to an error that is currently being returned. Tests should be added to datafusion/sql/tests/cases/diagnostic for each newly supported scenario.

For some of these items, it might be necessary to enrich the logical types with the Span information coming from the parser. This should be done using the datafusion::common::Spans type (note the "s"), introduced in #13664 to add span information to datafusion::common::Column.

It is desirable that the implementation is as little invasive as possible, in that it shouldn't require changing tons of function calls and types, unless absolutely necessary. The public facing API shouldn't change. The Diagnostic should be attached as soon as possible to the creation of the wrapped DataFusionError (i.e. deep in the call stack) and every error should ideally have just one Diagnostic.

Describe alternatives you've considered

No response

Additional context

No response