Skip to content

Add related source code locations to errors #13662

Closed
@eliaperantoni

Description

@eliaperantoni

Is your feature request related to a problem or challenge?

DataFusionError does not provide information about the location inside the SQL query that caused it. It's difficult for the end user to understand where, in a large query, to go look for the cause of the error.

Example:

WITH products_with_price AS (
	SELECT
		id,
		name,
		price_usd
	FROM
		products
	JOIN
		prices
	ON
		products.id = prices.product_id
)
SELECT
	id,
	name,
	price_usd + '$' AS display_price_usd
FROM
	products_with_price

When creating a logical plan for this query, we'd return:

Cannot coerce arithmetic expression Int64 + Utf8 to valid types

It's up to the user to figure out that the error lies on the third-to-last line.

Describe the solution you'd like

With the AST nodes from the parser now containing the source code location (thanks to apache/datafusion-sqlparser-rs#1435), it now becomes possible to add the same information to errors. This could seriously improve the experience for end users, since they would be able to clearly see where in the queries the errors lie.

In the example above, the desired feature of this ticket would be to add a reference to the third-to-last line, which is the cause of the error: price_usd + '$' AS display_price_usd.

Furthermore, it would be helpful to link to additonal segments of code note that, despite not representing the root cause of the error, help the user understand the context around the error and the elements involved. In this example, we'd highlight the projected price_usd column in the CTE to help the user understand where it comes from.

Describe alternatives you've considered

DataFusionError::Context only adds additional debug strings, but doesn't attach source code location info.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions