Skip to content

Commit da081c0

Browse files
committed
Add TSTEP function for step-aligned time buckets
1 parent a1ebc88 commit da081c0

File tree

18 files changed

+958
-16
lines changed

18 files changed

+958
-16
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.

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/WindowGroupingAggregatorFunction.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void evaluateFinalWithWindow(
103103
GroupingAggregatorFunction finalAggFunction = finalAgg.aggregatorFunction();
104104
boolean hasNullIntermediateState = addInitialIntermediateInput(finalAggFunction, selected, page);
105105
for (int i = 0; i < selected.getPositionCount(); i++) {
106-
int groupId = selected.getInt(i);
106+
groupId = selected.getInt(i);
107107
mergeBucketsFromWindow(groupId, backwards, page, finalAggFunction, evaluationContext, hasNullIntermediateState);
108108
}
109109
} finally {
@@ -174,7 +174,6 @@ private void mergeBucketsFromWindow(
174174
}
175175
}
176176

177-
<<<<<<< HEAD
178177
/**
179178
* Adds the non-null positions of {@code page} as intermediate input to {@code fn}, using
180179
* {@link Block#asVector()} to skip null-checking on dense blocks. Returns whether any null
@@ -190,15 +189,6 @@ private static boolean addInitialIntermediateInput(GroupingAggregatorFunction fn
190189
if (anyNullable == false) {
191190
fn.addIntermediateInput(0, groups, page);
192191
return false;
193-
=======
194-
private static void addNonNullIntermediateInput(GroupingAggregatorFunction fn, IntVector groups, Page page) {
195-
int[] positions = positionsWithIntermediateState(page);
196-
if (positions.length == 0) {
197-
return;
198-
}
199-
try (IntVector filteredGroups = groups.filter(false, positions); Page filteredPage = filterPage(page, positions)) {
200-
fn.addIntermediateInput(0, filteredGroups, filteredPage);
201-
>>>>>>> eca05d24b96 (Add logic to handle time bucket offset in window functions)
202192
}
203193
int[] positions = new int[page.getPositionCount()];
204194
int count = 0;
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+
;

0 commit comments

Comments
 (0)