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

feat: add current_date and current_timestamp functions #548

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions extensions/functions_datetime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ scalar_functions:
* ISO_YEAR Return the ISO 8601 week-numbering year. First week of an ISO year has the majority (4 or more) of
its days in January.
* US_YEAR Return the US epidemiological year. First week of US epidemiological year has the majority (4 or more)
of its days in January. Last week of US epidemiological year has the year's last Wednesday in it. US
of its days in January. Last week of US epidemiological year has the year's last Wednesday in it. US
epidemiological week starts on Sunday.
* QUARTER Return the number of the quarter within the year. January 1 through March 31 map to the first quarter,
April 1 through June 30 map to the second quarter, etc.
Expand Down Expand Up @@ -57,7 +57,7 @@ scalar_functions:
* MONDAY_WEEK, SUNDAY_WEEK, ISO_WEEK, and US_WEEK return values in range 0-52

The indexing option must be specified when the component is QUARTER, MONTH, DAY, DAY_OF_YEAR,
MONDAY_DAY_OF_WEEK, SUNDAY_DAY_OF_WEEK, MONDAY_WEEK, SUNDAY_WEEK, ISO_WEEK, or US_WEEK. The
MONDAY_DAY_OF_WEEK, SUNDAY_DAY_OF_WEEK, MONDAY_WEEK, SUNDAY_WEEK, ISO_WEEK, or US_WEEK. The
indexing option cannot be specified when the component is YEAR, ISO_YEAR, US_YEAR, HOUR, MINUTE, SECOND,
MILLISECOND, MICROSECOND, SUBSECOND, UNIX_TIME, or TIMEZONE_OFFSET.

Expand Down Expand Up @@ -688,3 +688,29 @@ scalar_functions:
- name: origin
value: time
return: time
-
name: "current_date"
description: >-
Return the current date.

Choose a reason for hiding this comment

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

Is it obvious that this intended to be in UTC?

Unlike timestamp, the date doesn't have enough information to do time zone conversion, so a parameter or separate function would be needed to be able to support both.

Copy link
Member

Choose a reason for hiding this comment

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

The options I see are using the locale the server was set up with and UTC. So perhaps we need an option. That could also apply to current_timestamp (either to return a timestamp with the timezone of current or UTC).

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively if all of the engines just return UTC then we should require that.


The `mode` option determines how often the date is evaluated. STREAMING mode
evaluates the current date for each row. BATCH mode evaluates the current date
once and uses the same result for every call to this function in the query.
impls:
- args:
- name: mode
options: [ STREAMING, BATCH ]
return: date
-
name: "current_timestamp"
description: >-
Return the current timestamp.

The `mode` option determines how often the timestamp is evaluated. STREAMING mode
evaluates the current timestamp for each row. BATCH mode evaluates the current
timestamp once and uses the same result for every call to this function in the query.
impls:
- args:
- name: mode
options: [ STREAMING, BATCH ]
return: timestamp