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 important timestamp/date builtins. #2420

Merged
merged 2 commits into from
Sep 9, 2015
Merged

Add important timestamp/date builtins. #2420

merged 2 commits into from
Sep 9, 2015

Conversation

vivekmenezes
Copy link
Contributor

closes #2329

returnType: DummyFloat,
fn: func(args DTuple) (Datum, error) {
t := args[1].(DTimestamp)
s := strings.ToLower(string(args[0].(DString)))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: t and s are not very descriptive variable names

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

true

query T
SELECT now() - current_timestamp < interval '1s'
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like some of these work with or without parens, while others require parens. We should have a test that current_timestamp() works and now doesn't.

@@ -110,6 +110,8 @@ var keywords = map[string]int{
"DATABASES": DATABASES,
"DATE": DATE,
"DAY": DAY,
"DAYOFWEEK": DAYOFWEEK,
"DAYOFYEAR": DAYOFYEAR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, I'm pretty sure you don't have to add all of these here and you don't have to add them to sql.ly either. The extract_arg rule accepts IDENT which will capture all of these strings.

@vivekmenezes
Copy link
Contributor Author

related issue #2427

@petermattis
Copy link
Collaborator

LGTM

@@ -470,3 +566,12 @@ func datumToRawString(datum Datum) (string, error) {

return "", fmt.Errorf("argument type unsupported: %s", datum.Type())
}

var nowImpl = builtin{
Copy link
Contributor

Choose a reason for hiding this comment

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

can you put this near the other var? weird to have it here.

@tamird
Copy link
Contributor

tamird commented Sep 9, 2015

LGTM

vivekmenezes added a commit that referenced this pull request Sep 9, 2015
Add important timestamp/date builtins.
@vivekmenezes vivekmenezes merged commit 527af89 into master Sep 9, 2015
@vivekmenezes vivekmenezes deleted the vivek/set branch September 9, 2015 23:56
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.

sql: Add useful Date/Timestamp functions.
4 participants