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

feat: Implement Spark-compatible CAST from String to Decimal #615

Closed
wants to merge 3 commits into from

Conversation

sujithjay
Copy link
Contributor

Which issue does this PR close?

Closes #325.

Rationale for this change

We currently delegate to DataFusion when casting from string to decimal and there are some differences in behavior compared to Spark.

This PR implements a Spark-compatible cast from String to Decimal.

What changes are included in this PR?

An implementation of parse_decimal copied from arrow-rs, modified to be compatible with Spark's behavior.

How are these changes tested?

  • The test underCometCastSuite now passes.
  • Unit tests were introduced in cast.rs.

We currently delegate to DataFusion when casting from
string to decimal and there are some differences in
behavior compared to Spark.

This PR implements a Spark-compatible cast from String to Decimal.
@sujithjay
Copy link
Contributor Author

@kevinmingtarja, thank you for helping me with a draft. Could you please take a look?

@sujithjay
Copy link
Contributor Author

@andygrove @vaibhawvipul Could you please take a look?

@andygrove
Copy link
Member

@andygrove @vaibhawvipul Could you please take a look?

Apologies @sujithjay I had missed this ping. I will review this early next week.

Ok(Some(cast))
}

/// Copied from arrow-rs, modified to replicate Spark's behavior
Copy link
Member

Choose a reason for hiding this comment

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

This comment is useful, thanks. Could you also update the comment to give a brief summary of what needed to change to replicate Spark's behavior?

@andygrove
Copy link
Member

This is looking good @sujithjay. CI is failing due to clippy warnings. If you run clippy locally you should be able to see the same warnings as well as suggestions for fixing.

@andygrove
Copy link
Member

@sujithjay I took the liberty of fixing the clippy issues and fixing the conflicts

Comment on lines +495 to +496
let result: SparkResult<ArrayRef> = Ok(Arc::new(cast_array.finish()) as ArrayRef);
result?
Copy link
Member

Choose a reason for hiding this comment

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

No need to wrap in a result and then unwrap.

Suggested change
let result: SparkResult<ArrayRef> = Ok(Arc::new(cast_array.finish()) as ArrayRef);
result?
Arc::new(cast_array.finish()) as ArrayRef

@andygrove
Copy link
Member

@sujithjay I will close this PR for now since it has been inactive for a while. Feel free to reopen this or create a new PR if you continue work on this.

@andygrove andygrove closed this Oct 22, 2024
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.

Implement Spark-compatible CAST from String to Decimal
2 participants