Skip to content

[SPARK-44778][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFF - #42435

Closed
MaxGekk wants to merge 4 commits into
apache:masterfrom
MaxGekk:timediff
Closed

[SPARK-44778][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFF#42435
MaxGekk wants to merge 4 commits into
apache:masterfrom
MaxGekk:timediff

Conversation

@MaxGekk

@MaxGekkMaxGekk commented Aug 10, 2023

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

In the PR, I propose to extend the rules of primaryExpression in SqlBaseParser.g4, and one more function TIMEDIFF which accepts 3-args in the same way as the existing expressions TIMESTAMPDIFF.

Why are the changes needed?

To achieve feature parity w/ other system and make the migration to Spark SQL from such systems easier:

  1. Snowflake: https://docs.snowflake.com/en/sql-reference/functions/timediff
  2. MySQL/MariaDB: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timediff

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running the existing test suites:

$ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"

@MaxGekkMaxGekk changed the title [WIP][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFF[WIP][SPARK-44778][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFFAug 11, 2023
@MaxGekkMaxGekk changed the title [WIP][SPARK-44778][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFF[SPARK-44778][SQL] Add the alias TIMEDIFF for TIMESTAMPDIFFAug 11, 2023
@MaxGekk
MaxGekk marked this pull request as ready for review August 11, 2023 17:03
@MaxGekk

Copy link
Copy Markdown
MemberAuthor

Merging to master. Thank you, @HyukjinKwon for review.

hvanhovell pushed a commit to hvanhovell/spark that referenced this pull request Aug 13, 2023
### What changes were proposed in this pull request?
In the PR, I propose to extend the rules of `primaryExpression` in `SqlBaseParser.g4`, and one more function `TIMEDIFF` which accepts 3-args in the same way as the existing expressions `TIMESTAMPDIFF`.
### Why are the changes needed?
To achieve feature parity w/ other system and make the migration to Spark SQL from such systems easier:
1. Snowflake: https://docs.snowflake.com/en/sql-reference/functions/timediff
2. MySQL/MariaDB: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timediff
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
By running the existing test suites:
```
$ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"
```
Closesapache#42435 from MaxGekk/timediff.
Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
valentinp17 pushed a commit to valentinp17/spark that referenced this pull request Aug 24, 2023
### What changes were proposed in this pull request?
In the PR, I propose to extend the rules of `primaryExpression` in `SqlBaseParser.g4`, and one more function `TIMEDIFF` which accepts 3-args in the same way as the existing expressions `TIMESTAMPDIFF`.
### Why are the changes needed?
To achieve feature parity w/ other system and make the migration to Spark SQL from such systems easier:
1. Snowflake: https://docs.snowflake.com/en/sql-reference/functions/timediff
2. MySQL/MariaDB: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timediff
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
By running the existing test suites:
```
$ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"
```
Closesapache#42435 from MaxGekk/timediff.
Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
sunchao pushed a commit that referenced this pull request Mar 10, 2026
* [SPARK-44778][SQL] Add the alias `TIMEDIFF` for `TIMESTAMPDIFF`
In the PR, I propose to extend the rules of `primaryExpression` in `SqlBaseParser.g4`, and one more function `TIMEDIFF` which accepts 3-args in the same way as the existing expressions `TIMESTAMPDIFF`.
To achieve feature parity w/ other system and make the migration to Spark SQL from such systems easier:
1. Snowflake: https://docs.snowflake.com/en/sql-reference/functions/timediff
2. MySQL/MariaDB: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timediff
No.
By running the existing test suites:
```
$ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"
```
Closes#42435 from MaxGekk/timediff.
Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
* changelog
---------
Signed-off-by: Max Gekk <max.gekk@gmail.com>
Co-authored-by: Max Gekk <max.gekk@gmail.com>
Sign up for freeto 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.

2 participants

@MaxGekk@HyukjinKwon