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

sql: respect IntervalStyle for parsing #67210

Merged
merged 4 commits into from
Jul 13, 2021

Conversation

otan
Copy link
Contributor

@otan otan commented Jul 5, 2021

See individual commits for details.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@otan otan force-pushed the intervalstyle_fix branch 2 times, most recently from dcc03f4 to 03ddddd Compare July 5, 2021 09:53
@otan otan changed the title [WIP] sql: respect IntervalStyle for parsing sql: respect IntervalStyle for parsing Jul 5, 2021
@otan otan requested review from rafiss and a team July 5, 2021 09:53
@otan otan marked this pull request as ready for review July 5, 2021 09:53
@otan otan requested a review from a team as a code owner July 5, 2021 09:53
@otan
Copy link
Contributor Author

otan commented Jul 5, 2021

thanks for the tip-off @mneverov

@otan otan force-pushed the intervalstyle_fix branch 3 times, most recently from 7e181a4 to a0d5114 Compare July 5, 2021 21:28
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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?

Copy link
Contributor Author

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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.)

@otan
Copy link
Contributor Author

otan commented Jul 8, 2021


pkg/sql/sem/tree/interval_test.go, line 159 at r2 (raw file):

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.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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.

image.png

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?

Copy link
Contributor Author

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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…

image.png

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?

ah, yes.
woops, unremoved and also fixed a subtle bug that caught. nice catch, don't trust my tired self

@otan otan force-pushed the intervalstyle_fix branch 3 times, most recently from c0e34c2 to cce8226 Compare July 9, 2021 05:21
@otan otan requested a review from rafiss July 12, 2021 23:47
Copy link
Collaborator

@rafiss rafiss left a 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: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

thanks!

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

Build failed:

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021 via email

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021 via email

@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

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
@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

Canceled.

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

worst rebase conflict ever!

hopefully this will do

bors r=rafiss

craig bot pushed a commit that referenced this pull request Jul 13, 2021
67210: sql: respect IntervalStyle for parsing r=rafiss a=otan

See individual commits for details.

Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

Build failed:

otan added 3 commits July 13, 2021 18:03
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
@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

bors r=rafiss

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

bors r-

@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

Canceled.

@otan
Copy link
Contributor Author

otan commented Jul 13, 2021

bors r=rafiss

flake on CI

@craig
Copy link
Contributor

craig bot commented Jul 13, 2021

Build succeeded:

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.

3 participants