Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Aug 23, 2021

What changes were proposed in this pull request?

In the PR, I propose to add new correctness rule SpecialDatetimeValues to the final analysis phase. It replaces casts of strings to date/timestamp_ltz/timestamp_ntz by literals of such types if the strings contain special datetime values like today, yesterday and tomorrow, and the input strings are foldable.

Why are the changes needed?

  1. To avoid a breaking change.
  2. To improve user experience with Spark SQL. After the PR [SPARK-35581][SQL] Support special datetime values in typed literals only #32714, users have to use typed literals instead of implicit casts. For instance,
    at Spark 3.1:
select ts_col > 'now';

but the query fails at the moment, and users have to use typed timestamp literal:

select ts_col > timestamp'now';

Does this PR introduce any user-facing change?

No. Previous release 3.1 has supported the feature already till it was removed by #32714.

How was this patch tested?

  1. Manually tested via the sql command line:
spark-sql> select cast('today' as date);
2021-08-24
spark-sql> select timestamp('today');
2021-08-24 00:00:00
spark-sql> select timestamp'tomorrow' > 'today';
true
  1. By running new test suite:
$ build/sbt "sql/testOnly org.apache.spark.sql.catalyst.optimizer.SpecialDatetimeValuesSuite"

@github-actions github-actions bot added the SQL label Aug 23, 2021
@SparkQA
Copy link

SparkQA commented Aug 23, 2021

Test build #142708 has finished for PR 33816 at commit 16371f7.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Aug 23, 2021

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

@SparkQA
Copy link

SparkQA commented Aug 23, 2021

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

@SparkQA
Copy link

SparkQA commented Aug 23, 2021

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

@SparkQA
Copy link

SparkQA commented Aug 23, 2021

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

@SparkQA
Copy link

SparkQA commented Aug 24, 2021

Test build #142709 has finished for PR 33816 at commit 59933d2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Aug 24, 2021

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

@MaxGekk MaxGekk changed the title [WIP][SPARK-36567][SQL] Support foldable special datetime strings by CAST [SPARK-36567][SQL] Support foldable special datetime strings by CAST Aug 24, 2021
@MaxGekk MaxGekk marked this pull request as ready for review August 24, 2021 19:27
@SparkQA
Copy link

SparkQA commented Aug 24, 2021

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

@MaxGekk
Copy link
Member Author

MaxGekk commented Aug 24, 2021

@cloud-fan @gengliangwang @HyukjinKwon Could you review this PR, please.

@SparkQA
Copy link

SparkQA commented Aug 24, 2021

Test build #142741 has finished for PR 33816 at commit d7a1787.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master/3.2!

@cloud-fan cloud-fan closed this in df0ec56 Aug 25, 2021
cloud-fan pushed a commit that referenced this pull request Aug 25, 2021
### What changes were proposed in this pull request?
In the PR, I propose to add new correctness rule `SpecialDatetimeValues` to the final analysis phase. It replaces casts of strings to date/timestamp_ltz/timestamp_ntz by literals of such types if the strings contain special datetime values like `today`, `yesterday` and `tomorrow`, and the input strings are foldable.

### Why are the changes needed?
1. To avoid a breaking change.
2. To improve user experience with Spark SQL. After the PR #32714, users have to use typed literals instead of implicit casts. For instance,
at Spark 3.1:
```sql
select ts_col > 'now';
```
but the query fails at the moment, and users have to use typed timestamp literal:
```sql
select ts_col > timestamp'now';
```

### Does this PR introduce _any_ user-facing change?
No. Previous release 3.1 has supported the feature already till it was removed by #32714.

### How was this patch tested?
1. Manually tested via the sql command line:
```sql
spark-sql> select cast('today' as date);
2021-08-24
spark-sql> select timestamp('today');
2021-08-24 00:00:00
spark-sql> select timestamp'tomorrow' > 'today';
true
```
2. By running new test suite:
```
$ build/sbt "sql/testOnly org.apache.spark.sql.catalyst.optimizer.SpecialDatetimeValuesSuite"
```

Closes #33816 from MaxGekk/foldable-datetime-special-values.

Authored-by: Max Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit df0ec56)
Signed-off-by: Wenchen Fan <[email protected]>
@cloud-fan
Copy link
Contributor

@MaxGekk I think we should also update the migration guide?

@MaxGekk
Copy link
Member Author

MaxGekk commented Aug 25, 2021

Here is the update for the SQL migration guide #33840

cloud-fan pushed a commit that referenced this pull request Aug 26, 2021
…ion guide about foldable special datetime values

### What changes were proposed in this pull request?
In the PR, I propose to update an existing item in the SQL migration guide, and mention that Spark 3.2 supports foldable special datetime values as well.
<img width="1292" alt="Screenshot 2021-08-25 at 23 29 51" src="https://user-images.githubusercontent.com/1580697/130860184-27f0ba56-6c2d-4a5a-91a8-195f2f8aa5da.png">

### Why are the changes needed?
To inform users about actual Spark SQL behavior introduced by #33816

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By generating docs, and checking results manually.

Closes #33840 from MaxGekk/special-datetime-cast-migr-guide.

Authored-by: Max Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
cloud-fan pushed a commit that referenced this pull request Aug 26, 2021
…ion guide about foldable special datetime values

### What changes were proposed in this pull request?
In the PR, I propose to update an existing item in the SQL migration guide, and mention that Spark 3.2 supports foldable special datetime values as well.
<img width="1292" alt="Screenshot 2021-08-25 at 23 29 51" src="https://user-images.githubusercontent.com/1580697/130860184-27f0ba56-6c2d-4a5a-91a8-195f2f8aa5da.png">

### Why are the changes needed?
To inform users about actual Spark SQL behavior introduced by #33816

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By generating docs, and checking results manually.

Closes #33840 from MaxGekk/special-datetime-cast-migr-guide.

Authored-by: Max Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit c4e739f)
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants