[SPARK-49635][SQL] Remove ANSI config suggestion in CAST error messages#53295
Closed
qlong wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-49635][SQL] Remove ANSI config suggestion in CAST error messages#53295qlong wants to merge 1 commit intoapache:masterfrom
qlong wants to merge 1 commit intoapache:masterfrom
Conversation
ab0aade to
2fc68b5
Compare
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastWithAnsiOnSuite.scala
Outdated
Show resolved
Hide resolved
60a4c3c to
a93b2b4
Compare
This PR improves CAST error messages to provide suggestions based on whether casts work in non-ANSI mode. SPARK-49635 identified that suggesting users disable ANSI mode in error messages goes against Spark 4.0's direction (ANSI enabled by default). This PR addresses that issue by implementing suggestion logic: - Suggest try_cast() for ANSI-compliant alternatives - Suggest disabling ANSI mode only when the cast actually works in non-ANSI mode but try_cast doesn't support it - Provide no suggestion when the cast doesn't work in any mode This ensures error messages guide users toward ANSI-compliant solutions while still helping users migrate from previous versions.
a93b2b4 to
4804c03
Compare
gengliangwang
approved these changes
Dec 9, 2025
Member
|
Thanks, merging to master |
Member
|
@qlong what is your jira id? I am trying to assign https://issues.apache.org/jira/browse/SPARK-49635 to you |
Author
|
My jira Id: qiegang
Thanks for merging the fix.
…On Tue, Dec 9, 2025 at 12:36 PM Gengliang Wang ***@***.***> wrote:
*gengliangwang* left a comment (apache/spark#53295)
<#53295 (comment)>
@qlong <https://github.com/qlong> what is your jira id? I am trying to
assign https://issues.apache.org/jira/browse/SPARK-49635 to you
—
Reply to this email directly, view it on GitHub
<#53295 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB4C7DI5CERIBZY3FAIHUD4A4CCBAVCNFSM6AAAAACN3NKWSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMMZTGQ2DQOBYGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR improves CAST error messages to provide suggestions based on whether casts work in ANSI mode, non-ANSI mode, or try_cast():
Why are the changes needed?
In Spark 4.0.0, ANSI mode is now enabled by default. The previous error messages suggested users disable ANSI mode when encountering cast failures, which goes against the direction of the project. However, completely removing these suggestions would leave users without guidance when migrating code from Spark 3.x that relied on non-ANSI cast behavior.
Does this PR introduce any user-facing change?
Yes. Error messages for CAST operations that fail in ANSI mode now suggest using
try_cast()instead of disabling ANSI mode, but only whentry_cast()actually supports that cast operation.Before:
After (for casts supported by try_cast):
After (suggests disabling ANSI when try_cast doesn't support it):
After (for casts not supported by try_cast):
How was this patch tested?
demonstrates try_cast suggestion
behavior
Was this patch authored or co-authored using generative AI tooling?
No