sqlparser: Improve interval parsing#13165
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
9b475bb to
c57ede6
Compare
|
@systay Looks like there's an upgrade / downgrade failing test unrelated to the changes here: |
Parse only strict valid units for intervals. We should not allow any arbitrary string value here. We already had the internal enumerable available, but we were not using yet. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
In order to better be able to implement these in the evalengine, it's easier to parse them explicitly in the parser. This ensures we have the interval type etc. directly available instead of having to infer it from a separate expression. Also makes parsing these functions more strict and better match MySQL. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
INTERVAL is not a possible general expression, but only used in specific cases. With the previous change, we already have it all handled for date functions. The only remaining cases are for + and - where this is handled. Those cases are a bit special. You can have an interval on both sides of a +, but for a - it can only be done on the right hand side. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
e5bd5d6 to
9c2a16f
Compare
|
The upgrade downgrade failure is unrelated and being fixed by #13183 |
| mcmp.Exec("SET time_zone = '+00:00'") | ||
| mcmp.AssertMatches("select '2020-01-01' + interval month(DATE_SUB(FROM_UNIXTIME(1234), interval 1 month))-1 month", `[[CHAR("2020-12-01")]]`) | ||
| mcmp.AssertMatches("select DATE_ADD(MIN(FROM_UNIXTIME(1673444922)),interval -DAYOFWEEK(MIN(FROM_UNIXTIME(1673444922)))+1 DAY)", `[[DATETIME("2023-01-08 13:48:42")]]`) | ||
| mcmp.AssertMatches("select '2020-01-01' + interval month(date_sub(FROM_UNIXTIME(1234), interval 1 month))-1 month", `[[CHAR("2020-12-01")]]`) |
There was a problem hiding this comment.
nit: why change this? the capitalized form is also valid, right?
There was a problem hiding this comment.
@systay It's because we normalize explicit function names here to lowercase for explicitly known parser implementations and I didn't want to diverge from that here. Similarly here, for example month also was emitted as lowercase.
It's also how MySQL itself normalizes it if you use it for example in a default in create table if you then issue a show create table statement. We try to follow that as the canonical form then.
There was a problem hiding this comment.
here you are changing the query we are sending down to vtgate/mysql. why did that need to change? we should follow the canonical form for the printing of ASTs, but we have to be able to receive the queries in any valid form, right?
There was a problem hiding this comment.
Ah yeah, it would also still be valid. I was pretty aggressive though with the find / replace to lowercase it which is why this one was caught as well 😄.
Parse only strict valid units for intervals. We should not allow any arbitrary string value here. We already had the internal enumerable available, but we were not using yet.
Related Issue(s)
In support of #9647 to then make it easier to add support for functions using intervals.
Checklist