Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-38535][SQL] Add the datetimeUnit enum and use it in TIMESTAMPADD/DIFF #35826

Closed
wants to merge 4 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Mar 12, 2022

What changes were proposed in this pull request?

In the PR, I propose to add new enum datetimeUnit and re-use it in the datetime "function"s TIMESTAMPADD (see SPARK-38195) and TIMESTAMPDIFF (see SPARK-38284):

SqlBaseParser.g4:

datetimeUnit
    : YEAR | QUARTER | MONTH
    | WEEK | DAY | DAYOFYEAR
    | HOUR | MINUTE | SECOND | MILLISECOND | MICROSECOND
    ;

Why are the changes needed?

  1. The enum will allow to document the list of supported units in the grammar which should improve user experience with Spark SQL.
  2. Switching to unified parse error should improve UX too.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running test suites for TIMESTAMPADD/TIMESTAMPDIFF:

$ build/sbt "test:testOnly *SQLKeywordSuite"
$ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z timestamp.sql"

@MaxGekk MaxGekk requested a review from cloud-fan March 12, 2022 18:54
Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please fix conflicts

@MaxGekk
Copy link
Member Author

MaxGekk commented Mar 14, 2022

Merging to master. Thank you, @cloud-fan for review.

@MaxGekk MaxGekk closed this in a342214 Mar 14, 2022
@melin
Copy link

melin commented Jul 1, 2022

datetimeUnit argument can also have a prefix of SQL_TSI_. For example, you could use either DAY or SQL_TSI_DAY
https://database.guide/timestampadd-examples-mysql/
@MaxGekk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants