Skip to content

Commit 2584aa4

Browse files
Merge remote-tracking branch 'upstream/8.19' into disableCaseInsensitive
2 parents 7f388b1 + be7f820 commit 2584aa4

File tree

18 files changed

+253
-149
lines changed

18 files changed

+253
-149
lines changed

server/src/test/java/org/elasticsearch/common/util/concurrent/AbstractAsyncTaskTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ protected void runInternal() {
5959
try {
6060
barrier1.await();
6161
} catch (Exception e) {
62+
logger.error("barrier1 interrupted", e);
6263
fail("interrupted");
6364
}
6465
count.incrementAndGet();
6566
try {
6667
barrier2.await();
6768
} catch (Exception e) {
69+
logger.error("barrier2 interrupted", e);
6870
fail("interrupted");
6971
}
7072
if (shouldRunThrowException) {
@@ -112,6 +114,7 @@ protected void runInternal() {
112114
try {
113115
barrier.await();
114116
} catch (Exception e) {
117+
logger.error("barrier interrupted", e);
115118
fail("interrupted");
116119
}
117120
if (shouldRunThrowException) {

test/external-modules/error-query/src/javaRestTest/java/org/elasticsearch/test/esql/EsqlPartialResultsIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public void testFailureFromRemote() throws Exception {
214214
}
215215

216216
public void testAllShardsFailed() throws Exception {
217+
assumeTrue(
218+
"fail functionality is not enabled",
219+
clusterHasCapability("POST", "/_query", List.of(), List.of("fail_if_all_shards_fail")).orElse(false)
220+
);
217221
setupRemoteClusters();
218222
populateIndices();
219223
try {
@@ -232,6 +236,26 @@ public void testAllShardsFailed() throws Exception {
232236
}
233237
}
234238

239+
public void testAllShardsFailedOldBehavior() throws Exception {
240+
// TODO: drop this once we no longer support the old behavior
241+
assumeFalse(
242+
"fail functionality is enabled",
243+
clusterHasCapability("POST", "/_query", List.of(), List.of("fail_if_all_shards_fail")).orElse(false)
244+
);
245+
setupRemoteClusters();
246+
populateIndices();
247+
try {
248+
Request request = new Request("POST", "/_query");
249+
request.setJsonEntity("{\"query\": \"FROM " + "*:failing*" + " | LIMIT 100\"}");
250+
request.addParameter("allow_partial_results", "true");
251+
Response resp = client().performRequest(request);
252+
Map<String, Object> results = entityAsMap(resp);
253+
assertThat(results.get("is_partial"), equalTo(true));
254+
} finally {
255+
removeRemoteCluster();
256+
}
257+
}
258+
235259
private void setupRemoteClusters() throws IOException {
236260
String settings = String.format(Locale.ROOT, """
237261
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void testStopQuery() throws Exception {
129129
}
130130

131131
public void testStopQueryLocal() throws Exception {
132+
assumeTrue("Pragma does not work in release builds", Build.current().isSnapshot());
132133
Map<String, Object> testClusterInfo = setupClusters(3);
133134
int remote1NumShards = (Integer) testClusterInfo.get("remote1.num_shards");
134135
int remote2NumShards = (Integer) testClusterInfo.get("remote2.num_shards");

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,12 @@ public enum Cap {
10301030
* Forbid usage of brackets in unquoted index and enrich policy names
10311031
* https://github.com/elastic/elasticsearch/issues/130378
10321032
*/
1033-
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES;
1033+
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES,
1034+
1035+
/**
1036+
* Fail if all shards fail
1037+
*/
1038+
FAIL_IF_ALL_SHARDS_FAIL(Build.current().isSnapshot());
10341039

10351040
private final boolean enabled;
10361041

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.transport.TransportException;
4444
import org.elasticsearch.transport.TransportRequest;
4545
import org.elasticsearch.transport.TransportService;
46+
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
4647
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
4748
import org.elasticsearch.xpack.esql.action.EsqlQueryAction;
4849
import org.elasticsearch.xpack.esql.core.expression.Attribute;
@@ -399,6 +400,9 @@ private static void updateExecutionInfoAfterCoordinatorOnlyQuery(EsqlExecutionIn
399400
* which doesn't consider the failures from the remote clusters when skip_unavailable is true.
400401
*/
401402
static void failIfAllShardsFailed(EsqlExecutionInfo execInfo, List<Page> finalResults) {
403+
if (EsqlCapabilities.Cap.FAIL_IF_ALL_SHARDS_FAIL.isEnabled() == false) {
404+
return;
405+
}
402406
// do not fail if any final result has results
403407
if (finalResults.stream().anyMatch(p -> p.getPositionCount() > 0)) {
404408
return;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.expression.function.scalar.string;
9+
10+
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
13+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
16+
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
17+
import org.elasticsearch.xpack.esql.core.tree.Source;
18+
import org.elasticsearch.xpack.esql.core.type.DataType;
19+
import org.elasticsearch.xpack.esql.core.type.EsField;
20+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
21+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
22+
23+
import java.util.Map;
24+
25+
import static org.hamcrest.Matchers.equalTo;
26+
27+
public class EndsWithStaticTests extends ESTestCase {
28+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
29+
EndsWith function = new EndsWith(
30+
Source.EMPTY,
31+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD),
32+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD)
33+
);
34+
35+
ESTestCase.assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
36+
}
37+
38+
public void testLuceneQuery_NonFoldableSuffix_NonTranslatable() {
39+
EndsWith function = new EndsWith(
40+
Source.EMPTY,
41+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
42+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true))
43+
);
44+
45+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
46+
}
47+
48+
public void testLuceneQuery_NonFoldableSuffix_Translatable() {
49+
EndsWith function = new EndsWith(
50+
Source.EMPTY,
51+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
52+
new Literal(Source.EMPTY, new BytesRef("a*b?c\\"), DataType.KEYWORD)
53+
);
54+
55+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
56+
57+
Query query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
58+
59+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "*a\\*b\\?c\\\\", false, false)));
60+
}
61+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/EndsWithTests.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,15 @@
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

1313
import org.apache.lucene.util.BytesRef;
14-
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
16-
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
17-
import org.elasticsearch.xpack.esql.core.expression.Literal;
18-
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
1915
import org.elasticsearch.xpack.esql.core.tree.Source;
2016
import org.elasticsearch.xpack.esql.core.type.DataType;
21-
import org.elasticsearch.xpack.esql.core.type.EsField;
2217
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
2318
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
24-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
25-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2619
import org.hamcrest.Matcher;
2720

2821
import java.util.LinkedList;
2922
import java.util.List;
30-
import java.util.Map;
3123
import java.util.function.Supplier;
3224

3325
import static org.hamcrest.Matchers.equalTo;
@@ -106,34 +98,4 @@ private static TestCaseSupplier.TestCase testCase(
10698
protected Expression build(Source source, List<Expression> args) {
10799
return new EndsWith(source, args.get(0), args.get(1));
108100
}
109-
110-
public void testLuceneQuery_AllLiterals_NonTranslatable() {
111-
var function = new EndsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
112-
113-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
114-
}
115-
116-
public void testLuceneQuery_NonFoldableSuffix_NonTranslatable() {
117-
var function = new EndsWith(
118-
Source.EMPTY,
119-
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
120-
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true))
121-
);
122-
123-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
124-
}
125-
126-
public void testLuceneQuery_NonFoldableSuffix_Translatable() {
127-
var function = new EndsWith(
128-
Source.EMPTY,
129-
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
130-
Literal.keyword(Source.EMPTY, "a*b?c\\")
131-
);
132-
133-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
134-
135-
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
136-
137-
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "*a\\*b\\?c\\\\", false, false)));
138-
}
139101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.expression.function.scalar.string;
9+
10+
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
13+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
16+
import org.elasticsearch.xpack.esql.core.tree.Source;
17+
import org.elasticsearch.xpack.esql.core.type.DataType;
18+
import org.elasticsearch.xpack.esql.core.type.EsField;
19+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
20+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
21+
22+
import java.util.Map;
23+
24+
import static org.hamcrest.Matchers.equalTo;
25+
26+
public class StartsWithStaticTests extends ESTestCase {
27+
28+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
29+
var function = new StartsWith(
30+
Source.EMPTY,
31+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD),
32+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD)
33+
);
34+
35+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
36+
}
37+
38+
public void testLuceneQuery_NonFoldablePrefix_NonTranslatable() {
39+
var function = new StartsWith(
40+
Source.EMPTY,
41+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
42+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true))
43+
);
44+
45+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
46+
}
47+
48+
public void testLuceneQuery_NonFoldablePrefix_Translatable() {
49+
var function = new StartsWith(
50+
Source.EMPTY,
51+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true)),
52+
new Literal(Source.EMPTY, new BytesRef("a*b?c\\"), DataType.KEYWORD)
53+
);
54+
55+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
56+
57+
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
58+
59+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "a\\*b\\?c\\\\*", false, false)));
60+
}
61+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/StartsWithTests.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

1313
import org.apache.lucene.util.BytesRef;
14-
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
16-
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
17-
import org.elasticsearch.xpack.esql.core.expression.Literal;
18-
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
1915
import org.elasticsearch.xpack.esql.core.tree.Source;
2016
import org.elasticsearch.xpack.esql.core.type.DataType;
21-
import org.elasticsearch.xpack.esql.core.type.EsField;
2217
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
2318
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
24-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
25-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2619

2720
import java.util.ArrayList;
2821
import java.util.List;
29-
import java.util.Map;
3022
import java.util.function.Supplier;
3123

3224
import static org.hamcrest.Matchers.equalTo;
@@ -66,34 +58,4 @@ public static Iterable<Object[]> parameters() {
6658
protected Expression build(Source source, List<Expression> args) {
6759
return new StartsWith(source, args.get(0), args.get(1));
6860
}
69-
70-
public void testLuceneQuery_AllLiterals_NonTranslatable() {
71-
var function = new StartsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
72-
73-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
74-
}
75-
76-
public void testLuceneQuery_NonFoldablePrefix_NonTranslatable() {
77-
var function = new StartsWith(
78-
Source.EMPTY,
79-
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
80-
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true))
81-
);
82-
83-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
84-
}
85-
86-
public void testLuceneQuery_NonFoldablePrefix_Translatable() {
87-
var function = new StartsWith(
88-
Source.EMPTY,
89-
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true)),
90-
Literal.keyword(Source.EMPTY, "a*b?c\\")
91-
);
92-
93-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
94-
95-
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
96-
97-
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "a\\*b\\?c\\\\*", false, false)));
98-
}
9961
}
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.expression.predicate.operator.comparison;
9+
10+
import org.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
12+
import org.elasticsearch.xpack.esql.core.expression.Literal;
13+
14+
import java.util.Arrays;
15+
16+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.L;
17+
import static org.elasticsearch.xpack.esql.core.expression.Literal.NULL;
18+
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
19+
20+
public class InStaticTests extends ESTestCase {
21+
private static final Literal ONE = L(1);
22+
private static final Literal TWO = L(2);
23+
private static final Literal THREE = L(3);
24+
25+
public void testInWithContainedValue() {
26+
In in = new In(EMPTY, TWO, Arrays.asList(ONE, TWO, THREE));
27+
assertTrue((Boolean) in.fold(FoldContext.small()));
28+
}
29+
30+
public void testInWithNotContainedValue() {
31+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, TWO));
32+
assertFalse((Boolean) in.fold(FoldContext.small()));
33+
}
34+
35+
public void testHandleNullOnLeftValue() {
36+
In in = new In(EMPTY, NULL, Arrays.asList(ONE, TWO, THREE));
37+
assertNull(in.fold(FoldContext.small()));
38+
in = new In(EMPTY, NULL, Arrays.asList(ONE, NULL, THREE));
39+
assertNull(in.fold(FoldContext.small()));
40+
41+
}
42+
43+
public void testHandleNullsOnRightValue() {
44+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, NULL, THREE));
45+
assertTrue((Boolean) in.fold(FoldContext.small()));
46+
in = new In(EMPTY, ONE, Arrays.asList(TWO, NULL, THREE));
47+
assertNull(in.fold(FoldContext.small()));
48+
}
49+
}

0 commit comments

Comments
 (0)