Skip to content

Commit 726f286

Browse files
authored
Merge branch 'main' into jdk/api-extractor-fix-inherited-access
2 parents 0361af5 + 58451ec commit 726f286

File tree

78 files changed

+982
-622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+982
-622
lines changed

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ tests:
606606
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IncreaseTests
607607
method: testGroupingAggregate {TestCase=<big positive doubles>}
608608
issue: https://github.com/elastic/elasticsearch/issues/135755
609+
- class: org.elasticsearch.xpack.esql.ccq.AllSupportedFieldsIT
610+
method: testFetchDenseVector {pref=null mode=time_series}
611+
issue: https://github.com/elastic/elasticsearch/issues/135762
609612

610613
# Examples:
611614
#

server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ public void onResponse(SearchResponse searchResponse) {
20992099
}
21002100
}
21012101
}
2102-
searchResponseMetrics.incrementResponseCount(responseCountTotalStatus);
2102+
searchResponseMetrics.incrementResponseCount(responseCountTotalStatus, searchRequestAttributes);
21032103

21042104
if (collectCCSTelemetry) {
21052105
extractCCSTelemetry(searchResponse);
@@ -2115,7 +2115,7 @@ public void onResponse(SearchResponse searchResponse) {
21152115

21162116
@Override
21172117
public void onFailure(Exception e) {
2118-
searchResponseMetrics.incrementResponseCount(SearchResponseMetrics.ResponseCountTotalStatus.FAILURE);
2118+
searchResponseMetrics.incrementResponseCount(SearchResponseMetrics.ResponseCountTotalStatus.FAILURE, searchRequestAttributes);
21192119
if (collectCCSTelemetry) {
21202120
usageBuilder.setFailure(e);
21212121
recordTelemetry();

server/src/main/java/org/elasticsearch/rest/action/search/SearchResponseMetrics.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.telemetry.metric.LongHistogram;
1515
import org.elasticsearch.telemetry.metric.MeterRegistry;
1616

17+
import java.util.HashMap;
1718
import java.util.Map;
1819

1920
/**
@@ -83,4 +84,10 @@ public void incrementResponseCount(ResponseCountTotalStatus responseCountTotalSt
8384
Map.of(RESPONSE_COUNT_TOTAL_STATUS_ATTRIBUTE_NAME, responseCountTotalStatus.getDisplayName())
8485
);
8586
}
87+
88+
public void incrementResponseCount(ResponseCountTotalStatus responseCountTotalStatus, Map<String, Object> attributes) {
89+
Map<String, Object> attributesWithStatus = new HashMap<>(attributes);
90+
attributesWithStatus.put(RESPONSE_COUNT_TOTAL_STATUS_ATTRIBUTE_NAME, responseCountTotalStatus.getDisplayName());
91+
responseCountTotalCounter.incrementBy(1L, attributesWithStatus);
92+
}
8693
}

server/src/test/java/org/elasticsearch/search/TelemetryMetrics/SearchResponseCountTelemetryTests.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
import java.util.Arrays;
3232
import java.util.Collection;
3333
import java.util.List;
34+
import java.util.Map;
3435

3536
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
3637
import static org.elasticsearch.index.query.QueryBuilders.simpleQueryStringQuery;
3738
import static org.elasticsearch.rest.action.search.SearchResponseMetrics.RESPONSE_COUNT_TOTAL_COUNTER_NAME;
3839
import static org.elasticsearch.rest.action.search.SearchResponseMetrics.RESPONSE_COUNT_TOTAL_STATUS_ATTRIBUTE_NAME;
40+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
3941
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertScrollResponsesAndHitCount;
42+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
4043
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHitsWithoutFailures;
4144
import static org.hamcrest.Matchers.containsString;
4245
import static org.hamcrest.Matchers.equalTo;
@@ -239,4 +242,48 @@ public void testScrollWithAllShardsFail() throws Exception {
239242
);
240243
});
241244
}
245+
246+
public void testAdditionalSearchAttributes() {
247+
// target index attribute contains the system index name
248+
createIndex(".kibana");
249+
{
250+
SearchResponse searchResponse = client().prepareSearch(".kibana").setQuery(simpleQueryStringQuery("foo")).get();
251+
try {
252+
assertNoFailures(searchResponse);
253+
assertSearchHits(searchResponse);
254+
} finally {
255+
searchResponse.decRef();
256+
}
257+
List<Measurement> measurements = getTestTelemetryPlugin().getLongCounterMeasurement(RESPONSE_COUNT_TOTAL_COUNTER_NAME);
258+
assertEquals(1, measurements.size());
259+
Measurement measurement = measurements.getFirst();
260+
assertEquals(1, measurement.getLong());
261+
Map<String, Object> attributes = measurement.attributes();
262+
assertEquals(4, attributes.size());
263+
assertEquals(".kibana", attributes.get("target"));
264+
assertEquals("hits_only", attributes.get("query_type"));
265+
assertEquals("_score", attributes.get("sort"));
266+
assertEquals("success", attributes.get(RESPONSE_COUNT_TOTAL_STATUS_ATTRIBUTE_NAME));
267+
}
268+
// target index attribute should be "user"
269+
createIndex("custom-index");
270+
{
271+
SearchResponse searchResponse = client().prepareSearch("custom*").setQuery(simpleQueryStringQuery("foo")).get();
272+
try {
273+
assertNoFailures(searchResponse);
274+
assertSearchHits(searchResponse);
275+
} finally {
276+
searchResponse.decRef();
277+
}
278+
List<Measurement> measurements = getTestTelemetryPlugin().getLongCounterMeasurement(RESPONSE_COUNT_TOTAL_COUNTER_NAME);
279+
assertEquals(2, measurements.size());
280+
Measurement measurement = measurements.getLast();
281+
Map<String, Object> attributes = measurement.attributes();
282+
assertEquals(4, attributes.size());
283+
assertEquals("user", attributes.get("target"));
284+
assertEquals("hits_only", attributes.get("query_type"));
285+
assertEquals("_score", attributes.get("sort"));
286+
assertEquals("success", attributes.get(RESPONSE_COUNT_TOTAL_STATUS_ATTRIBUTE_NAME));
287+
}
288+
}
242289
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public abstract class GenerativeRestTest extends ESRestTestCase implements Query
6666
"The incoming YAML document exceeds the limit:", // still to investigate, but it seems to be specific to the test framework
6767
"Data too large", // Circuit breaker exceptions eg. https://github.com/elastic/elasticsearch/issues/130072
6868
"optimized incorrectly due to missing references", // https://github.com/elastic/elasticsearch/issues/131509
69+
"long overflow", // https://github.com/elastic/elasticsearch/issues/135759
70+
"can't build page out of released blocks", // https://github.com/elastic/elasticsearch/issues/135679
6971

7072
// Awaiting fixes for correctness
7173
"Expecting at most \\[.*\\] columns, got \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/129561

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.xpack.esql.generator.command.pipe.EvalGenerator;
1717
import org.elasticsearch.xpack.esql.generator.command.pipe.ForkGenerator;
1818
import org.elasticsearch.xpack.esql.generator.command.pipe.GrokGenerator;
19+
import org.elasticsearch.xpack.esql.generator.command.pipe.InlineStatsGenerator;
1920
import org.elasticsearch.xpack.esql.generator.command.pipe.KeepGenerator;
2021
import org.elasticsearch.xpack.esql.generator.command.pipe.LimitGenerator;
2122
import org.elasticsearch.xpack.esql.generator.command.pipe.LookupJoinGenerator;
@@ -67,6 +68,7 @@ public class EsqlQueryGenerator {
6768
ForkGenerator.INSTANCE,
6869
GrokGenerator.INSTANCE,
6970
KeepGenerator.INSTANCE,
71+
InlineStatsGenerator.INSTANCE,
7072
LimitGenerator.INSTANCE,
7173
LookupJoinGenerator.INSTANCE,
7274
MvExpandGenerator.INSTANCE,
@@ -341,23 +343,43 @@ yield switch ((randomIntBetween(0, 2))) {
341343
}
342344

343345
public static String agg(List<Column> previousOutput) {
344-
String name = randomNumericOrDateField(previousOutput);
346+
String name = randomNumericField(previousOutput);
347+
// complex with numerics
345348
if (name != null && randomBoolean()) {
346-
// numerics only
347-
return switch (randomIntBetween(0, 1)) {
348-
case 0 -> "max(" + name + ")";
349-
default -> "min(" + name + ")";
350-
// TODO more numerics
351-
};
349+
int ops = randomIntBetween(1, 3);
350+
StringBuilder result = new StringBuilder();
351+
for (int i = 0; i < ops; i++) {
352+
if (i > 0) {
353+
result.append(" + ");
354+
}
355+
String agg = switch (randomIntBetween(0, 5)) {
356+
case 0 -> "max(" + name + ")";
357+
case 1 -> "min(" + name + ")";
358+
case 2 -> "avg(" + name + ")";
359+
case 3 -> "median(" + name + ")";
360+
case 4 -> "sum(" + name + ")";
361+
default -> "count(" + name + ")";
362+
// TODO more numerics
363+
};
364+
result.append(agg);
365+
}
366+
return result.toString();
352367
}
353368
// all types
354369
name = randomBoolean() ? randomStringField(previousOutput) : randomNumericOrDateField(previousOutput);
355370
if (name == null) {
356371
return "count(*)";
357372
}
358-
return switch (randomIntBetween(0, 2)) {
373+
if (randomBoolean()) {
374+
String exp = expression(previousOutput, false);
375+
name = exp == null ? name : exp;
376+
}
377+
return switch (randomIntBetween(0, 5)) {
359378
case 0 -> "count(*)";
360379
case 1 -> "count(" + name + ")";
380+
case 2 -> "absent(" + name + ")";
381+
case 3 -> "present(" + name + ")";
382+
case 4 -> "values(" + name + ")";
361383
default -> "count_distinct(" + name + ")";
362384
};
363385
}
@@ -414,9 +436,50 @@ public static String randomName(List<Column> cols, Set<String> allowedTypes) {
414436
return items.get(randomIntBetween(0, items.size() - 1));
415437
}
416438

417-
public static String expression(List<Column> previousOutput) {
418-
// TODO improve!!!
419-
return constantExpression();
439+
/**
440+
* @param previousOutput columns that can be used in the expression
441+
* @param allowConstants if set to true, this will never return a constant expression.
442+
* If no expression can be generated, it will return null
443+
* @return an expression or null
444+
*/
445+
public static String expression(List<Column> previousOutput, boolean allowConstants) {
446+
if (randomBoolean() && allowConstants) {
447+
return constantExpression();
448+
}
449+
if (randomBoolean()) {
450+
StringBuilder result = new StringBuilder();
451+
for (int i = 0; i < randomIntBetween(1, 3); i++) {
452+
String field = randomNumericField(previousOutput);
453+
if (field == null) {
454+
return allowConstants ? constantExpression() : null;
455+
}
456+
if (i > 0) {
457+
result.append(" + ");
458+
}
459+
result.append(field);
460+
}
461+
return result.toString();
462+
}
463+
if (randomBoolean()) {
464+
String field = randomKeywordField(previousOutput);
465+
if (field == null) {
466+
return allowConstants ? constantExpression() : null;
467+
}
468+
return switch (randomIntBetween(0, 3)) {
469+
case 0 -> "substring(" + field + ", 1, 3)";
470+
case 1 -> "to_lower(" + field + ")";
471+
case 2 -> "to_upper(" + field + ")";
472+
default -> "length(" + field + ")";
473+
};
474+
}
475+
if (randomBoolean() || allowConstants == false) {
476+
String field = randomStringField(previousOutput);
477+
if (field == null || randomBoolean()) {
478+
field = randomNumericOrDateField(previousOutput);
479+
}
480+
return field;
481+
}
482+
return allowConstants ? constantExpression() : null;
420483
}
421484

422485
public static String indexPattern(String indexName) {

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/EvalGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.ArrayList;
1616
import java.util.List;
1717
import java.util.Map;
18+
import java.util.stream.Collectors;
1819

1920
import static org.elasticsearch.test.ESTestCase.randomBoolean;
2021
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
@@ -34,6 +35,7 @@ public CommandDescription generate(
3435
) {
3536
StringBuilder cmd = new StringBuilder(" | eval ");
3637
int nFields = randomIntBetween(1, 10);
38+
Map<String, Column> usablePrevious = previousOutput.stream().collect(Collectors.toMap(Column::name, c -> c));
3739
// TODO pass newly created fields to next expressions
3840
var newColumns = new ArrayList<>();
3941
for (int i = 0; i < nFields; i++) {
@@ -46,7 +48,7 @@ public CommandDescription generate(
4648
name = EsqlQueryGenerator.randomIdentifier();
4749
}
4850
}
49-
String expression = EsqlQueryGenerator.expression(previousOutput);
51+
String expression = EsqlQueryGenerator.expression(usablePrevious.values().stream().toList(), true);
5052
if (i > 0) {
5153
cmd.append(",");
5254
}
@@ -56,6 +58,11 @@ public CommandDescription generate(
5658
newColumns.add(unquote(name));
5759
cmd.append(" = ");
5860
cmd.append(expression);
61+
62+
// there could be collisions in many ways, remove all of them
63+
usablePrevious.remove(name);
64+
usablePrevious.remove("`" + name + "`");
65+
usablePrevious.remove(unquote(name));
5966
}
6067
String cmdString = cmd.toString();
6168
return new CommandDescription(EVAL, this, cmdString, Map.ofEntries(Map.entry(NEW_COLUMNS, newColumns)));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.generator.command.pipe;
9+
10+
import org.elasticsearch.xpack.esql.generator.Column;
11+
import org.elasticsearch.xpack.esql.generator.command.CommandGenerator;
12+
13+
import java.util.List;
14+
15+
public class InlineStatsGenerator extends StatsGenerator {
16+
public static final String INLINE_STATS = "inline stats";
17+
public static final CommandGenerator INSTANCE = new InlineStatsGenerator();
18+
19+
@Override
20+
public String commandName() {
21+
return INLINE_STATS;
22+
}
23+
24+
@Override
25+
public ValidationResult validateOutput(
26+
List<CommandDescription> previousCommands,
27+
CommandDescription commandDescription,
28+
List<Column> previousColumns,
29+
List<List<Object>> previousOutput,
30+
List<Column> columns,
31+
List<List<Object>> output
32+
) {
33+
if (commandDescription == EMPTY_DESCRIPTION) {
34+
return VALIDATION_OK;
35+
}
36+
37+
int prevCols = previousColumns.size();
38+
39+
if (previousColumns.stream().anyMatch(x -> x.name().equals("<all-fields-projected>"))) {
40+
// known bug https://github.com/elastic/elasticsearch/issues/121741
41+
prevCols--;
42+
}
43+
44+
if (prevCols > columns.size()) {
45+
return new ValidationResult(false, "Expecting at least [" + prevCols + "] columns, got [" + columns.size() + "]");
46+
}
47+
return VALIDATION_OK;
48+
}
49+
}

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class StatsGenerator implements CommandGenerator {
2424
public static final String STATS = "stats";
2525
public static final CommandGenerator INSTANCE = new StatsGenerator();
2626

27+
public String commandName() {
28+
return STATS;
29+
}
30+
2731
@Override
2832
public CommandDescription generate(
2933
List<CommandDescription> previousCommands,
@@ -38,7 +42,9 @@ public CommandDescription generate(
3842
if (nonNull.isEmpty()) {
3943
return EMPTY_DESCRIPTION;
4044
}
41-
StringBuilder cmd = new StringBuilder(" | stats ");
45+
StringBuilder cmd = new StringBuilder(" | ");
46+
cmd.append(commandName());
47+
cmd.append(" ");
4248
int nStats = randomIntBetween(1, 5);
4349
for (int i = 0; i < nStats; i++) {
4450
String name;
@@ -65,7 +71,7 @@ public CommandDescription generate(
6571
cmd.append(" by " + col);
6672
}
6773
}
68-
return new CommandDescription(STATS, this, cmd.toString(), Map.of());
74+
return new CommandDescription(commandName(), this, cmd.toString(), Map.of());
6975
}
7076

7177
@Override

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/ForkIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class ForkIT extends AbstractEsqlIntegTestCase {
3232

3333
@Before
3434
public void setupIndex() {
35-
assumeTrue("requires FORK capability", EsqlCapabilities.Cap.FORK_V9.isEnabled());
3635
createAndPopulateIndices();
3736
}
3837

0 commit comments

Comments
 (0)