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 2022/06/29 14:40:42 UTC

[GitHub] [spark] singhpk234 opened a new pull request, #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

singhpk234 opened a new pull request, #37025:
URL: https://github.com/apache/spark/pull/37025

   <!--
   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'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### 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.
   -->
   
   When specifying the expressions to TimeTravelSpec we should cast the only integer format timestamp i.e `1656505650` to long type rather than leaving it string type which we got from df option.
   
   ### 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.
   -->
   
   If we don't cast the timestamp which is  only `1656505650` to long and leave it to string, it will by default assumed to be in the format like `2022-06-29 18:40:37` and when will be casted in TimeTravelSpec from string to `TimestampType` it will fail the program, complaining it's not in a valid format for 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'.
   -->
   
   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.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   Added a UT, which would fail without the fix


-- 
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] singhpk234 commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910645370


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   > I think this over: do we need to support the microsecond? Seems to me it doesn't make sense for user to specify a long value in the query 
   
   +1 on this there is also one risk in supporting this as well, we need to specify the time always in **seconds** precision only, other wise it can return timestamp in wrong precision, to the catalog and hence making the query fail . [CodePointer](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala#L743) 
   
   
   >  For timestamps, only date or timestamp strings should be accepted. I don't think we should accept a long value.
   
   Are you suggesting we make changes in the grammar for not supporting it in the SQL ?
   
   I raised this change considering : 
   1. SQL was supporting this and df options were not (apologies, i thought it was kind of parity gap)
   2. Iceberg supports time travel via custom options in data frame, such as [`as-of-timestamp`](https://iceberg.apache.org/docs/latest/spark-queries/#time-travel) which excepts the value of option as milliseconds value, since now spark supports this via SupportCatalogOptions, i thought we can use this.
   
   Happy to make the changes accordingly, or even close it if we think it's not an issue from df reader perspective.
   



-- 
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] singhpk234 commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910645370


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   > I think this over: do we need to support the microsecond? Seems to me it doesn't make sense for user to specify a long value in the query 
   
   +1 on this there is also one risk in supporting this as well, we need to specify the time always in **seconds** precision only, other wise it can return timestamp in wrong precision, to the catalog and hence making the query fail . [CodePointer](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala#L743) 
   
   
   >  For timestamps, only date or timestamp strings should be accepted. I don't think we should accept a long value.
   
   Are you suggesting we make changes in the grammar for not supporting it in the SQL ?
   
   I raised this change considering : 
   1. SQL was supporting this and df options were not (apologies, i thought it was kind of parity gap)
   2. Iceberg supports time travel via custom options in data frame, such as [`as-of-timestamp`](https://iceberg.apache.org/docs/latest/spark-queries/#time-travel) which expects the value of option as milliseconds value, since now spark supports this via SupportCatalogOptions, i thought we can use this.
   
   Happy to make the changes accordingly, or even close it if we think it's not an issue from df reader perspective.
   



-- 
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] huaxingao closed pull request #37025: [SPARK-39633][SQL] Support timestamp in seconds for TimeTravel using Dataframe options

Posted by GitBox <gi...@apache.org>.
huaxingao closed pull request #37025: [SPARK-39633][SQL] Support timestamp in seconds for TimeTravel using Dataframe options
URL: https://github.com/apache/spark/pull/37025


-- 
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] huaxingao commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
huaxingao commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910600263


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   For timestamps, only date or timestamp strings should be accepted. I don't think we should accept a long value.



-- 
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] cloud-fan commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910517268


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   so this is not a bug fix but a new feature? I don't think it was designed to support microsecond as the timestamp string.



-- 
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] singhpk234 commented on pull request #37025: [SPARK-39633][SQL] Support timestamp in seconds for TimeTravel using Dataframe options

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on PR #37025:
URL: https://github.com/apache/spark/pull/37025#issuecomment-1171900569

   Thank you @huaxingao @cloud-fan !


-- 
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] singhpk234 commented on pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on PR #37025:
URL: https://github.com/apache/spark/pull/37025#issuecomment-1170101448

   cc @cloud-fan @huaxingao 


-- 
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] huaxingao commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
huaxingao commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910592623


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   I think this over: do we need to support the microsecond? Seems to me it doesn't make sense for user to specify a long value in the query
   ```
   SELECT * FROM table TIMESTAMP AS OF '1616574866666'
   ```
   



-- 
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] huaxingao commented on pull request #37025: [SPARK-39633][SQL] Support timestamp in seconds for TimeTravel using Dataframe options

Posted by GitBox <gi...@apache.org>.
huaxingao commented on PR #37025:
URL: https://github.com/apache/spark/pull/37025#issuecomment-1171793306

   Merged to 3.3/master. Thanks @singhpk234 @cloud-fan 


-- 
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 #37025: [SPARK-39633][SQL] Support timestamp in seconds for TimeTravel using Dataframe options

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

   Can one of the admins verify this patch?


-- 
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] singhpk234 commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910653073


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   ACK



-- 
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] singhpk234 commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
singhpk234 commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910579873


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   My thought was considering seconds as the timestamp works in Spark SQL, it should work in data frame path also. 
   
   > I don't think it was designed to support microsecond as the timestamp string
   
   I now see, spark-sql AST builder un-intentionally creates a literal expression of longType in this scenario, which fits in the code flow path and works when we create a TimeTravelSpec and trigger the casting. Where as the data-frame code flow always forced us by design to return it in string format (implying date format should only given). 
   
   Should I update the jira / pr description ?



-- 
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] cloud-fan commented on a diff in pull request #37025: [SPARK-39633][SQL] Fix timetravel via dataframe using timestampAsOf

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37025:
URL: https://github.com/apache/spark/pull/37025#discussion_r910649089


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/SupportsCatalogOptionsSuite.scala:
##########
@@ -322,6 +323,12 @@ class SupportsCatalogOptionsSuite extends QueryTest with SharedSparkSession with
         timestamp = Some("2019-01-29 00:37:58")), df3.toDF())
       checkAnswer(load("t", Some(catalogName), version = None,
         timestamp = Some("2021-01-29 00:37:58")), df4.toDF())
+
+      // load with timestamp in number format
+      checkAnswer(load("t", Some(catalogName), version = None,
+        timestamp = Some(MICROSECONDS.toSeconds(ts1).toString)), df3.toDF())

Review Comment:
   > spark-sql AST builder un-intentionally creates a literal expression of longType in this scenario
   
   I see. This is indeed un-intentional... But since it's already supported, we can't remove it now. Then it makes sense to make SQL and dataframe API consistent. @singhpk234 can you update the PR title and description? And also add SQL tests for this case.



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