You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/08/17 10:28:59 UTC

[GitHub] [spark] HyukjinKwon opened a new pull request #33762: [SPARK-36379][SQL] Null at root level of a JSON array should not fai lw/ permissive mode

HyukjinKwon opened a new pull request #33762:
URL: https://github.com/apache/spark/pull/33762


   This PR backports https://github.com/apache/spark/pull/33608 to branch-3.1
   
   -----------------------------------------------------------------------------
   
   ### What changes were proposed in this pull request?
   
   This PR proposes to fail properly so JSON parser can proceed and parse the input with the permissive mode.
   Previously, we passed `null`s as are, the root `InternalRow`s became `null`s, and it causes the query fails even with permissive mode on.
   Now, we fail explicitly if `null` is passed when the input array contains `null`.
   
   Note that this is consistent with non-array JSON input:
   
   **Permissive mode:**
   
   ```scala
   spark.read.json(Seq("""{"a": "str"}""", """null""").toDS).collect()
   ```
   ```
   res0: Array[org.apache.spark.sql.Row] = Array([str], [null])
   ```
   
   **Failfast mode**:
   
   ```scala
   spark.read.option("mode", "failfast").json(Seq("""{"a": "str"}""", """null""").toDS).collect()
   ```
   ```
   org.apache.spark.SparkException: Malformed records are detected in record parsing. Parse Mode: FAILFAST. To process malformed records as null result, try setting the option 'mode' as 'PERMISSIVE'.
   	at org.apache.spark.sql.catalyst.util.FailureSafeParser.parse(FailureSafeParser.scala:70)
   	at org.apache.spark.sql.DataFrameReader.$anonfun$json$7(DataFrameReader.scala:540)
   	at scala.collection.Iterator$$anon$11.nextCur(Iterator.scala:484)
   ```
   
   ### Why are the changes needed?
   
   To make the permissive mode to proceed and parse without throwing an exception.
   
   ### Does this PR introduce _any_ user-facing change?
   
   **Permissive mode:**
   
   ```scala
   spark.read.json(Seq("""[{"a": "str"}, null]""").toDS).collect()
   ```
   
   Before:
   
   ```
   java.lang.NullPointerException
   	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)
   	at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
   	at org.apache.spark.sql.execution.WholeStageCodegenExec$$anon$1.hasNext(WholeStageCodegenExec.scala:759)
   ```
   
   After:
   
   ```
   res0: Array[org.apache.spark.sql.Row] = Array([null])
   ```
   
   NOTE that this behaviour is consistent when JSON object is malformed:
   
   ```scala
   spark.read.schema("a int").json(Seq("""[{"a": 123}, {123123}, {"a": 123}]""").toDS).collect()
   ```
   
   ```
   res0: Array[org.apache.spark.sql.Row] = Array([null])
   ```
   
   Since we're parsing _one_ JSON array, related records all fail together.
   
   **Failfast mode:**
   
   
   ```scala
   spark.read.option("mode", "failfast").json(Seq("""[{"a": "str"}, null]""").toDS).collect()
   ```
   
   Before:
   
   ```
   java.lang.NullPointerException
   	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)
   	at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
   	at org.apache.spark.sql.execution.WholeStageCodegenExec$$anon$1.hasNext(WholeStageCodegenExec.scala:759)
   ```
   
   After:
   
   ```
   org.apache.spark.SparkException: Malformed records are detected in record parsing. Parse Mode: FAILFAST. To process malformed records as null result, try setting the option 'mode' as 'PERMISSIVE'.
   	at org.apache.spark.sql.catalyst.util.FailureSafeParser.parse(FailureSafeParser.scala:70)
   	at org.apache.spark.sql.DataFrameReader.$anonfun$json$7(DataFrameReader.scala:540)
   	at scala.collection.Iterator$$anon$11.nextCur(Iterator.scala:484)
   ```
   
   
   ### How was this patch tested?
   
   Manually tested, and unit test was added.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900184176


   **[Test build #142551 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142551/testReport)** for PR 33762 at commit [`41d8254`](https://github.com/apache/spark/commit/41d82541930cf525118106cdf309a418e2a1cb9c).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900369705


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142551/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900242157


   Merged to branch-3.1.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900241544


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/47053/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900369705


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142551/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900241544


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/47053/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900367667


   **[Test build #142551 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142551/testReport)** for PR 33762 at commit [`41d8254`](https://github.com/apache/spark/commit/41d82541930cf525118106cdf309a418e2a1cb9c).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900241271


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/47053/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900218924


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/47053/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA removed a comment on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900184176


   **[Test build #142551 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142551/testReport)** for PR 33762 at commit [`41d8254`](https://github.com/apache/spark/commit/41d82541930cf525118106cdf309a418e2a1cb9c).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon closed pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fail w/ permissive mode

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #33762:
URL: https://github.com/apache/spark/pull/33762


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #33762: [SPARK-36379][SQL][3.1] Null at root level of a JSON array should not fai lw/ permissive mode

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #33762:
URL: https://github.com/apache/spark/pull/33762#issuecomment-900179900


   cc @cloud-fan @dongjoon-hyun @MaxGekk FYI


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org