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/14 07:54:55 UTC

[GitHub] [spark] sarutak opened a new pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

sarutak opened a new pull request #33742:
URL: https://github.com/apache/spark/pull/33742


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This PR fixes an issue that `from_json` and `to_json` cannot handle `timestamp_ntz` type properly.
   In the current master, `from_json`/`to_json` can handle `timestamp` type like as follows.
   ```
   SELECT from_json('{"a":"2021-11-23 11:22:33"}', "a TIMESTAMP");
   {"a":2021-11-23 11:22:33}
   ```
   ```
   SELECT to_json(map("a", TIMESTAMP"2021-11-23 11:22:33"));
   {"a":"2021-11-23T11:22:33.000+09:00"}
   ```
   But they cannot handle `timestamp_ntz` type properly.
   ```
   SELECT from_json('{"a":"2021-11-23 11:22:33"}', "a TIMESTAMP_NTZ");
   21/08/12 16:16:00 ERROR SparkSQLDriver: Failed in [SELECT from_json('{"a":"2021-11-23 11:22:33"}', "a TIMESTAMP_NTZ")]
   java.lang.Exception: Unsupported type: timestamp_ntz
           at org.apache.spark.sql.errors.QueryExecutionErrors$.unsupportedTypeError(QueryExecutionErrors.scala:777)
           at org.apache.spark.sql.catalyst.json.JacksonParser.makeConverter(JacksonParser.scala:339)
           at org.apache.spark.sql.catalyst.json.JacksonParser.$anonfun$makeConverter$17(JacksonParser.scala:313)
   ```
   ```
   SELECT to_json(map("a", TIMESTAMP_NTZ"2021-11-23 11:22:33"));
   21/08/12 16:14:07 ERROR SparkSQLDriver: Failed in [SELECT to_json(map("a", TIMESTAMP_NTZ"2021-11-23 11:22:33"))]
   java.lang.RuntimeException: Failed to convert value 1637666553000000 (class of class java.lang.Long) with the type of TimestampNTZType to JSON.
           at org.apache.spark.sql.errors.QueryExecutionErrors$.failToConvertValueToJsonError(QueryExecutionErrors.scala:294)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.$anonfun$makeWriter$25(JacksonGenerator.scala:201)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.$anonfun$makeWriter$25$adapted(JacksonGenerator.scala:199)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.writeMapData(JacksonGenerator.scala:253)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.$anonfun$write$3(JacksonGenerator.scala:293)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.writeObject(JacksonGenerator.scala:206)
           at org.apache.spark.sql.catalyst.json.JacksonGenerator.write(JacksonGenerator.scala:292)
   ```
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Bug fix.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   New test.


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


   **[Test build #142466 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142466/testReport)** for PR 33742 at commit [`31c9851`](https://github.com/apache/spark/commit/31c9851d11b606970918d8d87899419f6e92bedd).


-- 
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] sarutak commented on a change in pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

Posted by GitBox <gi...@apache.org>.
sarutak commented on a change in pull request #33742:
URL: https://github.com/apache/spark/pull/33742#discussion_r688897945



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala
##########
@@ -253,6 +259,12 @@ class JacksonParser(
           parser.getLongValue * 1000000L
       }
 
+    case TimestampNTZType =>
+      (parser: JsonParser) => parseJsonToken[java.lang.Long](parser, dataType) {
+        case VALUE_STRING if parser.getTextLength >= 1 =>
+          timestampNTZFormatter.parseWithoutTimeZone(parser.getText)

Review comment:
       Casting from numerical types to `timestamp_ntz` seems not supported so I don't care `VALUE_NUMBER_INT` here.




-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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] dongjoon-hyun commented on pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #33742:
URL: https://github.com/apache/spark/pull/33742#issuecomment-898996450


   cc @gengliangwang 


-- 
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] sarutak commented on a change in pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

Posted by GitBox <gi...@apache.org>.
sarutak commented on a change in pull request #33742:
URL: https://github.com/apache/spark/pull/33742#discussion_r688897743



##########
File path: sql/core/src/test/resources/sql-tests/results/timestampNTZ/timestamp-ansi.sql.out
##########
@@ -745,10 +745,9 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn
 -- !query
 select from_json('{"t":"26/October/2015"}', 't Timestamp', map('timestampFormat', 'dd/MMMMM/yyyy'))
 -- !query schema
-struct<>
+struct<from_json({"t":"26/October/2015"}):struct<t:timestamp_ntz>>
 -- !query output
-java.lang.Exception
-Unsupported type: timestamp_ntz
+{"t":null}

Review comment:
       `MMMMM` is an invalid format so `null` here is intended.




-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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] MaxGekk commented on pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


   +1, LGTM. Merging to master.
   Thank you, @sarutak .


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


   **[Test build #142466 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142466/testReport)** for PR 33742 at commit [`31c9851`](https://github.com/apache/spark/commit/31c9851d11b606970918d8d87899419f6e92bedd).


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


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


-- 
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 #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


   **[Test build #142466 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142466/testReport)** for PR 33742 at commit [`31c9851`](https://github.com/apache/spark/commit/31c9851d11b606970918d8d87899419f6e92bedd).
    * 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] MaxGekk closed pull request #33742: [SPARK-36491][SQL] Make from_json/to_json to handle timestamp_ntz type properly

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


   


-- 
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