-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The upgrade downgrade failure is unrelated and being fixed by #13183 |
@@ -174,8 +174,8 @@ func TestIntervalWithMathFunctions(t *testing.T) { | |||
// Set the time zone explicitly to UTC, otherwise the output of FROM_UNIXTIME is going to be dependent | |||
// on the time zone of the system. | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why change this? the capitalized form is also valid, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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