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: Add precision to timestamp objects, with 6 as the default precision value #37920

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

rohany
Copy link
Contributor

@rohany rohany commented May 29, 2019

This PR implements support for TIMESTAMP and TIMESTAMPTZ objects to be given a precision when created, for example TIMESTAMP(0). TIMESTAMP objects have precision 6 by default, and only the precision values 0 and 6 are supported right now.

@rohany rohany requested review from a team and solongordon May 29, 2019 19:16
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Looks like a good start. BTW, this was not explicit in the issue but we want to support 0 precision for TIMESTAMPTZ and TIME as well.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @solongordon)

@rohany
Copy link
Contributor Author

rohany commented May 30, 2019

Ok, this is ready for review -- I'll squash the commits and update the messages once it is ready for landing.

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Added a testing suggestion. I'm still puzzling through some of the types stuff.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rohany)


pkg/sql/logictest/testdata/logic_test/timestamp, line 20 at r8 (raw file):


statement ok
CREATE TABLE timestamp_test (x TIMESTAMP(0)); INSERT INTO timestamp_test VALUES ('1-1-18 1:00:00.001'), ('1-1-18 1:00:00.00');

Generally I think we try not to have multiple statements per line in these tests, just to keep things readable.

Actually creating a table seems unnecessary here. You can just do SELECT '1-1-18 1:00:00.001':::TIMESTAMP(0) and verify the result. (Same for all the following tests.)

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

The rest LGTM with some nits. The whole default -1 thing bugs me a little bit but I can't think of a great alternative.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rohany)


pkg/sql/types/types.go, line 1090 at r8 (raw file):

		return "JSONB"
	case TimestampFamily, TimestampTZFamily:
		// This is default timestamp

Maybe clearer to say it's a timestamp with the default precision.


pkg/sql/types/types.go, line 1094 at r8 (raw file):

			return strings.ToUpper(t.Name())
		}
		return fmt.Sprintf("%s(%d)", strings.ToUpper(t.Name()), t.Precision())

Nit: Slightly simpler would be to just do:

if t.Precision() != -1 {
  return fmt.Sprintf("%s(%d)", strings.ToUpper(t.Name()), t.Precision())
}

and just rely on the default case for when precision == -1.


pkg/sql/types/types.go, line 1097 at r8 (raw file):

	case TimeFamily:
		if t.Precision() > 0 {
			return fmt.Sprintf("TIME(%d)", t.Precision())

Nit: Might as well continue using strings.ToUpper(t.Name()) here rather than hard-coding TIME.

@rohany
Copy link
Contributor Author

rohany commented Jun 4, 2019

I don't like the -1 default either, but it is tricky for printing purposes to know whether the timestamp precision is "default 6" or manually set to 6

@solongordon
Copy link
Contributor

The alternative would be to add a boolean field specifying if Precision is set, but not sure that's an improvement in this case.

@rohany
Copy link
Contributor Author

rohany commented Jun 4, 2019

yeah, i would prefer to avoid changing protos and use elsewhere of the type

@rohany rohany force-pushed the timestamp_precision_fix branch 2 times, most recently from 8bc49cc to d8cb722 Compare June 4, 2019 20:05
We now support an optional precision value for timestamp
objects.

Fixes: cockroachdb#32098

Release note (sql change): Implements sql support for timestamp
objects to have an optional precision value
@rohany rohany force-pushed the timestamp_precision_fix branch from d8cb722 to 824ec01 Compare June 4, 2019 20:33
Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rohany)

@rohany
Copy link
Contributor Author

rohany commented Jun 4, 2019

bors r+

craig bot pushed a commit that referenced this pull request Jun 4, 2019
37920: sql: Add 0 precision timestamp objects. r=rohany a=rohany

Progress towards adding 0 precision timestamps in cockroach. This is a preliminary PR, there are probably places that touch this data that I missed, and tests that need to be added.

Co-authored-by: Rohan Yadav <rohany@alumni.cmu.edu>
@craig
Copy link
Contributor

craig bot commented Jun 4, 2019

Build succeeded

@craig craig bot merged commit 824ec01 into cockroachdb:master Jun 4, 2019
@jordanlewis
Copy link
Member

@rohany this is great! Could you please update the PR title and body to match the commit, to make it more obvious that this PR is about more than just 0 precision timestamp objects (which I think it is)?

@rohany rohany changed the title sql: Add 0 precision timestamp objects. sql: Add precision to timestamp objects, with 6 as the default precision value Jun 5, 2019
@rohany
Copy link
Contributor Author

rohany commented Jun 5, 2019

@jordanlewis is that good, or do you have something else in mind?

@jordanlewis
Copy link
Member

The title's good - can you update the body too? (like the first message in the PR). You can just edit it to be the same as your commit message. The reason it's important is to make sure that when someone inevitably goes back to this PR to try to figure out what the change was, they'll be able to understand the final merged state of the PR just by reading the subject.

@rohany
Copy link
Contributor Author

rohany commented Jun 5, 2019

Ok great -- sorry, I didn't know what you meant by update the body!

@jordanlewis
Copy link
Member

Perfect - thanks!

@awoods187
Copy link
Contributor

This pr was for this issue: #32098

@awoods187
Copy link
Contributor

Also related to #16349

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.

5 participants