Uh oh!
There was an error while loading. Please reload this page.
[SPARK-19637][SQL] Add to_json in FunctionRegistry - #16981
Conversation
SparkQA
commented
Feb 18, 2017
Test build #73095 has finished for PR 16981 at commit
|
SparkQA
commented
Feb 18, 2017
Test build #73096 has finished for PR 16981 at commit
|
SparkQA
commented
Feb 18, 2017
Test build #73099 has started for PR 16981 at commit |
maropu
commented
Feb 18, 2017
Jenkins, retest this please. |
SparkQA
commented
Feb 18, 2017
Test build #73102 has finished for PR 16981 at commit
|
HyukjinKwon
left a comment
There was a problem hiding this comment.
@maropu, I just left few opinions that might help.
There was a problem hiding this comment.
This is just my personal opinion but should we maybe consider minimising this import? For example, import org.json4s.jackson.JsonMethods.parse.
There was a problem hiding this comment.
We could try to utilize val parse(json).extract[Map[String, String]]. Given my observation, it produces empty Map if there are no such values or empty json and it throws an exception if it is an invalid json.
There was a problem hiding this comment.
Maybe, """ ... """ if more commits should be pushed.
maropu
commented
Feb 18, 2017
@HyukjinKwon Thanks! I'll check. |
SparkQA
commented
Feb 18, 2017
Test build #73107 has finished for PR 16981 at commit
|
There was a problem hiding this comment.
Could we do this as below
Try(parse(json).extract[Map[String, String]]).getOrElse {
thrownewAnalysisException(...)
}or maybe just a try-catch block?
There was a problem hiding this comment.
trivial..
s"Must be a string literal, but: $e"
There was a problem hiding this comment.
I guess we should check if it is StructType and throw a proper exception because it seems JsonToStruct does not check if exp is StructType and it probably throws a cast exception (if I haven't missed something here).
There was a problem hiding this comment.
I just wrote this way along with here https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L3010. Both is okay to me though, if we modify the code in a way you suggested, we need to modify from_json code, too?
There was a problem hiding this comment.
Ah, thanks. Yes, if it throws a class cast exception, I think we should produce a better exception and message rather than just one saying A cannot be cast to B. Maybe, add a util for both places?
There was a problem hiding this comment.
Probably just struct instead of `StructType` (as I found a example in
maropu
commented
Feb 19, 2017
I'll update in a day, thanks! |
There was a problem hiding this comment.
What is the reason we use the Json option string?
There was a problem hiding this comment.
Aha, you mean we use a map literal, directly? Sorry, but I missed that idea. This json option is totally meaningless? If yes, I'll fix to use a map literal here.
gatorsmile
commented
Feb 20, 2017
Could you add SQL test cases to SQLQueryTestSuite? |
maropu
commented
Feb 20, 2017
@gatorsmile okay, I'll do soon |
There was a problem hiding this comment.
More examples are needed to show users how to use options.
There was a problem hiding this comment.
Regarding the format of options, another way is to use the MapType.
For example,
from_json(value, '${schema2.json}', map("timestampFormat", "dd/MM/yyyy HH:mm"))I am not sure whether using JSON to represent options is a good way.
There was a problem hiding this comment.
Can we let users call named_struct function to specify the schema?
There was a problem hiding this comment.
@gatorsmile, do you mind if I ask to elaborate what you think wtih named_struct? I am just curious.
There was a problem hiding this comment.
I checked related code though, if we use named_struc here, we need to add substantial code to convert named_struct to StructType...
SparkQA
commented
Feb 20, 2017
Test build #73141 has finished for PR 16981 at commit
|
SparkQA
commented
Feb 20, 2017
Test build #73143 has finished for PR 16981 at commit
|
SparkQA
commented
Feb 20, 2017
Test build #73156 has finished for PR 16981 at commit
|
SparkQA
commented
Feb 20, 2017
Test build #73157 has finished for PR 16981 at commit
|
maropu
commented
Feb 22, 2017
ping |
maropu
commented
Mar 1, 2017
@gatorsmile ping |
1 similar comment
maropu
commented
Mar 2, 2017
@gatorsmile ping |
gatorsmile
commented
Mar 2, 2017
To parse the schema represented in DDL format, instead of the json format, we need to call the parser to do it. If you are not familar with the parser, maybe you only implement |
maropu
commented
Mar 3, 2017
So, this pr re-used |
There was a problem hiding this comment.
Why we need to keep here? This is not related to JacksonUtils.scala. The function name also needs a change.
There was a problem hiding this comment.
case m: CreateMap if m.dataType.acceptsType(MapType(StringType, StringType, false)) =>
8093498 to
4a49d64CompareSparkQA
commented
Mar 3, 2017
Test build #73874 has finished for PR 16981 at commit
|
SparkQA
commented
Mar 3, 2017
Test build #73875 has finished for PR 16981 at commit
|
SparkQA
commented
Mar 4, 2017
Test build #73876 has finished for PR 16981 at commit
|
There was a problem hiding this comment.
This message is misleading in the following case:
df2.selectExpr("to_json(a, map('a', 1))")
There was a problem hiding this comment.
Please also include the test case for this. Thanks!
There was a problem hiding this comment.
SparkQA
commented
Mar 4, 2017
Test build #73892 has finished for PR 16981 at commit
|
gatorsmile
commented
Mar 4, 2017
marmbrus
commented
Mar 6, 2017
yeah, LGTM |
SparkQA
commented
Mar 7, 2017
Test build #74104 has finished for PR 16981 at commit
|
SparkQA
commented
Mar 7, 2017
Test build #74105 has finished for PR 16981 at commit
|
gatorsmile
commented
Mar 7, 2017
Thanks! Merging to master. |
What changes were proposed in this pull request?
This pr added entries in
FunctionRegistryand supportedto_jsonin SQL.How was this patch tested?
Added tests in
JsonFunctionsSuite.