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: Avoid recursive external error wrapping #14371

Merged
merged 16 commits into from
Feb 7, 2025

Conversation

getChan
Copy link
Contributor

@getChan getChan commented Jan 30, 2025

Which issue does this PR close?

Rationale for this change

cause of the issue

In RepartitionExec, it was necessary to wrap the DatafusionError to send it across multiple partitions. However due to the absence of an appropriate error clone method, ExternalError was used. This resulted in a recursive ExternalError.

// wrap it because need to send error to all output partitions
let err = Err(DataFusionError::External(Box::new(Arc::clone(&e))));
tx.send(Some(err)).await.ok();

What changes are included in this PR?

  1. new DatafusionError variant SharedError for sharing source DatafusionError
    1. I couldn't think of an appropriate way to clone source error. If you have any ideas, please let me know.
  2. Replace ExternalError with SharedError in RepartitionExec/JoinExec
  3. Avoid recursive external error wrapping in type conversion.

Are these changes tested?

yes

Are there any user-facing changes?

error message will be changed.

@getChan getChan marked this pull request as draft January 30, 2025 13:44
@github-actions github-actions bot added the common Related to common crate label Jan 30, 2025
@github-actions github-actions bot added the core Core DataFusion crate label Jan 31, 2025
This reverts commit 127705e.
@github-actions github-actions bot removed the core Core DataFusion crate label Jan 31, 2025
@github-actions github-actions bot added physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) labels Feb 1, 2025
INSERT INTO tab0 VALUES(83,0,38);

query error DataFusion error: Arrow error: Divide by zero error
SELECT DISTINCT - 84 FROM tab0 AS cor0 WHERE NOT + 96 / + col1 <= NULL GROUP BY col1, col0;
Copy link
Contributor Author

@getChan getChan Feb 1, 2025

Choose a reason for hiding this comment

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

AS-IS

  • query error DataFusion error: External error: External error: External error: Arrow error: Divide by zero error
  • An ExternalError is added to each RepartitionExec.
스크린샷 2025-02-02 오전 12 05 06

@getChan getChan marked this pull request as ready for review February 1, 2025 16:04
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @getChan !

@@ -131,6 +131,10 @@ pub enum DataFusionError {
/// Errors from either mapping LogicalPlans to/from Substrait plans
/// or serializing/deserializing protobytes to Substrait plans
Substrait(String),

/// Errors for wrapping other errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed (compared to Context for example?) I don't understand why we need to keep the data wrappeed (why don't we just pass the underlying error back?)

Copy link
Contributor Author

@getChan getChan Feb 1, 2025

Choose a reason for hiding this comment

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

Because if we only pass the underlying error, we can't share the error (due to ownership constraints). For example, RepartitionExec needs to send errors to all output partitions. You can see this in the source code.

Ok(Err(e)) => {
let e = Arc::new(e);
for (_, tx) in txs {
// wrap it because need to send error to all output partitions
let err = Err(DataFusionError::External(Box::new(Arc::clone(&e))));
tx.send(Some(err)).await.ok();
}

To share the error, I considered the following.

  1. Implement Clone for DataFusionError and use err.clone(): This is not possible because nested Error types do not implement theClone trait.
  2. Pass Arc<DatafusionError> : I implemented it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If using Context, the underlying error is only passed as a single Result due to ownership constraints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it to SharedError

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you @getChan -- As DataFusionError is used all over the place and is a very visible part of the API I was thinking it would be best if we can avoid adding too many variants. However, after playing with some other options (like deep cloning the error) I agree that this solution is the best.

to be consistent with the other variants which don't have a Error in their name, I renamed this to DataFusionError::Shared

# Conflicts:
#	datafusion/common/src/error.rs
@github-actions github-actions bot added the optimizer Optimizer rules label Feb 3, 2025
@getChan getChan force-pushed the recursive-external-err branch from 88233aa to d4e860f Compare February 3, 2025 00:46
@github-actions github-actions bot removed the optimizer Optimizer rules label Feb 3, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you very much @getChan -- this is a nice usability improvement and I think it is ready to go. It was very nicely done and much appreciated.

I took the liberty of merging this PR up from main and updating some documentation so this is ready to merge.

Thanks again!

@@ -131,6 +131,10 @@ pub enum DataFusionError {
/// Errors from either mapping LogicalPlans to/from Substrait plans
/// or serializing/deserializing protobytes to Substrait plans
Substrait(String),

/// Errors for wrapping other errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you @getChan -- As DataFusionError is used all over the place and is a very visible part of the API I was thinking it would be best if we can avoid adding too many variants. However, after playing with some other options (like deep cloning the error) I agree that this solution is the best.

to be consistent with the other variants which don't have a Error in their name, I renamed this to DataFusionError::Shared

@alamb
Copy link
Contributor

alamb commented Feb 5, 2025

I double checked and we will have to update some expected error messages to get the extended tests passing too.

I made a PR here:

@alamb alamb added the api change Changes the API exposed to users of the crate label Feb 5, 2025
@alamb
Copy link
Contributor

alamb commented Feb 5, 2025

Marking as an API change as this will result in downstream users having to handle a new DataFusionError variants (which is fine, I just want to correctly capture the idea)

@alamb
Copy link
Contributor

alamb commented Feb 7, 2025

Thanks again @getChan

@alamb alamb merged commit c234833 into apache:main Feb 7, 2025
25 checks passed
@alamb
Copy link
Contributor

alamb commented Feb 7, 2025

The extended tests are going to fail on main until we merge apache/datafusion-testing#6 and update the testing pin

@alamb
Copy link
Contributor

alamb commented Feb 7, 2025

The extended tests are going to fail on main until we merge apache/datafusion-testing#6 and update the testing pin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate common Related to common crate physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External Error prefix is repeated multiple times
2 participants