Skip to content

Commit 5cd8893

Browse files
authored
Minor refactor of ES|QL match and qstr integration tests (#116416)
1 parent 70824c4 commit 5cd8893

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ public static List<List<Object>> getValuesList(Iterator<Iterator<Object>> values
352352
return valuesList;
353353
}
354354

355+
public static List<List<Object>> getValuesList(Iterable<Iterable<Object>> values) {
356+
var valuesList = new ArrayList<List<Object>>();
357+
values.iterator().forEachRemaining(row -> {
358+
var rowValues = new ArrayList<>();
359+
row.iterator().forEachRemaining(rowValues::add);
360+
valuesList.add(rowValues);
361+
});
362+
return valuesList;
363+
}
364+
355365
public static List<String> withDefaultLimitWarning(List<String> warnings) {
356366
List<String> result = warnings == null ? new ArrayList<>() : new ArrayList<>(warnings);
357367
result.add("No limit defined, adding default limit of [1000]");

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@
2626
import org.elasticsearch.plugins.Plugin;
2727
import org.elasticsearch.test.ESIntegTestCase;
2828
import org.elasticsearch.test.junit.annotations.TestLogging;
29+
import org.elasticsearch.xpack.core.esql.action.ColumnInfo;
2930
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
3031
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
3132
import org.elasticsearch.xpack.esql.plugin.TransportEsqlQueryAction;
3233
import org.junit.After;
3334

3435
import java.util.Collection;
36+
import java.util.Iterator;
3537
import java.util.List;
3638
import java.util.concurrent.TimeUnit;
3739

3840
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
41+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
3942
import static org.hamcrest.Matchers.equalTo;
4043

4144
@TestLogging(value = "org.elasticsearch.xpack.esql.session:DEBUG", reason = "to better understand planning")
@@ -204,4 +207,16 @@ protected static QueryPragmas randomPragmas() {
204207
protected static boolean canUseQueryPragmas() {
205208
return Build.current().isSnapshot();
206209
}
210+
211+
protected static void assertColumnNames(List<? extends ColumnInfo> actualColumns, List<String> expectedNames) {
212+
assertThat(actualColumns.stream().map(ColumnInfo::name).toList(), equalTo(expectedNames));
213+
}
214+
215+
protected static void assertColumnTypes(List<? extends ColumnInfo> actualColumns, List<String> expectedTypes) {
216+
assertThat(actualColumns.stream().map(ColumnInfo::outputType).toList(), equalTo(expectedTypes));
217+
}
218+
219+
protected static void assertValues(Iterator<Iterator<Object>> actualValues, Iterable<Iterable<Object>> expectedValues) {
220+
assertThat(getValuesList(actualValues), equalTo(getValuesList(expectedValues)));
221+
}
207222
}

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,22 @@
77

88
package org.elasticsearch.xpack.esql.plugin;
99

10-
import org.elasticsearch.Build;
1110
import org.elasticsearch.ElasticsearchException;
1211
import org.elasticsearch.action.index.IndexRequest;
1312
import org.elasticsearch.action.support.WriteRequest;
1413
import org.elasticsearch.common.settings.Settings;
1514
import org.elasticsearch.test.junit.annotations.TestLogging;
1615
import org.elasticsearch.xpack.esql.VerificationException;
1716
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
18-
import org.elasticsearch.xpack.esql.action.ColumnInfoImpl;
17+
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
1918
import org.elasticsearch.xpack.esql.action.EsqlQueryRequest;
2019
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse;
21-
import org.elasticsearch.xpack.esql.core.type.DataType;
2220
import org.junit.Before;
2321

2422
import java.util.List;
2523

26-
import static org.elasticsearch.test.ListMatcher.matchesList;
27-
import static org.elasticsearch.test.MapMatcher.assertMap;
2824
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
29-
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
3025
import static org.hamcrest.CoreMatchers.containsString;
31-
import static org.hamcrest.Matchers.equalTo;
3226

3327
@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
3428
public class MatchOperatorIT extends AbstractEsqlIntegTestCase {
@@ -40,7 +34,7 @@ public void setupIndex() {
4034

4135
@Override
4236
protected EsqlQueryResponse run(EsqlQueryRequest request) {
43-
assumeTrue("match operator available in snapshot builds only", Build.current().isSnapshot());
37+
assumeTrue("match operator capability not available", EsqlCapabilities.Cap.MATCH_OPERATOR_COLON.isEnabled());
4438
return super.run(request);
4539
}
4640

@@ -53,11 +47,9 @@ public void testSimpleWhereMatch() {
5347
""";
5448

5549
try (var resp = run(query)) {
56-
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of("id")));
57-
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of("INTEGER")));
58-
// values
59-
List<List<Object>> values = getValuesList(resp);
60-
assertMap(values, matchesList().item(List.of(1)).item(List.of(6)));
50+
assertColumnNames(resp.columns(), List.of("id"));
51+
assertColumnTypes(resp.columns(), List.of("integer"));
52+
assertValues(resp.values(), List.of(List.of(1), List.of(6)));
6153
}
6254
}
6355

@@ -70,11 +62,9 @@ public void testCombinedWhereMatch() {
7062
""";
7163

7264
try (var resp = run(query)) {
73-
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of(("id"))));
74-
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of(("INTEGER"))));
75-
// values
76-
List<List<Object>> values = getValuesList(resp);
77-
assertMap(values, matchesList().item(List.of(6)));
65+
assertColumnNames(resp.columns(), List.of("id"));
66+
assertColumnTypes(resp.columns(), List.of("integer"));
67+
assertValues(resp.values(), List.of(List.of(6)));
7868
}
7969
}
8070

@@ -87,12 +77,9 @@ public void testMultipleMatch() {
8777
""";
8878

8979
try (var resp = run(query)) {
90-
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of(("id"))));
91-
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of(("INTEGER"))));
92-
// values
93-
List<List<Object>> values = getValuesList(resp);
94-
assertThat(values.size(), equalTo(2));
95-
assertMap(values, matchesList().item(List.of(1)).item(List.of(6)));
80+
assertColumnNames(resp.columns(), List.of("id"));
81+
assertColumnTypes(resp.columns(), List.of("integer"));
82+
assertValues(resp.values(), List.of(List.of(1), List.of(6)));
9683
}
9784
}
9885

@@ -121,11 +108,9 @@ public void testNotWhereMatch() {
121108
""";
122109

123110
try (var resp = run(query)) {
124-
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of(("id"))));
125-
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of(("INTEGER"))));
126-
// values
127-
List<List<Object>> values = getValuesList(resp);
128-
assertMap(values, matchesList().item(List.of(5)));
111+
assertColumnNames(resp.columns(), List.of("id"));
112+
assertColumnTypes(resp.columns(), List.of("integer"));
113+
assertValues(resp.values(), List.of(List.of(5)));
129114
}
130115
}
131116

0 commit comments

Comments
 (0)