-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28497][SQL] Disallow upcasting complex data types to string type #25242
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
Conversation
|
good catch! can we also add an end-to-end test in |
|
Test build #108086 has finished for PR 25242 at commit
|
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
Show resolved
Hide resolved
|
Test build #108108 has finished for PR 25242 at commit
|
| test("SPARK-28497: complex type is not compatible with string encoder schema") { | ||
| val encoder = ExpressionEncoder[String] | ||
|
|
||
| { |
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.
Each block might be easily extracted with inner function to remove duplications. attr (element in attrs), and string representation of attr type are different and remaining is exactly same.
| { | ||
| val attrs = Seq('a.struct('x.long)) | ||
| assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message == | ||
| s""" |
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.
super nit: its ok just check .contains("Cannot up cast a from struct<x:bigint> to string")?
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
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.
I am OK with either way. I was following the other test cases in the suite. Let me change it to .contains...
| val attrs = Seq('a.array(StringType)) | ||
| assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message == | ||
| s""" | ||
| |Cannot up cast `a` from array<string> to string. |
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.
It doesn't necessarily compare the whole message. We can check if the message contains some keywords.
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.
Oh, it was the same comment as #25242 (comment)
HyukjinKwon
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.
Looks fine to me too otherwise.
|
Test build #108156 has finished for PR 25242 at commit
|
|
Merged to master. |
What changes were proposed in this pull request?
In the current implementation. complex types like Array/Map/StructType are allowed to upcast as StringType.
This is not safe casting. We should disallow it.
How was this patch tested?
Update the existing test case