-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: respect IntervalStyle for parsing #67210
Conversation
dcc03f4
to
03ddddd
Compare
thanks for the tip-off @mneverov |
7e181a4
to
a0d5114
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @otan)
pkg/cli/sql_util.go, line 446 at r2 (raw file):
// This should really be the same as the session's IntervalStyle // but that only affect for negative intervals in the magnitude
nit: should it say "the only effect for negative intervals is in the magnitude of days"?
had trouble reading this comment
pkg/sql/logictest/testdata/logic_test/interval, line 463 at r3 (raw file):
-10 years -22 months 1 day 01:02:03 -11 years -10 mons 1 day +01:02:03 -10 years 22 months -1 day 01:02:03 -8 years -2 mons -1 days +01:02:03 -10 years 22 months -1 day -01:02:03 -8 years -2 mons -1 days -01:02:03
i noticed in PG the +
sign is very slightly different for the first two rows. i think it puts the +
on the first non-negative one to make it more clear which ones are not negative?
-10 years 22 months 1 day 01:02:03 | -8 years -2 mons +1 day 01:02:03
-10 years -22 months 1 day 01:02:03 | -11 years -10 mons +1 day 01:02:03
-10 years 22 months -1 day 01:02:03 | -8 years -2 mons -1 days +01:02:03
-10 years 22 months -1 day -01:02:03 | -8 years -2 mons -1 days -01:02:03
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
} for style := range duration.IntervalStyle_value {
did this test get moved?
pkg/sql/sem/tree/interval_test.go, line 235 at r2 (raw file):
} for style := range duration.IntervalStyle_value {
did this test get moved?
pkg/sql/sem/tree/pretty_test.go, line 169 at r1 (raw file):
defer log.Scope(t).Close(t) tests := map[string]string{ // Verify that INTERVAL is maintained.
nit: is this comment incorrect now?
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)
pkg/sql/logictest/testdata/logic_test/interval, line 463 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
i noticed in PG the
+
sign is very slightly different for the first two rows. i think it puts the+
on the first non-negative one to make it more clear which ones are not negative?-10 years 22 months 1 day 01:02:03 | -8 years -2 mons +1 day 01:02:03 -10 years -22 months 1 day 01:02:03 | -11 years -10 mons +1 day 01:02:03 -10 years 22 months -1 day 01:02:03 | -8 years -2 mons -1 days +01:02:03 -10 years 22 months -1 day -01:02:03 | -8 years -2 mons -1 days -01:02:03
i've tacked on a commit to fix this bug.
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
did this test get moved?
it just got indented, the test now works over all styles
pkg/sql/sem/tree/interval_test.go, line 235 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
did this test get moved?
it just got indented, the test now works over all styles
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @otan and @rafiss)
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
Previously, otan (Oliver Tan) wrote…
it just got indented, the test now works over all styles
i see.. i was just viewing the diff for the 3rd commit, and it shows that for style := range duration.IntervalStyle_value
was removed from TestValidSQLIntervalSyntax
and TestInvalidSQLIntervalSyntax
. that's what i was asking about. (i do see that the range over all styles was added to other tests though.)
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
that one is still here
ah I remember! it always errored (output is never set), so the logic after the |
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @otan and @rafiss)
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
Previously, otan (Oliver Tan) wrote…
TestValidSQLIntervalSyntax
that one is still here
TestInvalidSQLIntervalSyntax
ah I remember! it always errored (output is never set), so the logic after the
continue
never got hit. i removed it.
it looks like TestValidSQLIntervalSyntax
doesn't have it though :P -- look at lines 183 and 194 of the latest revision where it hardcodes IntervalStyle_POSTGRES
.
But maybe the test should just be renamed if those test cases can't be parsed when using an intervalstyle other than Postgres?
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)
pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
it looks like
TestValidSQLIntervalSyntax
doesn't have it though :P -- look at lines 183 and 194 of the latest revision where it hardcodesIntervalStyle_POSTGRES
.But maybe the test should just be renamed if those test cases can't be parsed when using an intervalstyle other than Postgres?
ah, yes.
woops, unremoved and also fixed a subtle bug that caught. nice catch, don't trust my tired self
c0e34c2
to
cce8226
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!
Reviewed 3 of 4 files at r1, 18 of 24 files at r2, 10 of 10 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)
thanks! bors r=rafiss |
Build failed: |
bors r=rafiss
…On Tue, 13 Jul 2021, 3:54 pm craig[bot], ***@***.***> wrote:
Build failed:
- GitHub CI (Cockroach)
<https://teamcity.cockroachdb.com/viewLog.html?buildId=3175208&buildTypeId=Cockroach_UnitTests>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67210 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA32FQYWX3URZ6KZKIRHHVTTXPIIRANCNFSM47Z25SGQ>
.
|
bors r-
…On Tue, 13 Jul 2021, 4:09 pm Oliver Tan, ***@***.***> wrote:
bors r=rafiss
On Tue, 13 Jul 2021, 3:54 pm craig[bot], ***@***.***> wrote:
> Build failed:
>
> - GitHub CI (Cockroach)
> <https://teamcity.cockroachdb.com/viewLog.html?buildId=3175208&buildTypeId=Cockroach_UnitTests>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#67210 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA32FQYWX3URZ6KZKIRHHVTTXPIIRANCNFSM47Z25SGQ>
> .
>
|
Canceled. |
We currently evaluate intervals in the parsing stage, as opposed to the execution case. It is needed to be done in the execution stage to obey IntervalStyle. This commit changes the parsing of `INTERVAL x` to be a cast `x::INTERVAL` to allow for this. Note this should be `CastPrepend`, but that is a heavy handed fix. Release note: None
bors r=rafiss |
Canceled. |
worst rebase conflict ever! hopefully this will do bors r=rafiss |
Build failed: |
This commit plumbs IntervalStyle to ParseDInterval and associated friends. This is in preparation for respecting IntervalStyle later on. Release note: None
Release note (sql change): When parsing intervals, IntervalStyle is now taken into account. In particular, IntervalStyle = 'sql_standard' will make all interval fields negative if there is a negative symbol at the front, e.g. `-3 years 1 day` would be `-(3 years 1 day)` in sql_standard and `-3 days, 1 day` in postgres DateStyle.
Release note (bug fix): Postgres style intervals now print a `+` sign for day units if the year/month unit preceding was negative (e.g. `-1 year -2 months 2 days` will now print as `-1 year -2 months +2 days`). Release note (bug fix): SQL Standard intervals will omit the day value if the day value is 0
bors r=rafiss |
bors r- |
Canceled. |
bors r=rafiss flake on CI |
Build succeeded: |
See individual commits for details.