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

Add _all_ date function aliases to parser (extended) #1982

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

paulrutter
Copy link
Contributor

@paulrutter paulrutter commented Oct 22, 2024

Based on #1980, this PR attempts to add all relevant date functions to the parser (and thus validate the query for being valid).

  • ADDDATE(args)
  • DAY(date)
  • DAYOFMONTH(date)
  • DAYOFWEEK(date)
  • DATE_ADD(args)
  • DATE_SUB(args)
  • SUBDATE(args)
  • MINUTE(date)
  • SECOND(date)
  • MONTH(date)
  • YEAR(date)
  • WEEK(date)
  • WEEKDAY(date)

Additional: the interval values that can be specified are now also part of the parser:

    MICROSECOND
    | MILLISECOND
    | SECOND
    | MINUTE
    | HOUR
    | DAY
    | DAYOFWEEK
    | DAYOFYEAR
    | WEEK
    | MONTH
    | QUARTER
    | YEAR

This makes some keywords now reserved keywords, like using month as column alias for example.
This has been adjusted in this PR.

Do note that DATE() is not added to the parser, as its use is very ambigious in AlaSQL.

There are new unit tests that verify the changes made.

Add the following functions to the parser:
- NOW
- GETDATE

Also add `CURRENT_TIMESTAMP()` to the parser (with parenthesis).

- Adjust failing test as `now` is a reserved keyword. It was already, it was just not validated.
- Add test
- Add all other AlaSQL date functions and aliases to the parser
- Adjust unit tests, as month is now a reserved keyword
- Explicitly didn't add the "DATE()" function, as it's use is very ambiguous in AlaSQL -> as column alias, as column type, as JS expression.
- Added IntervalLiteral which contains all possible values to use when specifying an interval expression
- Use Expression instead of ExprList to restrict the number of arguments to the methods
- Extend unit test with non existing interval
- DAYOFYEAR is alias for DAY
- Compact the expression with an OR statement to reduce duplicate code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant