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 builtin function UNIX_TIMESTAMP #2369

Merged
merged 9 commits into from
Jan 5, 2017

Conversation

tiancaiamao
Copy link
Contributor

For issue #236

@@ -745,3 +745,43 @@ func parseDayInterval(sc *variable.StatementContext, value types.Datum) (int64,
}
return value.ToInt64(sc)
}

func builtinUnixTimestamp(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Add reference.

return
}
if e != nil {
return
Copy link
Member

Choose a reason for hiding this comment

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

return d, errors.Trace(e)?

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 find mysql default behavior is return 0, when input data is wrong...

@@ -278,6 +278,7 @@ import (
trim "TRIM"
rtrim "RTRIM"
ucase "UCASE"
unixTimestamp "UNIX_TIMESTAMP"
Copy link
Member

Choose a reason for hiding this comment

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

Is UNIX_TIMESTAMP a keyword or non-keyword-token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not a keyword or non-keyword.
https://dev.mysql.com/doc/refman/5.7/en/keywords.html

@shenli
Copy link
Member

shenli commented Jan 1, 2017

@tiancaiamao Please fix CI.

@tiancaiamao
Copy link
Contributor Author

PTAL

@zimulala
Copy link
Contributor

zimulala commented Jan 4, 2017

@tiancaiamao Fix the conflict.

Conflicts:
	expression/builtin_time_test.go
@zimulala
Copy link
Contributor

zimulala commented Jan 4, 2017

LGTM

var (
t types.Time
t1 time.Time
e error
Copy link
Member

Choose a reason for hiding this comment

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

There exists an err so you needn't to declare an error e.

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 know, but if I use if err != nil { return } , this function would return error, which is not the same as mysql behavior.

@shenli
Copy link
Member

shenli commented Jan 4, 2017

Ping @tiancaiamao

Conflicts:
	plan/typeinferer_test.go
@hanfei1991
Copy link
Member

LGTM

@tiancaiamao
Copy link
Contributor Author

For invalid input, select UNIX_TIMESTAMP(xxx) will return 0 and have warning, insert that value to column would get error.
I change the code to return error when mysql have warning.
PTAL @shenli

@tiancaiamao tiancaiamao merged commit a44d9c3 into master Jan 5, 2017
@tiancaiamao tiancaiamao deleted the tiancaiamao/unix-timestamp branch January 5, 2017 06:09
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.

4 participants