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

chore: Refactoring of CometError/SparkError #655

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Jul 11, 2024

Which issue does this PR close?

Part of #630

Rationale for this change

These changes are extracted from the larger WIP PR #654 and are a first step to being able to move the cast expression to the new spark-expr crate.

What changes are included in this PR?

  • Move SparkError into its own source file
  • Move variants ArithmeticOverflow, CastInvalidValue, CastOverFlow, and NumericValueOutOfRange from CometError to SparkError
  • Add new CometError::Spark(SparkError) variant

How are these changes tested?

Existing tests

@andygrove
Copy link
Member Author

@Blizzara @advancedxy fyi

Copy link
Contributor

@kazuyukitanimura kazuyukitanimura left a comment

Choose a reason for hiding this comment

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

LGTM

fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::ArithmeticOverflow { from_type } =>
write!(f, "[ARITHMETIC_OVERFLOW] {from_type} overflow. If necessary set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error."),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we keep the earlier comment, i.e. // Note that this message format is based on Spark 3.4?

use std::fmt::{Display, Formatter};

#[derive(Debug)]
pub enum SparkError {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not specified to expression but also Spark operator. But since we don't have spark-operator crate, it looks okay to have it in spark-expr now.

Copy link
Contributor

@advancedxy advancedxy left a comment

Choose a reason for hiding this comment

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

One minor comment, others LGTM.

impl Display for SparkError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::ArithmeticOverflow { from_type } =>
Copy link
Contributor

Choose a reason for hiding this comment

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

could we leverage the error macro in the previous impl?

#[error("[ARITHMETIC_OVERFLOW] {from_type} overflow. If necessary set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error.")]

Which seems slightly readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason I didn't do this was because I was trying to avoid adding a dependency on thiserror, but from looking at their documentation it seems like this isn't really an issue because it is just a derive macro. I will make this change.

@andygrove andygrove merged commit 863b40f into apache:main Jul 12, 2024
74 checks passed
himadripal pushed a commit to himadripal/datafusion-comet that referenced this pull request Sep 7, 2024
@andygrove andygrove deleted the cast-error branch December 3, 2024 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants