-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ES|QL][DOCS] Add docs for date_period and time_duration #116368
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a02e9b0
add docs for date_period and time_duration
fang-xing-esql b3dabf6
add docs for date_period and time_duration
fang-xing-esql f22f43b
update docs
fang-xing-esql c73583c
update docs
fang-xing-esql 5a0d525
update docs
fang-xing-esql 4f33792
Merge branch 'main' into time-spans-doc
fang-xing-esql 4eeb682
Merge branch 'main' into time-spans-doc
fang-xing-esql 96fe148
update docs according to review comments
fang-xing-esql e9bc792
update docs according to review comments
fang-xing-esql da25762
update according to review comments
fang-xing-esql File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[[esql-time-spans]] | ||
=== {esql} time spans | ||
|
||
++++ | ||
<titleabbrev>Time spans</titleabbrev> | ||
++++ | ||
|
||
Time spans provide a way of describing a specific period of time that separates two datetime values. There are currently two supported types of time spans, `DATE_PERIOD` specifies intervals in years, quarters, months, weeks and days, and `TIME_DURATION` specifies intervals in hours, minutes, seconds and milliseconds. | ||
|
||
The time span contains two elements, an integer value and a temporal unit, both of them are required when specifying a time span. | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Time spans are often used in datetime related grouping functions like <<esql-bucket, BUCKET>>, scalar functions like <<esql-date_trunc, DATE_TRUNC>> and arithmetic operators like `+` and `-`. There are conversions functions that can convert string literals to time spans, <<esql-to_dateperiod, TO_DATEPERIOD>>, <<esql-to_timeduration, TO_TIMEDURATION>> and their corresponding cast operators `::DATE_PERIOD` and `::TIME_DURATION`. | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[float] | ||
=== Examples of using time spans in {esql} | ||
|
||
With `BUCKET` | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[source, esql] | ||
---- | ||
FROM employees | ||
| STATS hires_per_week = COUNT(*) BY week = BUCKET(hire_date, 1 week) | ||
| SORT week | ||
---- | ||
|
||
With `DATE_TRUNC` | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[source, esql] | ||
---- | ||
FROM employees | ||
| EVAL x = date_trunc(240 hours, hire_date) | ||
---- | ||
|
||
With `+` and/or `-` | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[source, esql] | ||
---- | ||
FROM employees | ||
| EVAL x = hire_date + 1 month - 1 day | ||
---- | ||
fang-xing-esql marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
When a time span is provided as a name parameter in string format, `TO_DATEPERIOD`, `::DATE_PERIOD`, `TO_TIMEDURATION` or `::TIME_DURATION` can be used to convert it to its corresponding time span value. | ||
[source, esql] | ||
---- | ||
POST /_query | ||
{ | ||
"query": """ | ||
FROM employees | ||
| EVAL x = hire_date + ?timespan::DATE_PERIOD, y = hire_date - TO_DATEPERIOD(?timespan) | ||
""", | ||
"params": [{"timespan" : "1 day"}] | ||
} | ||
---- | ||
|
||
|
||
[float] | ||
=== Supported Temporal Units | ||
|
||
The supported temporal units are listed in the following table | ||
|
||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
Temporal Units|Valid Abbreviations | ||
year|y, yr, years | ||
quarter|q, quarters | ||
month|mo, months | ||
week|w, weeks | ||
day|d, days | ||
hour|h, hours, | ||
minute|min, minutes | ||
second|s, sec, seconds | ||
millisecond|ms, milliseconds | ||
|=== | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.