-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,43 @@ class EncoderResolutionSuite extends PlanTest { | |
| encoder.resolveAndBind(attrs) | ||
| } | ||
|
|
||
| test("SPARK-28497: complex type is not compatible with string encoder schema") { | ||
| val encoder = ExpressionEncoder[String] | ||
|
|
||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: its ok just check
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| |Cannot up cast `a` from struct<x:bigint> to string. | ||
| |The type path of the target object is: | ||
| |- root class: "java.lang.String" | ||
| |You can either add an explicit cast to the input data or choose a higher precision type | ||
| """.stripMargin.trim + " of the field in the target object") | ||
| } | ||
|
|
||
| { | ||
| val attrs = Seq('a.array(StringType)) | ||
| assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message == | ||
| s""" | ||
| |Cannot up cast `a` from array<string> to string. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, it was the same comment as #25242 (comment) |
||
| |The type path of the target object is: | ||
| |- root class: "java.lang.String" | ||
| |You can either add an explicit cast to the input data or choose a higher precision type | ||
| """.stripMargin.trim + " of the field in the target object") | ||
| } | ||
|
|
||
| { | ||
| val attrs = Seq('a.map(StringType, StringType)) | ||
| assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message == | ||
| s""" | ||
| |Cannot up cast `a` from map<string,string> to string. | ||
| |The type path of the target object is: | ||
| |- root class: "java.lang.String" | ||
| |You can either add an explicit cast to the input data or choose a higher precision type | ||
| """.stripMargin.trim + " of the field in the target object") | ||
| } | ||
| } | ||
|
|
||
| test("throw exception if real type is not compatible with encoder schema") { | ||
| val msg1 = intercept[AnalysisException] { | ||
| ExpressionEncoder[StringIntClass].resolveAndBind(Seq('a.string, 'b.long)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.