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 2020/11/20 11:28:59 UTC

[GitHub] [spark] gengliangwang opened a new pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

gengliangwang opened a new pull request #30445:
URL: https://github.com/apache/spark/pull/30445


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### 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.
   -->
   Support filed EPOCH in the function `extract` and `date_part`, which returns the number of seconds since `1970-01-01 00:00:00-00`
   For example:
   ```
   > SELECT EXTRACT(EPOCH FROM TIMESTAMP'1970-01-02 00:00:00-08');
   115200.0
   > SELECT DATE_PART('EPOCH', TIMESTAMP'1970-01-01 00:00:01.234-00')
   1.234
   ```
   
   Note that this field only works with Date and Timestamp input. It doesn't work with Interval type. In Spark, the number of seconds of `month` /`day` is considered as uncertain in Spark (a month contains 28~31 days, a day contains 23 ~25 hours). 
   
   
   ### 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.
   -->
   This is useful for getting the number of seconds since `1970-01-01 00:00:00-00`. 
   PostgreSQL also supports the same field:
   https://www.postgresql.org/docs/9.1/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
   
   The other reason is that since casting from TimestampType to Numeric Type is disallowed in ANSI mode, we need to provide a proper solution if a user has to do the casting.
   
   ### 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'.
   -->
   Yes, a new field "EPOCH" for datetime function extract/date_part 
   
   ### 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.
   -->
   Unit 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.

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] cloud-fan commented on pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30445:
URL: https://github.com/apache/spark/pull/30445#issuecomment-731138928


   Because we thought it's not commonly used. But @gengliangwang gave a good point that we need a replacement for casting datetime to numbers.


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


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


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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






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

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 a change in pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -493,6 +493,13 @@ object DateTimeUtils {
     Decimal(getMicroseconds(micros, zoneId), 8, 6)
   }
 
+  /**
+   * Returns the number of seconds since 1970-01-01 00:00:00-00 (can be negative).
+   */
+  def getSecondsAfterEpoch(micros: Long, zoneId: ZoneId): Double = {
+    micros.toDouble / MICROS_PER_SECOND

Review comment:
       @gengliangwang If you would like to be compatible to PostgreSQL, you need to take the removed implementation:
   ```scala
   /**
      * Returns the number of seconds with fractional part in microsecond precision
      * since 1970-01-01 00:00:00 local time.
      */
     def getEpoch(timestamp: SQLTimestamp, zoneId: ZoneId): Decimal = {
       val offset = SECONDS.toMicros(
         zoneId.getRules.getOffset(microsToInstant(timestamp)).getTotalSeconds)
       val sinceEpoch = timestamp + offset
       Decimal(sinceEpoch, 20, 6)
     }
   ```
   PostgreSQL takes seconds since the **local** epoch 1970-01-01 00:00:00-00 but your implementation calculates seconds since 1970-01-01 00:00:00-00**Z** (in UTC time zone).




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

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] gengliangwang commented on a change in pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -493,6 +493,13 @@ object DateTimeUtils {
     Decimal(getMicroseconds(micros, zoneId), 8, 6)
   }
 
+  /**
+   * Returns the number of seconds since 1970-01-01 00:00:00-00 (can be negative).
+   */
+  def getSecondsAfterEpoch(micros: Long, zoneId: ZoneId): Double = {
+    micros.toDouble / MICROS_PER_SECOND

Review comment:
       +1, thanks for pointing it out 👍 




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

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] gengliangwang commented on pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   Close this since we already have https://github.com/apache/spark/pull/30566


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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






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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   Merged build finished. Test FAILed.


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

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] gengliangwang closed pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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






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

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] yaooqinn commented on pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


    I checked the chat history with @cloud-fan, the reasons that we agreed for deleting  EPOCH are 1) EPOCH is non-ANSI 2) EPOCH cannot express the meaning of `extract` comparing with other patterns. 3) supporters are few.


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


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


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   **[Test build #131424 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/131424/testReport)** for PR 30445 at commit [`6a5f31b`](https://github.com/apache/spark/commit/6a5f31b4713b7efd78bb1e78dd7f257acef02299).
    * 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.

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


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


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

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] cloud-fan commented on pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30445:
URL: https://github.com/apache/spark/pull/30445#issuecomment-731146823


   ah yea, it's not really extract. Can we follow big query to add 3 functions: `UNIX_SECONDS`, `UNIX_MILLIS`, `UNIX_MICROS`. See https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   **[Test build #131424 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/131424/testReport)** for PR 30445 at commit [`6a5f31b`](https://github.com/apache/spark/commit/6a5f31b4713b7efd78bb1e78dd7f257acef02299).


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

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] gengliangwang commented on pull request #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   > The other reason is that since casting from TimestampType to Numeric Type is disallowed in ANSI mode, we need to provide a proper solution if a user has to do the casting.
   
   @MaxGekk This is my major motivation. Actually, I didn't know we had it before and got removed.


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

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 #30445: [SPARK-33500][SQL] Support field "EPOCH" in datetime function extract/date_part

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


   **[Test build #131424 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/131424/testReport)** for PR 30445 at commit [`6a5f31b`](https://github.com/apache/spark/commit/6a5f31b4713b7efd78bb1e78dd7f257acef02299).


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

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