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: Support ANSI mode in CAST from String to Bool #290

Merged
merged 19 commits into from
Apr 22, 2024

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Apr 19, 2024

Which issue does this PR close?

Part of the epic #286

Rationale for this change

This PR implements ANSI mode for casting string to boolean, and hopefully provides a good example that others can follow when adding ANSI support to other cast operations.

What changes are included in this PR?

  • Add a new configuration to enable experimental ANSI support in Comet
  • Adds EvalMode to the cast definition in protobuf
  • Throw an exception on invalid inputs when ANSI mode is enabled
  • Refactor CometCastSuite to test both cast() and try_cast() with ANSI enabled and disabled
  • Disable some tests that are now failing

How are these changes tested?

New/improved tests in CometCastSuite.

Comment on lines 123 to 129
other if ansi_mode => {
return Err(CometError::CastInvalidValue {
value: other.to_string(),
from_type: "STRING".to_string(),
to_type: "BOOLEAN".to_string(),
})
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the actual fix to add ANSI support in this specific cast operation. The rest of the PR is plumbing to pass ANSI mode down into the planner and improving the cast test suite.

Copy link
Contributor

@edmondop edmondop left a comment

Choose a reason for hiding this comment

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

Is checking children length required?

core/src/execution/datafusion/expressions/cast.rs Outdated Show resolved Hide resolved
@andygrove andygrove marked this pull request as draft April 19, 2024 20:08
@andygrove andygrove marked this pull request as ready for review April 19, 2024 20:58
@andygrove andygrove requested a review from viirya April 19, 2024 21:55
@andygrove
Copy link
Member Author

I will need to do some shim work to make this compile with earlier versions of Spark.

Comment on lines +154 to +157
// We have to workaround https://github.com/apache/datafusion-comet/issues/293 here by
// removing the "Execution error: " error message prefix that is added by DataFusion
val cometMessage = actual.getMessage
.substring("Execution error: ".length)
Copy link
Member Author

Choose a reason for hiding this comment

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

Follow on issue to resolve this: #293

@andygrove andygrove merged commit 7fa23d5 into apache:main Apr 22, 2024
28 checks passed
@andygrove andygrove deleted the cast-string-to-bool branch April 22, 2024 12:37
@viirya
Copy link
Member

viirya commented Apr 22, 2024

Thank you @andygrove

himadripal pushed a commit to himadripal/datafusion-comet that referenced this pull request Sep 7, 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.

3 participants