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

[FEATURE] Add 3 interval types instead of 1 to support complex interval expressions #859

Open
Tracked by #722
Yury-Fridlyand opened this issue Sep 28, 2022 · 0 comments
Labels
enhancement New feature or request SQL

Comments

@Yury-Fridlyand
Copy link
Collaborator

Is your feature request related to a problem?

I discovered that in MySQL some functions' return type depends on arguments' values (not on their types❗)
For example, DATE_ADD function returns

  • DATETIME when arguments are TIME and date or complex INTERVAL
  • DATETIME when arguments are DATE and time or complex INTERVAL
  • TIME when arguments are TIME and time INTERVAL
  • DATE when arguments are DATE and date INTERVAL
  • ...
    So function had following signature:
(DATE, INTERVAL) -> DATE
(DATE, INTERVAL) -> DATETIME
(TIME, INTERVAL) -> TIME
(TIME, INTERVAL) -> DATETIME
...

Which is extremely ambiguous for Resolver. It picked first matching signature (last in the list) and used it for further resolving.
In the given example (see pic), a signature which returns DATE was resolved, but actual function execution returned DATETIME.

image

What solution would you like?

Introduce 3 new INTERVAL-like types instead of existing INTERVAL (ExprIntervalValue):

  • DATE_INTERVAL which operates with date terms, like days, months and years
  • TIME_INTERVAL which operates with time terms, e.g. hours, minutes and so on
  • DATETIME_INTERVAL which all datetime terms
  1. These types shouldn't be visible for user to avoid confusion. Syntax shouldn't be changed.
  2. These types should support more than one term, e.g. 'x hours y seconds' and even 'x years y minutes' for DATETIME_INTERVAL. This feature should implement complex interval expressions.
  3. This feature should contain update for DATE_ADD function (and its siblings: ADDDATE, SUBDATE, DATE_SUB) as a use case:
(DATE, DATE_INTERVAL) -> DATE
(DATE, TIME_INTERVAL) -> DATETIME
(DATE, DATETIME_INTERVAL) -> DATETIME
(TIME, TIME_INTERVAL) -> TIME
(TIME, DATE_INTERVAL) -> DATETIME
(TIME, DATETIME_INTERVAL) -> DATETIME

What alternatives have you considered?

N/A

Do you have any additional context?

#855

@Yury-Fridlyand Yury-Fridlyand changed the title [FEATURE] Add 3 interval types instead of 1 [FEATURE] Add 3 interval types instead of 1 to support complex interval expressions Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SQL
Projects
None yet
Development

No branches or pull requests

2 participants