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

Add Date, Timestamp and Interval types. #2314

Merged
merged 3 commits into from
Sep 3, 2015
Merged

Add Date, Timestamp and Interval types. #2314

merged 3 commits into from
Sep 3, 2015

Conversation

vivekmenezes
Copy link
Contributor

No description provided.

@vivekmenezes
Copy link
Contributor Author

This change is a first step towards introducing Date, Timestamp and Interval types. It still requires values to be cast when specifying them in sql to convert them to the correct type.

@vivekmenezes
Copy link
Contributor Author

Hmmm, I can't use time.Time to represent a Date. I'm already hitting truncation related inaccuracies. I'll change the representation.


func (d DDate) String() string {
year, month, day := d.Date()
return fmt.Sprintf("%4d-%02d-%02d", year, month, day)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is simply and obvious, though I'm wondering if you should use Time.Format() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@petermattis
Copy link
Collaborator

Generally looks good. I'll need to give this another pass later as it is quite a substantial addition. Pretty nice how the date/timestamp/interval stuff maps to time.Time and time.Duration.

As a follow-up, it would be good to add support for various time related functions such as CURRENT_{DATE,TIMESTAMP}() and EXTRACT(part from date).

}
t, err = time.Parse(timestampWithNamedZoneFormat, str)
if err == nil {
// This is more involved. See https://github.com/golang/go/issues/12388
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like the bug you're pointing to only affects the Go playground. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A couple of issues here. A shortform like PST can be interpreted in two ways PST US and PST phillipines
See:
http://www.timeanddate.com/time/zones/

Secondly GO doesn't reliably parse and interpret these without passing in a location. There is no way to load the entire database and parse. Also it's not clear whether we want to do that to support this feature.

I think we want to have the user SET TIME ZONE and use that that time zone to time.ParseInLocation()

Copy link
Contributor

Choose a reason for hiding this comment

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

That issue doesn't seem to provide useful context here. Can you update this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment and added a TODO.

@@ -441,15 +589,27 @@ var binOps = map[binArgs]func(Datum, Datum) (Datum, error){

// TODO(pmattis): Overflow/underflow checks?

// TODO(pmattis): Should we allow the implicit conversion from int to float
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the issue is closed

Copy link
Contributor

Choose a reason for hiding this comment

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

this TODO is clearly not resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhap it needs to be reworded. The implicit casts were removed in

#1793

Did you have anything specific in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this comment is ambiguous. I was thinking it was referring to the (int, int) case which still casts to floats. I guess this is OK to remove.

@bdarnell
Copy link
Contributor

bdarnell commented Sep 1, 2015

I'm not sure about the way we're handling time zones here. MySQL's timestamps do not contain any time zone information; postgres has a separate type for "timestamp with time zone", but they recommend not using it (a UTC offset isn't enough; real time-zone aware applications need to know the time zone name, not just a single offset).

I think we should probably store timestamps as UTC with no offset information; supporting time zones properly will require a lot more thought.

// IsMin implements the Datum interface.
func (d DTimestamp) IsMin() bool {
// Subtracting 1 underflows to a larger value.
return d.Time.Before(d.Time.Add(-1))
Copy link
Contributor

Choose a reason for hiding this comment

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

.Time

@tamird
Copy link
Contributor

tamird commented Sep 3, 2015

This turned out to be a non-trivial rebase, so I went ahead and did it. It's on my fork here: https://github.com/tamird/cockroach/tree/vivek/time.

To get it: git remote add tamird git@github.com:tamird/cockroach.git && git checkout tamird/vivek/time

{`1::decimal`, `invalid cast: int -> DECIMAL`},
{`1::date`, `invalid cast: int -> DATE`},
{`1::time`, `invalid cast: int -> TIME`},
{`1::timestamp`, `invalid cast: int -> TIMESTAMP`},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken these tests out because they are implemented elsewhere

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

This does add in the three types but the
usage of these types is rather restrictive
(you need to explictly cast a string to these types).
Making these types more user friendly will be
implemented as a followup.
@tamird
Copy link
Contributor

tamird commented Sep 3, 2015

LGTM

vivekmenezes added a commit that referenced this pull request Sep 3, 2015
Add Date, Timestamp and Interval types.
@vivekmenezes vivekmenezes merged commit c0944b9 into master Sep 3, 2015
@vivekmenezes vivekmenezes deleted the vivek/time branch September 3, 2015 01:42
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.

None yet

5 participants