Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21954][SQL] JacksonUtils should verify MapType's value type instead of key type - #19167
[SPARK-21954][SQL] JacksonUtils should verify MapType's value type instead of key type#19167viirya wants to merge 4 commits into
Conversation
| class JacksonUtilsSuite extends SparkFunSuite { | ||
| test("verifySchema") { |
There was a problem hiding this comment.
@viirya, would you mind if I ask to leave a simple e2e test alone for this PR? This one looks quite a simple fix to me and I think this won't require such many tests alone for this issue. I want to backport this but only leave strictly related changes here.
I think we could do something like SELECT to_json(struct(map(interval 1 second, 'a'))) or SELECT to_json(struct(map('a', interval 1 second))).
There was a problem hiding this comment.
OK, I am fine with those test coverage improvement too together. Up to you.
| val atomicTypes = DataTypeTestUtils.atomicTypes | ||
| val atomicArrayTypes = atomicTypes.map(ArrayType(_, containsNull = false)) | ||
| val atomicMapTypes = for (keyType <- atomicTypes; | ||
| valueType <- atomicTypes) yield MapType(keyType, valueType, false) |
There was a problem hiding this comment.
I'd do this as below:
valatomicMapTypes=for {
keyType <- atomicTypes
valueType <- atomicTypes
} yieldMapType(keyType, valueType, false)| class JacksonUtilsSuite extends SparkFunSuite { | ||
| test("verifySchema") { |
There was a problem hiding this comment.
OK, I am fine with those test coverage improvement too together. Up to you.
| // For MapType, its keys are treated as a string basically when generating JSON, so we only | ||
| // care if the values are valid for JSON. | ||
| val alsoValidMapTypes = for (keyType <- atomicTypes ++ invalidTypes; |
There was a problem hiding this comment.
Would it be possible to move these supported cases into 45L so we loop twice, one for the vaild and one for invalid one?
SparkQA
commented
Sep 8, 2017
Test build #81552 has finished for PR 19167 at commit
|
9bc8b2d to
a15bdb7Compareviirya
commented
Sep 9, 2017
@HyukjinKwon Thanks for review. I simplified the test cases. Please take a look when you are available. |
a15bdb7 to
884c533Compare| "A type of keys and values in map() must be string, but got")) | ||
| } | ||
| test("SPARK-21954: JacksonUtils should verify MapType's value type instead of key type") { |
There was a problem hiding this comment.
@viirya, how about puting this test around to_json unsupported type here and maybe use Scala function API for consistency?
HyukjinKwon
left a comment
There was a problem hiding this comment.
LGTM except for a minor comment.
| .select(struct(map(lit("a"), $"a._1".cast(CalendarIntervalType)).as("col1")).as("c")) | ||
| checkAnswer( | ||
| df2.select(to_json($"c")), | ||
| Row("""{"col1":{"interval -3 months 7 hours":"a"}}""") :: Nil) |
There was a problem hiding this comment.
valdf2= baseDf
.select(struct(map($"a._1".cast(CalendarIntervalType), lit("a")).as("col1")).as("c"))
...
checkAnswer(
df2.select(to_json($"c")),
Row("""{"col1":{"interval -3 months 7 hours":"a"}}""") ::Nil)This case looks a supported case though. We could maybe make a separate test for this one.
SparkQA
commented
Sep 9, 2017
Test build #81573 has finished for PR 19167 at commit
|
SparkQA
commented
Sep 9, 2017
Test build #81575 has finished for PR 19167 at commit
|
SparkQA
commented
Sep 9, 2017
Test build #81582 has finished for PR 19167 at commit
|
SparkQA
commented
Sep 9, 2017
Test build #81578 has finished for PR 19167 at commit
|
HyukjinKwon
commented
Sep 9, 2017
retest this please |
SparkQA
commented
Sep 9, 2017
Test build #81583 has finished for PR 19167 at commit
|
…stead of key type ## What changes were proposed in this pull request? `JacksonUtils.verifySchema` verifies if a data type can be converted to JSON. For `MapType`, it now verifies the key type. However, in `JacksonGenerator`, when converting a map to JSON, we only care about its values and create a writer for the values. The keys in a map are treated as strings by calling `toString` on the keys. Thus, we should change `JacksonUtils.verifySchema` to verify the value type of `MapType`. ## How was this patch tested? Added tests. Author: Liang-Chi Hsieh <viirya@gmail.com> Closes#19167 from viirya/test-jacksonutils. (cherry picked from commit 6b45d7e) Signed-off-by: hyukjinkwon <gurwls223@gmail.com>
HyukjinKwon
commented
Sep 9, 2017
Merged to master and branch-2.2. |
viirya
commented
Sep 9, 2017
Thanks @HyukjinKwon |
…stead of key type ## What changes were proposed in this pull request? `JacksonUtils.verifySchema` verifies if a data type can be converted to JSON. For `MapType`, it now verifies the key type. However, in `JacksonGenerator`, when converting a map to JSON, we only care about its values and create a writer for the values. The keys in a map are treated as strings by calling `toString` on the keys. Thus, we should change `JacksonUtils.verifySchema` to verify the value type of `MapType`. ## How was this patch tested? Added tests. Author: Liang-Chi Hsieh <viirya@gmail.com> Closesapache#19167 from viirya/test-jacksonutils. (cherry picked from commit 6b45d7e) Signed-off-by: hyukjinkwon <gurwls223@gmail.com>
What changes were proposed in this pull request?
JacksonUtils.verifySchemaverifies if a data type can be converted to JSON. ForMapType, it now verifies the key type. However, inJacksonGenerator, when converting a map to JSON, we only care about its values and create a writer for the values. The keys in a map are treated as strings by callingtoStringon the keys.Thus, we should change
JacksonUtils.verifySchemato verify the value type ofMapType.How was this patch tested?
Added tests.