Skip to content

Commit c1e0540

Browse files
Merge branch 'main' into pkar/resolve-index-force-reconn
2 parents 389e942 + 404d61c commit c1e0540

File tree

37 files changed

+439
-249
lines changed

37 files changed

+439
-249
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9228000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aggregate_metric_double_typed_block,9227000
1+
esql_timestamps_info,9228000

test/external-modules/esql-heap-attack/src/javaRestTest/java/org/elasticsearch/xpack/esql/heap_attack/HeapAttackIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public void testSortByManyLongsGiantTopN() throws IOException {
169169
.entry("values", List.of(List.of(9)))
170170
.entry("documents_found", greaterThan(0))
171171
.entry("values_loaded", greaterThan(0))
172+
.entry("completion_time_in_millis", greaterThan(0L))
173+
.entry("expiration_time_in_millis", greaterThan(0L))
174+
.entry("start_time_in_millis", greaterThan(0L))
172175
);
173176
}
174177

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,13 +2767,20 @@ protected static MapMatcher getProfileMatcher() {
27672767
.entry("plans", instanceOf(List.class));
27682768
}
27692769

2770-
protected static MapMatcher getResultMatcher(boolean includePartial, boolean includeDocumentsFound) {
2770+
protected static MapMatcher getResultMatcher(boolean includePartial, boolean includeDocumentsFound, boolean includeTimestamps) {
27712771
MapMatcher mapMatcher = matchesMap();
27722772
if (includeDocumentsFound) {
27732773
// Older versions may not return documents_found and values_loaded.
27742774
mapMatcher = mapMatcher.entry("documents_found", greaterThanOrEqualTo(0));
27752775
mapMatcher = mapMatcher.entry("values_loaded", greaterThanOrEqualTo(0));
27762776
}
2777+
if (includeTimestamps) {
2778+
// Older versions may not return start_time_in_millis, completion_time_in_millis and expiration_time_in_millis
2779+
mapMatcher = mapMatcher.entry("start_time_in_millis", greaterThanOrEqualTo(0L));
2780+
mapMatcher = mapMatcher.entry("completion_time_in_millis", greaterThanOrEqualTo(0L));
2781+
mapMatcher = mapMatcher.entry("expiration_time_in_millis", greaterThanOrEqualTo(0L));
2782+
}
2783+
27772784
mapMatcher = mapMatcher.entry("took", greaterThanOrEqualTo(0));
27782785
// Older version may not have is_partial
27792786
if (includePartial) {
@@ -2786,7 +2793,11 @@ protected static MapMatcher getResultMatcher(boolean includePartial, boolean inc
27862793
* Create empty result matcher from result, taking into account all metadata items.
27872794
*/
27882795
protected static MapMatcher getResultMatcher(Map<String, Object> result) {
2789-
return getResultMatcher(result.containsKey("is_partial"), result.containsKey("documents_found"));
2796+
return getResultMatcher(
2797+
result.containsKey("is_partial"),
2798+
result.containsKey("documents_found"),
2799+
result.containsKey("start_time_in_millis")
2800+
);
27902801
}
27912802

27922803
/**

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/tree/Node.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ public List<T> collect(Predicate<? super T> predicate) {
176176
return l.isEmpty() ? emptyList() : l;
177177
}
178178

179+
public <E extends T> List<E> collect(Class<E> typeToken) {
180+
return collect(typeToken, n -> true);
181+
}
182+
183+
public <E extends T> List<E> collect(Class<E> typeToken, Predicate<? super E> predicate) {
184+
List<E> l = new ArrayList<>();
185+
forEachDown(n -> {
186+
if (typeToken.isInstance(n)) {
187+
E e = typeToken.cast(n);
188+
if (predicate.test(e)) {
189+
l.add(e);
190+
}
191+
}
192+
});
193+
return l.isEmpty() ? emptyList() : l;
194+
}
195+
179196
public List<T> collectLeaves() {
180197
return collect(n -> n.children().isEmpty());
181198
}

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterTimeSeriesIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ private boolean capabilitiesSupportedNewAndOld(List<String> requiredCapabilities
311311
}
312312

313313
private void assertResultMap(boolean includeCCSMetadata, Map<String, Object> result, Map<String, Object> expectedResult) {
314-
MapMatcher mapMatcher = getResultMatcher(result.containsKey("is_partial"), result.containsKey("documents_found")).extraOk();
314+
MapMatcher mapMatcher = getResultMatcher(
315+
result.containsKey("is_partial"),
316+
result.containsKey("documents_found"),
317+
result.containsKey("start_time_in_millis")
318+
).extraOk();
315319
if (includeCCSMetadata) {
316320
mapMatcher = mapMatcher.entry("_clusters", any(Map.class));
317321
}

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ private boolean capabilitiesSupportedNewAndOld(List<String> requiredCapabilities
262262
}
263263

264264
private <C, V> void assertResultMap(boolean includeCCSMetadata, Map<String, Object> result, C columns, V values, boolean remoteOnly) {
265-
MapMatcher mapMatcher = getResultMatcher(result.containsKey("is_partial"), result.containsKey("documents_found")).extraOk();
265+
MapMatcher mapMatcher = getResultMatcher(
266+
result.containsKey("is_partial"),
267+
result.containsKey("documents_found"),
268+
result.containsKey("start_time_in_millis")
269+
).extraOk();
266270
if (includeCCSMetadata) {
267271
mapMatcher = mapMatcher.entry("_clusters", any(Map.class));
268272
}
@@ -523,7 +527,11 @@ public void testLookupJoinAliasesSkipOld() throws IOException {
523527
var columns = List.of(Map.of("name", "c", "type", "long"));
524528
var values = List.of(List.of(localDocs.size()));
525529

526-
MapMatcher mapMatcher = getResultMatcher(false, result.containsKey("documents_found")).extraOk();
530+
MapMatcher mapMatcher = getResultMatcher(
531+
false,
532+
result.containsKey("documents_found"),
533+
result.containsKey("start_time_in_millis")
534+
).extraOk();
527535
mapMatcher = mapMatcher.entry("_clusters", any(Map.class));
528536
mapMatcher = mapMatcher.entry("is_partial", true);
529537
assertMap(result, mapMatcher.entry("columns", columns).entry("values", values));

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import static org.hamcrest.Matchers.either;
7575
import static org.hamcrest.Matchers.emptyOrNullString;
7676
import static org.hamcrest.Matchers.equalTo;
77+
import static org.hamcrest.Matchers.greaterThan;
7778
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
7879
import static org.hamcrest.Matchers.hasSize;
7980
import static org.hamcrest.Matchers.is;
@@ -288,7 +289,7 @@ public static RequestObjectBuilder jsonBuilder() throws IOException {
288289

289290
public void testGetAnswer() throws IOException {
290291
Map<String, Object> answer = runEsql(requestObjectBuilder().query("row a = 1, b = 2"));
291-
assertEquals(6, answer.size());
292+
assertEquals(9, answer.size());
292293
assertThat(((Integer) answer.get("took")).intValue(), greaterThanOrEqualTo(0));
293294
Map<String, String> colA = Map.of("name", "a", "type", "integer");
294295
Map<String, String> colB = Map.of("name", "b", "type", "integer");
@@ -300,6 +301,9 @@ public void testGetAnswer() throws IOException {
300301
.entry("values_loaded", 0)
301302
.entry("columns", List.of(colA, colB))
302303
.entry("values", List.of(List.of(1, 2)))
304+
.entry("completion_time_in_millis", greaterThan(0L))
305+
.entry("expiration_time_in_millis", greaterThan(0L))
306+
.entry("start_time_in_millis", greaterThan(0L))
303307
);
304308
}
305309

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeForkRestTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ protected void shouldSkipTest(String testName) throws IOException {
6060
testCase.requiredCapabilities.contains(SUBQUERY_IN_FROM_COMMAND.capabilityName())
6161
);
6262

63-
assumeFalse("Tests using PROMQL are not supported for now", testCase.requiredCapabilities.contains(PROMQL_V0.capabilityName()));
63+
assumeFalse(
64+
"Tests using PROMQL are not supported for now",
65+
testCase.requiredCapabilities.contains(PROMQL_PRE_TECH_PREVIEW_V1.capabilityName())
66+
);
6467

6568
assumeFalse(
6669
"Tests using GROUP_BY_ALL are skipped since we add a new _timeseries field",

x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries-avg-over-time.csv-spec

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ cost:double | time_bucket:datetime
1717
36.375 | 2024-05-10T00:11:00.000Z
1818
;
1919

20+
avg_over_time_of_double_no_grouping_promql
21+
required_capability: promql_pre_tech_preview_v1
22+
TS k8s
23+
| PROMQL step 1m (sum(avg_over_time(network.cost[1m])))
24+
| SORT `sum(avg_over_time(network.cost[1m]))` DESC, step DESC | LIMIT 10;
25+
26+
sum(avg_over_time(network.cost[1m])):double | step:date
27+
69.6875 | 2024-05-10T00:09:00.000Z
28+
56.5625 | 2024-05-10T00:08:00.000Z
29+
49.5 | 2024-05-10T00:17:00.000Z
30+
48.3125 | 2024-05-10T00:22:00.000Z
31+
45.8125 | 2024-05-10T00:15:00.000Z
32+
40.4375 | 2024-05-10T00:06:00.000Z
33+
39.54166666666667 | 2024-05-10T00:13:00.000Z
34+
37.9375 | 2024-05-10T00:12:00.000Z
35+
36.6875 | 2024-05-10T00:19:00.000Z
36+
36.375 | 2024-05-10T00:11:00.000Z
37+
;
38+
2039
avg_over_time_of_double_no_grouping_single_bucket
2140
required_capability: ts_command_v0
2241
required_capability: tbucket
@@ -28,11 +47,11 @@ cost:double | time_bucket:datetime
2847
;
2948

3049
avg_over_time_of_double_no_grouping_single_bucket_promql
31-
required_capability: promql_v0
50+
required_capability: promql_pre_tech_preview_v1
3251
TS k8s
3352
| PROMQL step 1h (sum(avg_over_time(network.cost[1h])));
3453

35-
sum(avg_over_time(network.cost[1h])):double | TBUCKET:date
54+
sum(avg_over_time(network.cost[1h])):double | step:date
3655
56.32254035241995 | 2024-05-10T00:00:00.000Z
3756
;
3857

0 commit comments

Comments
 (0)