Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16548][SQL] Inconsistent error handling in JSON parsing SQL functions - #17693
[SPARK-16548][SQL] Inconsistent error handling in JSON parsing SQL functions#17693ewasserman wants to merge 3 commits into
Conversation
@ewasserman Could you fix the title to point out the JIRA In terms of behaviour, I see @marmbrus and @srowen in that JIRA. Please let me cc. |
| if (parsed.isDefined) { | ||
| try { | ||
| Utils.tryWithResource(jsonFactory.createParser(jsonStr.getBytes)) { parser => | ||
| Utils.tryWithResource(jsonFactory.createParser(jsonStr.toString)) { parser => |
There was a problem hiding this comment.
I think we should catch the exception below rather than introducing unnecessary string instance apparently. (Sorry, I left a comment and removed back. I thought it was from_json/to_json).
There was a problem hiding this comment.
Could you check whether the other exceptions could be thrown by the illegal outputs?
There was a problem hiding this comment.
Keep the jsonStr.getBytes unchanged.
/** * Method for constructing parser for parsing * the contents of given byte array. * * @since 2.1 */publicJsonParsercreateParser(byte[] data) throwsIOException, JsonParseException {
IOContextctxt = _createContext(data, true);
if (_inputDecorator != null) {
InputStreamin = _inputDecorator.decorate(ctxt, data, 0, data.length);
if (in != null) {
return_createParser(in, ctxt);
}
}
return_createParser(data, 0, data.length, ctxt);
}I think we should capture both IOException and JsonParseException.
There was a problem hiding this comment.
I thought JsonParseException extends IOException.
gatorsmile
commented
Apr 20, 2017
Could you add a test case in |
liancheng
commented
Apr 20, 2017
Not suggesting doing it in this PR but maybe adding a SQL option to let the users choose the error handling strategy of all the JSON functions probably makes more sense here? The Spark JSON data source allows users to choose a parsing mode among:
|
gatorsmile
commented
Apr 20, 2017
@liancheng Good suggestion! Just like what we did for |
HyukjinKwon
commented
Apr 20, 2017
I like the idea but I am not sure of I think we don't explicitly support parse modes in both It sets |
| try { | ||
| Utils.tryWithResource(jsonFactory.createParser(json.getBytes)) { | ||
| Utils.tryWithResource(jsonFactory.createParser(json.toString)) { |
There was a problem hiding this comment.
this change has performance penalty, we should just catch more exception below.
ewasserman
commented
Apr 21, 2017
Reverted from use of toString on the org.apache.spark.unsafe.types.UTF8String by running the byte array through a java.io.Reader. This still fixes the bug and is also more efficient on the JSON parser side so it is a net performance win as well. |
| if (parsed.isDefined) { | ||
| try { | ||
| Utils.tryWithResource(jsonFactory.createParser(jsonStr.getBytes)) { parser => | ||
| Utils.tryWithResource(jsonFactory.createParser(new InputStreamReader( |
There was a problem hiding this comment.
please add some comments to say that, this is to avoid a bug in encoding detection, and we explicitly specify the encoding(UTF8) here.
cloud-fan
commented
Apr 22, 2017
LGTM |
gatorsmile
commented
Apr 22, 2017
ok to test |
SparkQA
commented
Apr 22, 2017
Test build #76068 has finished for PR 17693 at commit
|
SparkQA
commented
Apr 26, 2017
Test build #76153 has finished for PR 17693 at commit
|
…nctions ## What changes were proposed in this pull request? change to using Jackson's `com.fasterxml.jackson.core.JsonFactory` public JsonParser createParser(String content) ## How was this patch tested? existing unit tests Please review http://spark.apache.org/contributing.html before opening a pull request. Author: Eric Wasserman <ericw@sgn.com> Closes#17693 from ewasserman/SPARK-20314. (cherry picked from commit 57e1da3) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan
commented
Apr 26, 2017
thanks, merging to master/2.2 |
…nToStructs ## What changes were proposed in this pull request? A fix for the same problem was made in #17693 but ignored `JsonToStructs`. This PR uses the same fix for `JsonToStructs`. ## How was this patch tested? Regression test Author: Burak Yavuz <brkyvz@gmail.com> Closes#17826 from brkyvz/SPARK-20549. (cherry picked from commit 86174ea) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…nToStructs ## What changes were proposed in this pull request? A fix for the same problem was made in apache#17693 but ignored `JsonToStructs`. This PR uses the same fix for `JsonToStructs`. ## How was this patch tested? Regression test Author: Burak Yavuz <brkyvz@gmail.com> Closesapache#17826 from brkyvz/SPARK-20549.
…nctions ## What changes were proposed in this pull request? change to using Jackson's `com.fasterxml.jackson.core.JsonFactory` public JsonParser createParser(String content) ## How was this patch tested? existing unit tests Please review http://spark.apache.org/contributing.html before opening a pull request. Author: Eric Wasserman <ericw@sgn.com> Closesapache#17693 from ewasserman/SPARK-20314. (cherry picked from commit 57e1da3) Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit c8803c0)
What changes were proposed in this pull request?
change to using Jackson's
com.fasterxml.jackson.core.JsonFactoryHow was this patch tested?
existing unit tests
Please review http://spark.apache.org/contributing.html before opening a pull request.