Skip to content

Commit 5dc190c

Browse files
committed
Add TSTEP function for step-aligned time buckets
1 parent eca05d2 commit 5dc190c

File tree

17 files changed

+957
-5
lines changed

17 files changed

+957
-5
lines changed

docs/reference/query-languages/esql/_snippets/functions/description/tstep.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/examples/tstep.md

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/tstep.md

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/tstep.md

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/tstep.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/images/functions/tstep.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/reference/query-languages/esql/kibana/definition/functions/tstep.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/docs/functions/tstep.md

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// TSTEP-specific tests
2+
3+
tstepByTenMinutesDuration
4+
required_capability: tstep
5+
6+
FROM sample_data
7+
| WHERE TRANGE("2023-10-23T12:15:00.000Z", "2023-10-23T13:55:01.543Z")
8+
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TSTEP(10 minutes)
9+
| SORT min
10+
;
11+
ignoreOrder:true
12+
13+
min:datetime | max:datetime | bucket:datetime
14+
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:25:01.543Z
15+
2023-10-23T12:27:28.948Z | 2023-10-23T12:27:28.948Z | 2023-10-23T12:35:01.543Z
16+
2023-10-23T13:33:34.937Z | 2023-10-23T13:33:34.937Z | 2023-10-23T13:35:01.543Z
17+
2023-10-23T13:51:54.732Z | 2023-10-23T13:55:01.543Z | 2023-10-23T13:55:01.543Z
18+
;
19+
20+
tstepByTenMinutesDurationAsString
21+
required_capability: implicit_casting_string_literal_to_temporal_amount
22+
required_capability: tstep
23+
24+
FROM sample_data
25+
| WHERE TRANGE("2023-10-23T12:15:00.000Z", "2023-10-23T13:55:01.543Z")
26+
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TSTEP("10 minutes")
27+
| SORT min
28+
;
29+
ignoreOrder:true
30+
31+
min:datetime | max:datetime | bucket:datetime
32+
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:25:01.543Z
33+
2023-10-23T12:27:28.948Z | 2023-10-23T12:27:28.948Z | 2023-10-23T12:35:01.543Z
34+
2023-10-23T13:33:34.937Z | 2023-10-23T13:33:34.937Z | 2023-10-23T13:35:01.543Z
35+
2023-10-23T13:51:54.732Z | 2023-10-23T13:55:01.543Z | 2023-10-23T13:55:01.543Z
36+
;
37+
38+
docsTStepByOneHourDuration
39+
required_capability: tstep
40+
41+
// tag::docsTStepByOneHourDuration[]
42+
FROM sample_data
43+
| WHERE TRANGE("2023-10-23T12:15:00.000Z", "2023-10-23T13:55:01.543Z")
44+
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TSTEP(1 hour)
45+
| SORT min
46+
// end::docsTStepByOneHourDuration[]
47+
;
48+
ignoreOrder:true
49+
50+
// tag::docsTStepByOneHourDuration-result[]
51+
min:datetime | max:datetime | bucket:datetime
52+
2023-10-23T12:15:03.360Z | 2023-10-23T12:27:28.948Z | 2023-10-23T12:55:01.543Z
53+
2023-10-23T13:33:34.937Z | 2023-10-23T13:55:01.543Z | 2023-10-23T13:55:01.543Z
54+
// end::docsTStepByOneHourDuration-result[]
55+
;
56+
57+
docsTStepByOneHourDurationAsString
58+
required_capability: implicit_casting_string_literal_to_temporal_amount
59+
required_capability: tstep
60+
61+
// tag::docsTStepByOneHourDurationAsString[]
62+
FROM sample_data
63+
| WHERE TRANGE("2023-10-23T12:15:00.000Z", "2023-10-23T13:55:01.543Z")
64+
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TSTEP("1 hour")
65+
| SORT min
66+
// end::docsTStepByOneHourDurationAsString[]
67+
;
68+
ignoreOrder:true
69+
70+
// tag::docsTStepByOneHourDurationAsString-result[]
71+
min:datetime | max:datetime | bucket:datetime
72+
2023-10-23T12:15:03.360Z | 2023-10-23T12:27:28.948Z | 2023-10-23T12:55:01.543Z
73+
2023-10-23T13:33:34.937Z | 2023-10-23T13:55:01.543Z | 2023-10-23T13:55:01.543Z
74+
// end::docsTStepByOneHourDurationAsString-result[]
75+
;
76+
77+
tstepWithTimezoneAndDuration
78+
required_capability: global_timezone_parameter_with_output
79+
required_capability: tstep
80+
81+
SET time_zone = "+05:00"\;
82+
FROM sample_data
83+
| WHERE TRANGE("2023-10-23T12:15:00.000Z", "2023-10-23T13:55:01.543Z")
84+
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TSTEP(1 hour)
85+
| SORT min
86+
;
87+
ignoreOrder:true
88+
89+
min:datetime | max:datetime | bucket:datetime
90+
2023-10-23T12:15:03.360Z | 2023-10-23T12:27:28.948Z | 2023-10-23T12:55:01.543Z
91+
2023-10-23T13:33:34.937Z | 2023-10-23T13:55:01.543Z | 2023-10-23T13:55:01.543Z
92+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,11 @@ public enum Cap {
15581558
*/
15591559
TBUCKET,
15601560

1561+
/**
1562+
* Support for tstep function
1563+
*/
1564+
TSTEP,
1565+
15611566
/**
15621567
* Allow qualifiers in attribute names.
15631568
*/

0 commit comments

Comments
 (0)