Skip to content

Commit a6f543a

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 0d5b0d3 + 0393e56 commit a6f543a

File tree

29 files changed

+334
-351
lines changed

29 files changed

+334
-351
lines changed

docs/changelog/121260.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121260
2+
summary: Introduce a pre-mapping logical plan processing step
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

docs/src/yamlRestTest/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected boolean isWatcherTest() {
286286

287287
/**
288288
* Compares the results of running two analyzers against many random
289-
* strings. The goal is to figure out if two anlayzers are "the same" by
289+
* strings. The goal is to figure out if two analyzers are "the same" by
290290
* comparing their results. This is far from perfect but should be fairly
291291
* accurate, especially for gross things like missing {@code decimal_digit}
292292
* token filters, and should be fairly fast because it compares a fairly

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,6 @@ tests:
359359
- class: org.elasticsearch.xpack.security.CoreWithSecurityClientYamlTestSuiteIT
360360
method: test {yaml=indices.get_alias/10_basic/Get aliases via /*/_alias/}
361361
issue: https://github.com/elastic/elasticsearch/issues/121290
362-
- class: org.elasticsearch.xpack.inference.action.TransportInferenceActionTests
363-
method: testRerouting_HandlesTransportException_FromOtherNode
364-
issue: https://github.com/elastic/elasticsearch/issues/121292
365-
- class: org.elasticsearch.xpack.inference.action.TransportInferenceActionTests
366-
method: testRerouting_ToOtherNode
367-
issue: https://github.com/elastic/elasticsearch/issues/121293
368362
- class: org.elasticsearch.xpack.inference.common.InferenceServiceNodeLocalRateLimitCalculatorTests
369363
issue: https://github.com/elastic/elasticsearch/issues/121294
370364
- class: org.elasticsearch.env.NodeEnvironmentTests

test/framework/src/main/java/org/elasticsearch/test/LambdaMatchers.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
public class LambdaMatchers {
2525

26-
private static class TransformMatcher<T, U> extends BaseMatcher<T> {
26+
private static class TransformMatcher<T, U> extends TypeSafeMatcher<T> {
2727
private final Matcher<U> matcher;
2828
private final Function<T, U> transform;
2929

@@ -33,24 +33,21 @@ private TransformMatcher(Matcher<U> matcher, Function<T, U> transform) {
3333
}
3434

3535
@Override
36-
@SuppressWarnings("unchecked")
37-
public boolean matches(Object actual) {
36+
protected boolean matchesSafely(T item) {
3837
U u;
3938
try {
40-
u = transform.apply((T) actual);
39+
u = transform.apply(item);
4140
} catch (ClassCastException e) {
4241
throw new AssertionError(e);
4342
}
44-
4543
return matcher.matches(u);
4644
}
4745

4846
@Override
49-
@SuppressWarnings("unchecked")
50-
public void describeMismatch(Object item, Description description) {
47+
protected void describeMismatchSafely(T item, Description description) {
5148
U u;
5249
try {
53-
u = transform.apply((T) item);
50+
u = transform.apply(item);
5451
} catch (ClassCastException e) {
5552
description.appendValue(item).appendText(" is not of the correct type (").appendText(e.getMessage()).appendText(")");
5653
return;

test/framework/src/test/java/org/elasticsearch/test/LambdaMatchersTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import static org.elasticsearch.test.LambdaMatchers.transformedItemsMatch;
2020
import static org.elasticsearch.test.LambdaMatchers.transformedMatch;
2121
import static org.elasticsearch.test.LambdaMatchers.trueWith;
22+
import static org.hamcrest.Matchers.anything;
2223
import static org.hamcrest.Matchers.arrayContaining;
2324
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
2425
import static org.hamcrest.Matchers.containsInAnyOrder;
2526
import static org.hamcrest.Matchers.emptyString;
2627
import static org.hamcrest.Matchers.equalTo;
28+
import static org.hamcrest.Matchers.is;
2729
import static org.hamcrest.Matchers.not;
2830

2931
public class LambdaMatchersTests extends ESTestCase {
@@ -56,6 +58,7 @@ public void testTransformMatcher() {
5658
assertThat(new A("1"), transformedMatch(a -> a.str, equalTo("1")));
5759
assertThat(new B("1"), transformedMatch((A a) -> a.str, equalTo("1")));
5860

61+
assertMismatch((A) null, transformedMatch(A::toString, anything()), is("was null"));
5962
assertMismatch(new A("1"), transformedMatch(a -> a.str, emptyString()), equalTo("transformed value was \"1\""));
6063
}
6164

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/util/Holder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public void set(T value) {
2626
this.value = value;
2727
}
2828

29+
/**
30+
* Sets a value in the holder, but only if none has already been set.
31+
* @param value the new value to set.
32+
*/
33+
public void setIfAbsent(T value) {
34+
if (this.value == null) {
35+
this.value = value;
36+
}
37+
}
38+
2939
public T get() {
3040
return value;
3141
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.apache.lucene.sandbox.document.HalfFloatPoint;
1212
import org.apache.lucene.util.BytesRef;
1313
import org.elasticsearch.ExceptionsHelper;
14+
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
15+
import org.elasticsearch.cluster.service.ClusterService;
1416
import org.elasticsearch.common.Strings;
1517
import org.elasticsearch.common.breaker.CircuitBreaker;
1618
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
@@ -31,9 +33,11 @@
3133
import org.elasticsearch.geo.ShapeTestUtils;
3234
import org.elasticsearch.index.IndexMode;
3335
import org.elasticsearch.license.XPackLicenseState;
36+
import org.elasticsearch.search.SearchService;
3437
import org.elasticsearch.tasks.TaskCancelledException;
3538
import org.elasticsearch.test.ESTestCase;
3639
import org.elasticsearch.transport.RemoteTransportException;
40+
import org.elasticsearch.transport.TransportService;
3741
import org.elasticsearch.xcontent.json.JsonXContent;
3842
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse;
3943
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
@@ -72,8 +76,8 @@
7276
import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier;
7377
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
7478
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
79+
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
7580
import org.elasticsearch.xpack.esql.session.Configuration;
76-
import org.elasticsearch.xpack.esql.session.QueryBuilderResolver;
7781
import org.elasticsearch.xpack.esql.stats.SearchStats;
7882
import org.elasticsearch.xpack.esql.telemetry.Metrics;
7983
import org.elasticsearch.xpack.versionfield.Version;
@@ -140,6 +144,7 @@
140144
import static org.hamcrest.Matchers.instanceOf;
141145
import static org.junit.Assert.assertNotNull;
142146
import static org.junit.Assert.assertNull;
147+
import static org.mockito.Mockito.mock;
143148

144149
public final class EsqlTestUtils {
145150

@@ -360,7 +365,14 @@ public static LogicalOptimizerContext unboundLogicalOptimizerContext() {
360365

361366
public static final Verifier TEST_VERIFIER = new Verifier(new Metrics(new EsqlFunctionRegistry()), new XPackLicenseState(() -> 0L));
362367

363-
public static final QueryBuilderResolver MOCK_QUERY_BUILDER_RESOLVER = new MockQueryBuilderResolver();
368+
public static final TransportActionServices MOCK_TRANSPORT_ACTION_SERVICES = new TransportActionServices(
369+
mock(TransportService.class),
370+
mock(SearchService.class),
371+
null,
372+
mock(ClusterService.class),
373+
mock(IndexNameExpressionResolver.class),
374+
null
375+
);
364376

365377
private EsqlTestUtils() {}
366378

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void testWhereMatchWithRow() {
246246
var error = expectThrows(ElasticsearchException.class, () -> run(query));
247247
assertThat(
248248
error.getMessage(),
249-
containsString("[MATCH] function cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
249+
containsString("line 2:15: [MATCH] function cannot operate on [content], which is not a field from an index mapping")
250250
);
251251
}
252252

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void testWhereMatchWithRow() {
230230
var error = expectThrows(ElasticsearchException.class, () -> run(query));
231231
assertThat(
232232
error.getMessage(),
233-
containsString("[:] operator cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
233+
containsString("line 2:9: [:] operator cannot operate on [content], which is not a field from an index mapping")
234234
);
235235
}
236236

0 commit comments

Comments
 (0)