-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33496][SQL]Improve error message of ANSI explicit cast #30440
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
[SPARK-33496][SQL]Improve error message of ANSI explicit cast #30440
Conversation
|
Since there is no alternative function for converting timestamp to numeric, I will work on another one before continuing this one. |
|
Test build #131399 has finished for PR 30440 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #131559 has finished for PR 30440 at commit
|
|
Test build #131593 has finished for PR 30440 at commit
|
| // scalastyle:off line.size.limit | ||
| s""" | ||
| | cannot cast ${from.catalogString} to ${to.catalogString}, | ||
| | you can enable the casting by setting ${SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP.key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we remove LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP? It's true by default and I don't see why it's needed since we have ansi mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, we can have another PR for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do it first? then we don't need to change this part again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I have just created #30493
maropu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments and the other parts look fine.
| s""" | ||
| | cannot cast ${from.catalogString} to ${to.catalogString}, | ||
| | you can enable the casting by setting ${SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP.key} | ||
| | to true, but we strongly recommend using function TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: function -> functions?
| override def canCast(from: DataType, to: DataType): Boolean = AnsiCast.canCast(from, to) | ||
|
|
||
| // For now, this expression is only used in table insertion. | ||
| // If there are more scenarios for this expression, we should update the error message on type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a unnecessary space found in expression, we
| // scalastyle:off line.size.limit | ||
| s""" | ||
| | cannot cast ${from.catalogString} to ${from.catalogString}. | ||
| | We strongly recommend using function TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about describing it like To convert values from ${...} to ${...}, you can use functions TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead. ?
| case (_: NumericType, TimestampType) => | ||
| // scalastyle:off line.size.limit | ||
| s""" | ||
| | cannot cast ${from.catalogString} to ${from.catalogString}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from.catalogString -> to.catalogString for the latter one.
|
@cloud-fan @maropu Thanks for the suggestions. I have addressed them. |
|
Test build #131652 has finished for PR 30440 at commit
|
|
retest this please. |
|
Test build #131664 has finished for PR 30440 at commit
|
|
retest this please. |
|
Test build #131721 has finished for PR 30440 at commit
|
|
retest this please. |
e762162 to
bb5b219
Compare
|
Test build #131756 has finished for PR 30440 at commit
|
|
retest this please. |
| case (_: ArrayType, StringType) => | ||
| s""" | ||
| | cannot cast ${from.catalogString} to ${to.catalogString} with ANSI mode on. | ||
| | If you have to cast ${from.catalogString} to ${to.catalogString}, you can use the function array_join or set $fallbackConfKey as $fallbackConfValue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upper case the function name?
|
Test build #131764 has finished for PR 30440 at commit
|
|
@maropu @cloud-fan Thanks for the review! |
|
Test build #131772 has finished for PR 30440 at commit
|
|
Build finished. |
|
Refer to this link for build results (access rights to CI server needed): |
|
Test build #131777 has finished for PR 30440 at commit
|
|
Build finished. |
|
Refer to this link for build results (access rights to CI server needed): |
What changes were proposed in this pull request?
After #30260, there are some type conversions disallowed under ANSI mode.
We should tell users what they can do if they have to use the disallowed casting.
Why are the changes needed?
Make it more user-friendly.
Does this PR introduce any user-facing change?
Yes, the error message is improved on casting failure when ANSI mode is enabled
How was this patch tested?
Unit tests.